Sha256: 5e5490f80a6f361dbf0754677d37bde752e57407c3a86260801d72b3528f2025

Contents?: true

Size: 932 Bytes

Versions: 1

Compression:

Stored size: 932 Bytes

Contents

module StackExchange
  module StackOverflow
    class Base 
      extend Forwardable

      class << self
        attr_reader :api_methods

        def setup_delegators(*delegators)
          @api_methods = delegators
          def_delegators *delegators
        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

        def client
          StackExchange::StackOverflow::Client.instance
        end
      end

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

      def api_methods
        self.class.api_methods 
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pilha-0.2.2 lib/pilha/stack_overflow/base.rb