Class: SObjectModel::Rest::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance_url:, access_token:, api_version:) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
# File 'lib/sobject_model/rest/client.rb', line 15

def initialize(instance_url:, access_token:, api_version:)
  @instance_url = instance_url
  @access_token = access_token
  @api_version = api_version
  @http = Http.new(instance_url, access_token)
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



13
14
15
# File 'lib/sobject_model/rest/client.rb', line 13

def access_token
  @access_token
end

#api_versionObject (readonly)

Returns the value of attribute api_version.



13
14
15
# File 'lib/sobject_model/rest/client.rb', line 13

def api_version
  @api_version
end

#instance_urlObject (readonly)

Returns the value of attribute instance_url.



13
14
15
# File 'lib/sobject_model/rest/client.rb', line 13

def instance_url
  @instance_url
end

Instance Method Details

#create(object_type, values) ⇒ Object



43
44
45
46
# File 'lib/sobject_model/rest/client.rb', line 43

def create(object_type, values)
  response = http.post "/services/data/v#{api_version}/sobjects/#{object_type}/", values
  JSON.parse(response)['id']
end

#delete(object_type, id) ⇒ Object



53
54
55
56
# File 'lib/sobject_model/rest/client.rb', line 53

def delete(object_type, id)
  http.delete "/services/data/v#{api_version}/sobjects/#{object_type}/#{id}/"
  id
end

#describe(object_type) ⇒ Object



27
28
29
30
# File 'lib/sobject_model/rest/client.rb', line 27

def describe(object_type)
  response = http.get "/services/data/v#{api_version}/sobjects/#{object_type.to_sym}/describe"
  JSON.parse(response)
end

#describe_globalObject



32
33
34
35
# File 'lib/sobject_model/rest/client.rb', line 32

def describe_global
  response = http.get "/services/data/v#{api_version}/sobjects/"
  JSON.parse(response)
end

#find(object_type, id, fields: []) ⇒ Object



37
38
39
40
41
# File 'lib/sobject_model/rest/client.rb', line 37

def find(object_type, id, fields: [])
  query = fields.empty? ? '' : %|?fields=#{fields.map(&:to_s).join(',')}|
  response = http.get "/services/data/v#{api_version}/sobjects/#{object_type}/#{id}#{query}"
  JSON.parse(response)
end

#query(soql) ⇒ Object



22
23
24
25
# File 'lib/sobject_model/rest/client.rb', line 22

def query(soql)
  response = http.get "/services/data/v#{api_version}/query?q=#{CGI.escape(soql)}"
  QueryResult.new(response)
end

#update(object_type, id, values) ⇒ Object



48
49
50
51
# File 'lib/sobject_model/rest/client.rb', line 48

def update(object_type, id, values)
  http.patch "/services/data/v#{api_version}/sobjects/#{object_type}/#{id}/", values
  id
end