Class: Telstra::SMS
- Inherits:
-
Object
- Object
- Telstra::SMS
- Defined in:
- lib/telstra/sms.rb
Instance Attribute Summary collapse
-
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
-
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#generate_token ⇒ Object
end.
-
#initialize(consumer_key, consumer_secret) ⇒ SMS
constructor
Initialize API Keys.
- #send(sms_body, sms_to) ⇒ Object
Constructor Details
#initialize(consumer_key, consumer_secret) ⇒ SMS
Initialize API Keys
11 12 13 14 |
# File 'lib/telstra/sms.rb', line 11 def initialize(consumer_key, consumer_secret) @consumer_key = consumer_key @consumer_secret = consumer_secret end |
Instance Attribute Details
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
8 9 10 |
# File 'lib/telstra/sms.rb', line 8 def consumer_key @consumer_key end |
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
8 9 10 |
# File 'lib/telstra/sms.rb', line 8 def consumer_secret @consumer_secret end |
#token ⇒ Object
Returns the value of attribute token.
8 9 10 |
# File 'lib/telstra/sms.rb', line 8 def token @token end |
Instance Method Details
#generate_token ⇒ Object
end
21 22 23 24 |
# File 'lib/telstra/sms.rb', line 21 def generate_token response = HTTParty.get("https://api.telstra.com/v1/oauth/token?client_id=#{@consumer_key}&client_secret=#{@consumer_secret}&grant_type=client_credentials&scope=SMS") @token = JSON.parse(response.body)['access_token'] end |
#send(sms_body, sms_to) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/telstra/sms.rb', line 26 def send(sms_body, sms_to) generate_token = { body: { body: sms_body, to: sms_to }.to_json, headers: { "Content-Type" => "application/json", "Authorization" => "Bearer #{@token}" }} HTTParty.post("https://api.telstra.com/v1/sms/messages", ) end |