Sha256: 62921a1496acef7bc53fb6ca568f6254344edca2d2f776033b0df07068f48ac5

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

module StackExchange
  module StackOverflow
    class Question < Base
      extend Forwardable

      def_delegators :@struct, :question_id, :tags, :creation_date, :last_activity_date,
                               :up_vote_count, :down_vote_count, :view_count, :score,
                               :community_owned, :title, :body, :answers, :answer_count,
                               :accepted_answer_id, :favorite_count, :question_timeline_url,
                               :question_comments_url, :question_answers_url, :owner

      class << self 

        def all(options = {})
          request('/questions', nil, options)
        end

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

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

        def find_favorites_by_user_id(id, options = {})
          request('/users/:id/favorites', id, options) 
        end

        def find_by_tags(*tags)
          options = tags.last.is_a?(Hash) ? tags.pop : {}
          options.merge!(:conditions => { :tagged => tags.join('+') })
          request('/questions', nil, options)
        end

        def unanswered(options = {})
          request('/questions/unanswered', nil, options)
        end

        def parse(response)
          response['questions'].each do |comment|
            parse_with_class(comment, 'owner', User)
          end
          parse_with_class(response, 'questions', Question)
          OpenStruct.new response
        end
      end

      def id
        @struct.question_id
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pilha-0.2.1 lib/pilha/stack_overflow/question.rb