Sha256: 0eb3ed66c617c6ed259d11afbc74284534a635a5cfe0ea885defcaae4f43bb25

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 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 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)
          if tags.last.is_a? Hash
            options = tags.last
            tags = tags[0, tags.size - 1]
          else
            options = {}
          end

          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

3 entries across 3 versions & 1 rubygems

Version Path
pilha-0.1.9 lib/pilha/stack_overflow/question.rb
pilha-0.1.8 lib/pilha/stack_overflow/question.rb
pilha-0.1.7 lib/pilha/stack_overflow/question.rb