Class: Hermes::PlivoProvider

Inherits:
Provider show all
Defined in:
lib/providers/plivo/plivo_provider.rb

Instance Attribute Summary

Attributes inherited from Provider

#credentials, #defaults, #deliverer, #weight

Instance Method Summary collapse

Methods inherited from Provider

#initialize, #message_failure, #message_success, #provider_name, required_credentials

Methods included from Extractors

#complex_extract, #extract_from, #extract_html, #extract_text, #extract_to

Constructor Details

This class inherits a constructor from Hermes::Provider

Instance Method Details

#clientObject



29
30
31
# File 'lib/providers/plivo/plivo_provider.rb', line 29

def client
  Plivo::RestAPI.new(self.credentials[:auth_id], self.credentials[:auth_token])
end

#payload(rails_message) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/providers/plivo/plivo_provider.rb', line 19

def payload(rails_message)
  {
    src:  extract_from(rails_message).full_number,
    dst:  extract_to(rails_message),
    text: extract_text(rails_message),
    type: :sms,
    url:  rails_message.plivo_url || self.defaults[:url]
  }
end

#send_message(rails_message) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/providers/plivo/plivo_provider.rb', line 5

def send_message(rails_message)
  payload = payload(rails_message)
  
  if self.deliverer.should_deliver?
    result = self.client.send_message(payload)
    rails_message[:message_id] = result["api_id"]
  else
    # rails message still needs a fake sid as if it succeeded
    rails_message[:message_id] = SecureRandom.uuid
  end

  self.message_success(rails_message)
end