Class: Radar::API::Resource
- Inherits:
-
Object
- Object
- Radar::API::Resource
show all
- Defined in:
- lib/radar/api/resource.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(data = {}) ⇒ Resource
Returns a new instance of Resource.
4
5
6
|
# File 'lib/radar/api/resource.rb', line 4
def initialize(data = {})
convert_to_obj(data)
end
|
Class Method Details
.api_client ⇒ Object
8
9
10
|
# File 'lib/radar/api/resource.rb', line 8
def self.api_client
@api_client ||= Radar::API::Client.new
end
|
.class_name ⇒ Object
12
13
14
|
# File 'lib/radar/api/resource.rb', line 12
def self.class_name
name.split('::')[-1]
end
|
.descendants ⇒ Object
22
23
24
25
26
|
# File 'lib/radar/api/resource.rb', line 22
def self.descendants
ObjectSpace.each_object(Class).select do |klass|
klass < self && klass != Radar::API::NestedResource
end
end
|
.resource_base_path(path_base: '/v1/') ⇒ Object
16
17
18
19
20
|
# File 'lib/radar/api/resource.rb', line 16
def self.resource_base_path(path_base: '/v1/')
raise NotImplementedError, 'Radar::API::Resource is an abstract class' if self == Resource
path_base + self::RESOURCE_NAME[:plural]
end
|
Instance Method Details
#to_h ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/radar/api/resource.rb', line 28
def to_h
instance_variables.each_with_object({}) do |instance_variable, h|
key = instance_variable[1..instance_variable.length]
value = instance_variable_get(instance_variable)
h[key.to_sym] = build_hash_value_from_attribute_value(value)
end
end
|