Class: ActionTexter::TwilioClient

Inherits:
Client
  • Object
show all
Defined in:
lib/action_texter/twilio.rb

Overview

Implementation of client for Twilio: twilio.com

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Client

default, default=, setup

Constructor Details

#initialize(account_sid, auth_token) ⇒ TwilioClient

Create a new Twilio client with account sid and auth token

Parameters:

  • account_sid (String)

    as specified by Twilio for authenticating.

  • auth_token (String)

    as specified by Twilio for authenticating.


51
52
53
54
55
# File 'lib/action_texter/twilio.rb', line 51

def initialize(, auth_token)
  super()
  self. = 
  self.auth_token = auth_token
end

Instance Attribute Details

#account_sidObject

Returns the value of attribute account_sid


45
46
47
# File 'lib/action_texter/twilio.rb', line 45

def 
  @account_sid
end

#auth_tokenObject

Returns the value of attribute auth_token


45
46
47
# File 'lib/action_texter/twilio.rb', line 45

def auth_token
  @auth_token
end

Instance Method Details

#deliver(message) ⇒ Object


57
58
59
60
61
62
63
64
65
66
# File 'lib/action_texter/twilio.rb', line 57

def deliver(message)
  http = Net::HTTP.new("api.twilio.com", 443)
  http.use_ssl = true
  request = Net::HTTP::Post.new("/2010-04-01/Accounts/#{@account_sid}/Messages.json")
  request.basic_auth(@account_sid, @auth_token)
  request.set_form_data({"From" => message.from, "To" => message.to, "Body" => message.text})
  response = http.request(request)

  return ActionTexter::TwilioResponse.new(response.body)
end

#to_sObject


69
70
71
# File 'lib/action_texter/twilio.rb', line 69

def to_s
  "#<#{self.class.name}:#{key}>"
end