Sha256: 3c32411af7deb62e963ab88d0334b70a35116e8b90254126c212db32cf43a600
Contents?: true
Size: 1.28 KB
Versions: 5
Compression:
Stored size: 1.28 KB
Contents
require "hashie" require "multi_json" 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) if response.is_a?(Faraday::Response) return nil if response.status == 204 response = response.body end if self.format == :json MultiJson.load(response) elsif self.format == :xml MultiXml.parse(response) else response end end end # Defaults self.format :json def id self['id'] end def inspect attributes = [] attr_keys = self.keys - ['id'] attributes.push "id: #{self.id}" if self.id attr_keys.each do |key| attributes.push("#{key}: #{self[key].inspect}") end "#<#{self.class} #{attributes.join(', ')}>" end end end
Version data entries
5 entries across 5 versions & 1 rubygems