Class: Feathr::Api::FeathrObject

Inherits:
FeathrEndpoint show all
Defined in:
lib/feathr/api/feathr_object.rb

Instance Attribute Summary collapse

Attributes inherited from FeathrEndpoint

#client, #prepended_path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FeathrEndpoint

api_path, define_all, define_create, define_destroy, define_find, define_update, feathr_endpoints, feathr_object

Constructor Details

#initialize(data, id) ⇒ FeathrObject

Returns a new instance of FeathrObject.



9
10
11
12
13
14
# File 'lib/feathr/api/feathr_object.rb', line 9

def initialize(data, id)
  @data = data
  @id   = id

  super()
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/feathr/api/feathr_object.rb', line 5

def data
  @data
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/feathr/api/feathr_object.rb', line 5

def id
  @id
end

Class Method Details

.nested(*resources) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/feathr/api/feathr_object.rb', line 28

def self.nested(*resources)
  resources.each do |resource|
    define_method(resource) do
      ivar = "@#{ resource }"
      klass_name = resource.to_s.split('_').collect(&:capitalize).join
      klass = Object.const_get("Feathr::Api::#{ klass_name }")

      instance_variable_get(ivar) ||
      instance_variable_set(ivar, klass.new(prepended_path: path))
    end
  end
end

Instance Method Details

#as_jsonObject



24
25
26
# File 'lib/feathr/api/feathr_object.rb', line 24

def as_json
  data.to_h
end

#full_pathObject



20
21
22
# File 'lib/feathr/api/feathr_object.rb', line 20

def full_path
  url = [client.config.base_url, path].join('/') + "/"
end

#pathObject



16
17
18
# File 'lib/feathr/api/feathr_object.rb', line 16

def path
  [api_path, id].join('')
end