Class: TwilioThinqlcr::TwilioWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/twilio_thinqlcr.rb

Overview

The main twilio wrapper class that integrates thinQ.

Constant Summary collapse

THINQ_DOMAIN =
"wap.thinq.com"
TWIML_RESOURCE_URL_DEFAULT =
"http://demo.twilio.com/docs/voice.xml"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(twilio_account_sid, twilio_account_token, thinQ_id, thinQ_token) ⇒ TwilioWrapper

Returns a new instance of TwilioWrapper.



10
11
12
13
14
15
16
17
# File 'lib/twilio_thinqlcr.rb', line 10

def initialize(, , thinQ_id, thinQ_token)
  @twilio_account_sid = 
  @twilio_account_token = 
  @thinQ_id = thinQ_id
  @thinQ_token = thinQ_token

  @client = Twilio::REST::Client.new , 
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



8
9
10
# File 'lib/twilio_thinqlcr.rb', line 8

def client
  @client
end

#thinQ_idObject

Returns the value of attribute thinQ_id.



8
9
10
# File 'lib/twilio_thinqlcr.rb', line 8

def thinQ_id
  @thinQ_id
end

#thinQ_tokenObject

Returns the value of attribute thinQ_token.



8
9
10
# File 'lib/twilio_thinqlcr.rb', line 8

def thinQ_token
  @thinQ_token
end

#twilio_account_sidObject

Returns the value of attribute twilio_account_sid.



8
9
10
# File 'lib/twilio_thinqlcr.rb', line 8

def 
  @twilio_account_sid
end

#twilio_account_tokenObject

Returns the value of attribute twilio_account_token.



8
9
10
# File 'lib/twilio_thinqlcr.rb', line 8

def 
  @twilio_account_token
end

Instance Method Details

#call(from, to, twiml_resource_url = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/twilio_thinqlcr.rb', line 23

def call(from, to, twiml_resource_url = nil)
    @twiml_resource_url = twiml_resource_url ||= TWIML_RESOURCE_URL_DEFAULT
    if !self.isClientValid?
      return "Invalid Twilio Account details."
    end

    begin
      # :url => @twiml_resource_url,
      @call = @client.calls.create({:to => "sip:#{to}@#{THINQ_DOMAIN}?thinQid=#{@thinQ_id}&thinQtoken=#{@thinQ_token}",
                                            :from => from,
                                            :url => @twiml_resource_url})
      return  @call
    rescue Exception => e
      return e.message
    end
end

#isClientValid?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/twilio_thinqlcr.rb', line 19

def isClientValid?
    !@client.nil? and !@client.accounts.nil?
end