Module: TwilioWrapper

Extended by:
TwilioWrapper
Included in:
TwilioWrapper
Defined in:
lib/twilio-wrapper.rb

Constant Summary collapse

API_VERSION =
'2010-04-01'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#account_sidObject

Returns the value of attribute account_sid.



8
9
10
# File 'lib/twilio-wrapper.rb', line 8

def 
  @account_sid
end

#account_tokenObject

Returns the value of attribute account_token.



8
9
10
# File 'lib/twilio-wrapper.rb', line 8

def 
  @account_token
end

#caller_idObject

Returns the value of attribute caller_id.



8
9
10
# File 'lib/twilio-wrapper.rb', line 8

def caller_id
  @caller_id
end

#caller_pinObject

Returns the value of attribute caller_pin.



8
9
10
# File 'lib/twilio-wrapper.rb', line 8

def caller_pin
  @caller_pin
end

#loggerObject

Returns the value of attribute logger.



8
9
10
# File 'lib/twilio-wrapper.rb', line 8

def logger
  @logger
end

#twilio_responseObject

Returns the value of attribute twilio_response.



8
9
10
# File 'lib/twilio-wrapper.rb', line 8

def twilio_response
  @twilio_response
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (TwilioWrapper)

    the object that the method was called on



10
11
12
13
14
# File 'lib/twilio-wrapper.rb', line 10

def configure
yield self
	
  @account = Twilio::RestAccount.new(@account_sid, @account_token)
end

#sms(recipient_number, message) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/twilio-wrapper.rb', line 16

def sms(recipient_number, message)
  payload = {
    'From' => caller_id,
    'To' => recipient_number,
    'Body' => message
  }
  
  resp = @account.request("/#{API_VERSION}/Accounts/#{@account_sid}/SMS/Messages", 'POST', payload)
  
  send_success = resp.is_a?(Net::HTTPSuccess)

if(logger)
	if(send_success)
		logger.debug("Twilio SMS Sent")
	else
		logger.warn("Twilio SMS Failed: #{resp.inspect}")
	end
end
  
  return send_success
end