Module: Alula::ApiOperations::Request

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



4
5
6
# File 'lib/alula/api_operations/request.rb', line 4

def self.extended(base)
  base.include(InstanceMethods)
end

Instance Method Details

#build_and_merge_item_relationships(item, relations) ⇒ Object



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

def build_and_merge_item_relationships(item, relations)
  relations.each do |relation|
    model = Alula.class_from_resource_type(relation['type'])
    model = model.new.construct_from(relation)

    #
    # TODO: Remove this line. This makes us ignore unknown relationships
    unless get_relationship(model.get_type).nil?
      item.add_model_to_relationship(model)
    end
  end

  item
end

#retrieve(id, built_filters = {}) ⇒ Object

Load a single model by ID



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/alula/api_operations/request.rb', line 9

def retrieve(id, built_filters = {})
  response = Alula::Client.request(:get, self.resource_url(id), built_filters, {})
  if response.ok?
    item = self.new.construct_from(response.data['data'])
    item = build_and_merge_item_relationships(item, response.data['included']) if response.data['included']
    item.rate_limit = response.rate_limit
    item
  else
    error_class = AlulaError.for_response(response)
    raise error_class
  end
end