Class: UnifonicIntegration::Client
- Inherits:
-
Object
- Object
- UnifonicIntegration::Client
- Includes:
- HTTParty
- Defined in:
- lib/unifonic_integration/client.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #send_message(body, recipient) ⇒ Object
- #send_scheduled_message(body, recipient, time_scheduled) ⇒ Object
- #set_headers ⇒ Object
- #set_message_params(body, recipient) ⇒ Object
- #set_scheduled_message_params(body, recipient, time_scheduled) ⇒ Object
- #validate_recipient(recipient) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
12 13 14 |
# File 'lib/unifonic_integration/client.rb', line 12 def initialize @config = Configuration.new end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
10 11 12 |
# File 'lib/unifonic_integration/client.rb', line 10 def config @config end |
Instance Method Details
#send_message(body, recipient) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/unifonic_integration/client.rb', line 16 def (body, recipient) unless validate_recipient(recipient) puts "Invalid recipient phone number format. Please provide a valid international format." return end endpoint = '/messages?async=false' set_headers (body, recipient) response = self.class.post(endpoint, headers: @headers, body: @params) puts response.body return response.body end |
#send_scheduled_message(body, recipient, time_scheduled) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/unifonic_integration/client.rb', line 36 def (body, recipient, time_scheduled) unless validate_recipient(recipient) puts "Invalid recipient phone number format. Please provide a valid international format." return end endpoint = '/messages/scheduledmessages?async=false' set_headers (body, recipient, time_scheduled) response = self.class.post(endpoint, headers: @headers, body: @params) puts response.body return response.body end |
#set_headers ⇒ Object
50 51 52 53 54 |
# File 'lib/unifonic_integration/client.rb', line 50 def set_headers @headers = { Accept: 'application/json', } end |
#set_message_params(body, recipient) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/unifonic_integration/client.rb', line 61 def (body, recipient) @params = { AppSid: @config.app_sid, SenderID: @config.sender_id, Body: body, Recipient: recipient } end |
#set_scheduled_message_params(body, recipient, time_scheduled) ⇒ Object
56 57 58 59 |
# File 'lib/unifonic_integration/client.rb', line 56 def (body, recipient, time_scheduled) (body, recipient) @params.merge!(TimeScheduled: time_scheduled) end |
#validate_recipient(recipient) ⇒ Object
31 32 33 34 |
# File 'lib/unifonic_integration/client.rb', line 31 def validate_recipient(recipient) cleaned_number = recipient.to_s.gsub(/^(\+|00)/, '') cleaned_number =~ /\A\d+\z/ end |