Class: Alula::Video::BaseResource

Inherits:
ApiResource show all
Extended by:
ResourceAttributes
Defined in:
lib/alula/resources/video/base_resource.rb

Direct Known Subclasses

Device

Instance Attribute Summary

Attributes inherited from ApiResource

#dirty_attributes, #errors, #id, #link_matchers, #links, #rate_limit, #raw_data, #values

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ResourceAttributes

date_fields, extended, field, field_names, filterable_fields, get_fields, get_http_methods, get_resource_path, get_type, http_methods, param_key, read_only_attributes, resource_path, sortable_fields, type

Methods inherited from ApiResource

#annotate_errors, #apply_attributes, #as_json, #as_patchable_json, build, #cache_links, class_name, #clone, #dirty?, #errors?, #filter_builder, #initialize, #model_name, #reconstruct_from, #refresh

Constructor Details

This class inherits a constructor from Alula::ApiResource

Class Method Details

.api_name(name = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/alula/resources/video/base_resource.rb', line 7

def api_name(name = nil)
  if name
    @api_name = name
  elsif @api_name
    @api_name
  else
    superclass.api_name
  end
end

.resource_name(name = nil) ⇒ Object

Infer resource name from classname if not provided



18
19
20
21
22
23
24
25
26
# File 'lib/alula/resources/video/base_resource.rb', line 18

def resource_name(name = nil)
  if name
    @resource_name = name
  elsif @resource_name
    @resource_name
  else
    @resource_name = self.name.split('::').last.downcase.to_sym
  end
end

.resource_url(id = nil) ⇒ Object



28
29
30
# File 'lib/alula/resources/video/base_resource.rb', line 28

def resource_url(id = nil)
  "/#{api_name}/v1/#{resource_name}/#{id}"
end

Instance Method Details

#construct_from(json_object) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/alula/resources/video/base_resource.rb', line 40

def construct_from(json_object)
  @raw_data = json_object.dup
  @values = json_object

  self.id = json_object['id'] unless [nil, ''].include?(json_object['id'])

  @dirty_attributes = Set.new
  @errors = ModelErrors.new(self.class)

  @related_models = {}
  cache_links(json_object['relationships'] || {})

  self
end

#resource_url(id = self.id) ⇒ Object

Instance method



36
37
38
# File 'lib/alula/resources/video/base_resource.rb', line 36

def resource_url(id = self.id)
  "/#{self.class.api_name}/v1/#{self.class.resource_name}/#{id}"
end