Class: SalesforceStreamer::SalesforceClient

Inherits:
Object
  • Object
show all
Defined in:
lib/salesforce_streamer/salesforce_client.rb

Constant Summary collapse

QUERY =
<<~SOQL.chomp.freeze
  SELECT Id, Name, ApiVersion, Description, NotifyForFields, Query, isActive
  FROM PushTopic
  WHERE Name = '{{NAME}}'
SOQL

Instance Method Summary collapse

Constructor Details

#initialize(client: Restforce.new) ⇒ SalesforceClient

Returns a new instance of SalesforceClient.



3
4
5
# File 'lib/salesforce_streamer/salesforce_client.rb', line 3

def initialize(client: Restforce.new)
  @client = client
end

Instance Method Details

#authenticate!Object



7
8
9
# File 'lib/salesforce_streamer/salesforce_client.rb', line 7

def authenticate!
  @client.authenticate!
end

#find_push_topic_by_name(name) ⇒ Object

Returns nil or an instance of Restforce::SObject



16
17
18
19
# File 'lib/salesforce_streamer/salesforce_client.rb', line 16

def find_push_topic_by_name(name)
  query = QUERY.dup.gsub(/\s+/, ' ').gsub('{{NAME}}', name)
  @client.query(query).first
end

#subscribe(*args) ⇒ Object



11
12
13
# File 'lib/salesforce_streamer/salesforce_client.rb', line 11

def subscribe(*args, &)
  @client.subscribe(args, &)
end

#upsert_push_topic(push_topic) ⇒ Object

Returns true or raises an exception if the upsert fails



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/salesforce_streamer/salesforce_client.rb', line 22

def upsert_push_topic(push_topic)
  @client.upsert!(
    'PushTopic', :Id,
    'Id' => push_topic.id,
    'Name' => push_topic.name,
    'ApiVersion' => push_topic.api_version,
    'Description' => push_topic.description,
    'NotifyForFields' => push_topic.notify_for_fields,
    'Query' => push_topic.query
  )
end