This repository has been archived by the owner on Jan 31, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to only notify on commits to master for Twilio.
- Loading branch information
1 parent
344366e
commit f09faed
Showing
3 changed files
with
59 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,38 @@ | ||
class Service::Twilio < Service | ||
string :account_sid, :from_phone, :to_phone | ||
boolean :master_only | ||
password :auth_token | ||
|
||
def receive_push | ||
check_configuration_options(data) | ||
|
||
sms_body = "#{payload['pusher']['name']} has pushed #{payload['commits'].size} commit(s) to #{payload['repository']['name']}" | ||
client = ::Twilio::REST::Client.new(data['account_sid'], data['auth_token']) | ||
client.account.sms.messages.create( | ||
:from => data['from_phone'], | ||
:to => data['to_phone'], | ||
:body => sms_body | ||
) | ||
send_message(data, sms_body) if send_notification?(data) | ||
end | ||
|
||
private | ||
|
||
|
||
def send_notification?(data) | ||
notify_user = true | ||
if data['master_only'].to_i == 1 && branch_name != 'master' | ||
notify_user = false | ||
end | ||
notify_user | ||
end | ||
|
||
def check_configuration_options(data) | ||
raise_config_error 'Account SID must be set' if data['account_sid'].blank? | ||
raise_config_error 'Authorization token must be set' if data['auth_token'].blank? | ||
raise_config_error 'Twilio-enabled phone number or short code must be set' if data['from_phone'].blank? | ||
raise_config_error 'Destination phone number must be set' if data['to_phone'].blank? | ||
end | ||
end | ||
|
||
def send_message(data, message) | ||
client = ::Twilio::REST::Client.new(data['account_sid'], data['auth_token']) | ||
client.account.sms.messages.create( | ||
:from => data['from_phone'], | ||
:to => data['to_phone'], | ||
:body => message | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters