Class: ApiClient::Base

Inherits:
Hashie::Mash
  • Object
show all
Extended by:
Mixins::Configuration, Mixins::ConnectionHooks, Mixins::Delegation, Mixins::Inheritance, Mixins::Instantiation, Mixins::Scoping
Defined in:
lib/api_client/base.rb

Direct Known Subclasses

Resource::Base

Instance Attribute Summary

Attributes included from Mixins::Scoping

#default_scopes

Attributes included from Mixins::ConnectionHooks

#connection_hooks

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixins::Inheritance

inherited

Methods included from Mixins::Instantiation

build, build_many, build_one, extended

Methods included from Mixins::Scoping

always, scope, scope_in_thread, scope_thread_attribute_name, scoped

Methods included from Mixins::ConnectionHooks

connection

Methods included from Mixins::Delegation

delegate

Methods included from Mixins::Configuration

dsl_accessor

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &blk) ⇒ Object (private)



57
58
59
60
61
62
63
64
65
# File 'lib/api_client/base.rb', line 57

def method_missing(method_name, *args, &blk)
  if respond_to?(method_name) || has_special_ending?(method_name)
    super
  elsif use_strict_reader?(method_name)
    fetch(method_name)
  else
    super
  end
end

Class Method Details

.parse(response) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/api_client/base.rb', line 22

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

.subkey_classObject



18
19
20
# File 'lib/api_client/base.rb', line 18

def subkey_class
  Hashie::Mash
end

Instance Method Details

#idObject



42
43
44
# File 'lib/api_client/base.rb', line 42

def id
  self['id']
end

#inspectObject



46
47
48
49
50
51
52
53
54
# File 'lib/api_client/base.rb', line 46

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