Sha256: c899dd70f46ff0790c08e21b10d49e2ba56356299bde5892f0e0a37a890e7d05

Contents?: true

Size: 698 Bytes

Versions: 4

Compression:

Stored size: 698 Bytes

Contents

module StackExchange
  module StackOverflow
    class Base 

      class << self
        def client
          @client ||= StackExchange::StackOverflow::Client.config
        end

        def parse_with_class(hash, key, klass)
          case hash[key]
            when Hash 
              hash[key] = klass.new(hash[key])
            when Array
              hash[key] = hash[key].map { |value| klass.new(value) }
          end
        end

        def request(path_pattern, id, options)
          options.merge! :id => id if id
          parse client.request(path_pattern, options)
        end
      end

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

Version data entries

4 entries across 4 versions & 1 rubygems

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