Sha256: faea6bdcd1f4d83ce1183b7c5c2fe36312d5df3282ed1f8bcd5c20b9717e4962

Contents?: true

Size: 892 Bytes

Versions: 1

Compression:

Stored size: 892 Bytes

Contents

module StackExchange
  module StackOverflow
    class Badge < Base

      extend Forwardable

      def_delegators :@struct, :badge_id, :rank, :name, :description,
                               :award_count, :tag_based, :badges_recipients_url

      class << self 
        attr_reader :client

        def all(options = {})
          method = select_method(options)
          request(method, nil, options)
        end

        def select_method(options)
          tag_based = options[:tag_based] || options['tag_based']
          tag_based ? '/badges/tags' : '/badges'
        end

        def parse(response)
          response['badges'] = response['badges'].map { |badge| Badge.new badge }
          OpenStruct.new response
        end
      end

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

      def id
        @struct.badge_id
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pilha-0.1.6 lib/pilha/stack_overflow/badge.rb