Class: Clientele::Resource

Inherits:
SimpleDelegator
  • Object
show all
Extended by:
Utils
Includes:
Utils
Defined in:
lib/clientele/resource.rb,
lib/clientele/resource/pagination.rb

Defined Under Namespace

Modules: Pagination

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Utils

deep_camelize_keys, ensure_trailing_slash, merge_paths

Class Attribute Details

.subclassesObject (readonly)

Returns the value of attribute subclasses.



20
21
22
# File 'lib/clientele/resource.rb', line 20

def subclasses
  @subclasses
end

Class Method Details

.build(data, client: nil, klass: nil) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/clientele/resource.rb', line 69

def build(data, client: nil, klass: nil)
  if (klass or data).kind_of? Array
    data.map do |dataset|
      build dataset, client: client
    end
  elsif (klass or data).kind_of? Hash and data.keys.map(&:to_s).include? result_key.to_s
    build data.send method_name, client: client
  elsif (klass or data).kind_of? Hash and data.keys.map(&:to_s).include? plural_key.to_s
    build data.send method_name, client: client
  else
    new(data).tap do |instance|
      instance.instance_variable_set :@client, client if client
    end
  end
end

.default_pathObject



41
42
43
# File 'lib/clientele/resource.rb', line 41

def default_path
  self.name.split('::').last.pluralize.underscore
end

.method_nameObject



49
50
51
# File 'lib/clientele/resource.rb', line 49

def method_name
  @method_name || path
end

.nested_plural_keyObject



65
66
67
# File 'lib/clientele/resource.rb', line 65

def nested_plural_key
  @nested_plural_key || plural_key
end

.nested_result_keyObject



61
62
63
# File 'lib/clientele/resource.rb', line 61

def nested_result_key
  @nested_result_key || result_key
end

.paginateable?Boolean

Returns:

  • (Boolean)


85
# File 'lib/clientele/resource.rb', line 85

def paginateable?; false; end

.pathObject



45
46
47
# File 'lib/clientele/resource.rb', line 45

def path
  @path || default_path
end

.plural_keyObject



57
58
59
# File 'lib/clientele/resource.rb', line 57

def plural_key
  @plural_key || method_name
end

.request(verb, path = '', opts = {}, &callback) ⇒ Object



33
34
35
# File 'lib/clientele/resource.rb', line 33

def request(verb, path = '', opts = {}, &callback)
  send verb, path, opts, &callback
end

.result_keyObject



53
54
55
# File 'lib/clientele/resource.rb', line 53

def result_key
  @result_key || method_name.singularize
end

.to_request(opts = {}, &callback) ⇒ Object



37
38
39
# File 'lib/clientele/resource.rb', line 37

def to_request(opts={}, &callback)
  get opts, &callback
end