Class: Draisine::Syncer
- Inherits:
-
Object
- Object
- Draisine::Syncer
- Defined in:
- lib/draisine/syncer.rb
Overview
Wrapper around salesforce client implementation Might have pluggable adapters in the future.
Instance Attribute Summary collapse
-
#salesforce_object_name ⇒ Object
readonly
Returns the value of attribute salesforce_object_name.
Instance Method Summary collapse
- #create(attrs) ⇒ Object
- #delete(id) ⇒ Object
- #get(id, options = {}) ⇒ Object
- #get_system_modstamp(id) ⇒ Object
-
#initialize(salesforce_object_name, client = nil) ⇒ Syncer
constructor
A new instance of Syncer.
- #update(id, attrs) ⇒ Object
Constructor Details
#initialize(salesforce_object_name, client = nil) ⇒ Syncer
Returns a new instance of Syncer.
7 8 9 10 |
# File 'lib/draisine/syncer.rb', line 7 def initialize(salesforce_object_name, client = nil) @salesforce_object_name ||= salesforce_object_name @client = client end |
Instance Attribute Details
#salesforce_object_name ⇒ Object (readonly)
Returns the value of attribute salesforce_object_name.
5 6 7 |
# File 'lib/draisine/syncer.rb', line 5 def salesforce_object_name @salesforce_object_name end |
Instance Method Details
#create(attrs) ⇒ Object
18 19 20 21 |
# File 'lib/draisine/syncer.rb', line 18 def create(attrs) response = client.http_post(build_sobject_url(nil), attrs.to_json) JSON.parse(response.body) end |
#delete(id) ⇒ Object
29 30 31 32 |
# File 'lib/draisine/syncer.rb', line 29 def delete(id) raise ArgumentError unless id.present? client.http_delete(build_sobject_url(id)) end |
#get(id, options = {}) ⇒ Object
12 13 14 15 16 |
# File 'lib/draisine/syncer.rb', line 12 def get(id, = {}) raise ArgumentError unless id.present? response = client.http_get(build_sobject_url(id), ) JSON.parse(response.body) end |
#get_system_modstamp(id) ⇒ Object
34 35 36 37 38 |
# File 'lib/draisine/syncer.rb', line 34 def get_system_modstamp(id) raise ArgumentError unless id.present? time = get(id, fields: "SystemModstamp")['SystemModstamp'] time && Time.parse(time) end |
#update(id, attrs) ⇒ Object
23 24 25 26 27 |
# File 'lib/draisine/syncer.rb', line 23 def update(id, attrs) raise ArgumentError unless id.present? return unless attrs.present? client.http_patch(build_sobject_url(id), attrs.to_json) end |