Skip to content

Commit 3db5fb1

Browse files
authored
Merge pull request #8 from mlibrary/sms
fix: adds sid to message output and some helpful sms debugging methods
2 parents 3671775 + 3a56214 commit 3db5fb1

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

lib/aim/sms.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,25 @@ def self.send_metrics(results)
3333
Logger.new($stdout).error("Failed to contact the push gateway")
3434
end
3535
end
36+
37+
# For debugging purposes
38+
# See
39+
# https://www.twilio.com/docs/sms/api/message-resource?code-sample=code-read-list-all-messages&code-language=Ruby&code-sdk-version=6.x#read-multiple-message-resources
40+
# for things one might do with the client
41+
def self.twilio_client
42+
Twilio::REST::Client.new(ENV.fetch("TWILIO_ACCT_SID"), ENV.fetch("TWILIO_AUTH_TOKEN"))
43+
end
44+
45+
def self.get_message_status(sid)
46+
message = twilio_client.messages(sid).fetch
47+
{
48+
status: message.status,
49+
sid: message.sid,
50+
to: message.to,
51+
body: message.body,
52+
date_created: message.date_created,
53+
date_sent: message.date_sent
54+
}
55+
end
3656
end
3757
end

lib/aim/sms/sender.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def run
3535

3636
begin
3737
response = @sender.send(message)
38-
@logger.info("status: #{response.status}, to: #{response.to}, body: #{response.body}")
38+
@logger.info("status: #{response.status}, sid: #{response.sid}, to: #{response.to}, body: #{response.body}")
3939
summary[:num_files_sent] = summary[:num_files_sent] + 1
4040
rescue Twilio::REST::TwilioError => e
4141
error_message(sms_file: sms_file, error: e)
@@ -81,7 +81,7 @@ def proccessed_path
8181
end
8282

8383
class Sender
84-
def initialize(client = Twilio::REST::Client.new(ENV.fetch("TWILIO_ACCT_SID"), ENV.fetch("TWILIO_AUTH_TOKEN")))
84+
def initialize(client = AIM::SMS.twilio_client)
8585
@client = client
8686
end
8787

spec/aim/sms/sender_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
before(:each) do
33
@sftp = instance_double(SFTP::Client, ls: [], get: nil, rename: nil)
44
@file_class = class_double(File)
5-
twilio_response = double("TwilioClient", status: "success", to: "someone", body: "body")
5+
twilio_response = double("TwilioClient", status: "success", sid: "sid", to: "someone", body: "body")
66
@sender_double = instance_double(AIM::SMS::Sender, send: twilio_response)
77
@logger_double = instance_double(Logger, info: nil, error: nil)
88
end

0 commit comments

Comments
 (0)