Class: SObjectModel::Adapter::Rest

Inherits:
Base
  • Object
show all
Defined in:
lib/sobject_model/adapter/rest.rb

Instance Method Summary collapse

Constructor Details

#initialize(rest_client) ⇒ Rest

Returns a new instance of Rest.



7
8
9
# File 'lib/sobject_model/adapter/rest.rb', line 7

def initialize(rest_client)
  @client = rest_client
end

Instance Method Details

#create(object_type, values, klass = nil) ⇒ Object



27
28
29
30
31
32
# File 'lib/sobject_model/adapter/rest.rb', line 27

def create(object_type, values, klass = nil)
  id = client.create(object_type, values)
  return id if klass.nil?

  find(object_type, id, klass)
end

#delete(object_type, id) ⇒ Object



38
39
40
# File 'lib/sobject_model/adapter/rest.rb', line 38

def delete(object_type, id)
  client.delete(object_type, id)
end

#describe(object_type) ⇒ Object



16
17
18
# File 'lib/sobject_model/adapter/rest.rb', line 16

def describe(object_type)
  client.describe(object_type)
end

#exec_query(soql, model_class: nil) ⇒ Object



11
12
13
14
# File 'lib/sobject_model/adapter/rest.rb', line 11

def exec_query(soql, model_class: nil)
  result = client.query(soql)
  result.to_records(model_class: model_class)
end

#find(object_type, id, klass) ⇒ Object



20
21
22
23
24
25
# File 'lib/sobject_model/adapter/rest.rb', line 20

def find(object_type, id, klass)
  attributes = client.find(object_type, id)
  klass.new(**attributes)
rescue ::SObjectModel::Rest::RecordNotFoundError
  nil
end

#query(soql, klass) ⇒ Object



42
43
44
# File 'lib/sobject_model/adapter/rest.rb', line 42

def query(soql, klass)
  exec_query(soql, model_class: klass)
end

#update(object_type, id, values) ⇒ Object



34
35
36
# File 'lib/sobject_model/adapter/rest.rb', line 34

def update(object_type, id, values)
  client.update(object_type, id, values)
end