Sha256: 3447ef1433f5157e9b05a25a46dc365a3c17ae4aa6729de946a72e515fa4a59f

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

module StackExchange
  module StackOverflow
    class Answer < Base
      extend Forwardable
      
      def_delegators :@struct, :answer_id, :accepted, :answer_comments_url, :question_id,
                     :owner, :creation_date, :last_activity_date, :up_vote_count, :down_vote_count,
                     :view_count, :score, :community_owned, :title, :comments

      class << self
        attr_reader :client

        def find(id, options = {})
          request('/answers/:id', id, options).answers.first
        end

        def find_by_user_id(id, options = {})
          request('/users/:id/answers', id, options)
        end

        def find_by_question_id(id, options = {})
          request('/questions/:id/answers', id, options)
        end

        private
          def parse(response)
            response['answers'].each do |answer|
              parse_with_class(answer, 'comments', Comment)
              parse_with_class(answer, 'owner', User)
            end
            parse_with_class(response, 'answers', Answer)
            OpenStruct.new response
          end
      end

      def initialize(hash)
        @struct = OpenStruct.new hash
      end

      def id
        @struct.answer_id
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pilha-0.1.5 lib/pilha/stack_overflow/answer.rb