Sha256: cd4a4b23987922bd3f548c9359b0b2d793fb9b19ca98c67908d17cb680732577

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

require "hashie"
require "yajl"

module ApiClient

  class Base < Hashie::Mash

    extend ApiClient::Mixins::Inheritance
    extend ApiClient::Mixins::Instantiation
    extend ApiClient::Mixins::Scoping
    extend ApiClient::Mixins::ConnectionHooks

    class << self
      extend ApiClient::Mixins::Delegation
      extend ApiClient::Mixins::Configuration

      delegate :fetch, :get, :put, :post, :delete, :headers, :endpoint, :options, :adapter, :params, :raw, :to => :scope

      dsl_accessor :format, :namespace

      def subkey_class
        Hashie::Mash
      end

      def parse(response)
        response = response.body if response.is_a?(Faraday::Response)
        if self.format == :json
          Yajl::Parser.parse(response)
        elsif self.format == :xml
          MultiXml.parse(response)
        else
          response
        end
      end

    end

    # Defaults
    self.format :json

    def id
      self['id']
    end

    def inspect
      "#<#{self.class} id: #{self.id}>"
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
api_client-0.1.7 lib/api_client/base.rb
api_client-0.1.6 lib/api_client/base.rb
api_client-0.1.5 lib/api_client/base.rb
api_client-0.1.4 lib/api_client/base.rb