twilio-ruby 3.11.5 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.gitignore +1 -1
- data/.travis.yml +20 -9
- data/AUTHORS.md +32 -25
- data/CHANGES.md +203 -0
- data/Gemfile +8 -1
- data/{LICENSE → LICENSE.md} +4 -2
- data/Makefile +1 -2
- data/README.md +70 -39
- data/Rakefile +8 -10
- data/docs/faq.rst +3 -3
- data/docs/getting-started.rst +17 -12
- data/docs/index.rst +15 -0
- data/docs/usage/accounts.rst +6 -6
- data/docs/usage/addresses.rst +101 -0
- data/docs/usage/applications.rst +10 -10
- data/docs/usage/basics.rst +17 -4
- data/docs/usage/caller-ids.rst +4 -2
- data/docs/usage/conferences.rst +11 -11
- data/docs/usage/errors.rst +7 -7
- data/docs/usage/messages.rst +48 -20
- data/docs/usage/notifications.rst +6 -4
- data/docs/usage/phone-calls.rst +33 -14
- data/docs/usage/phone-numbers.rst +45 -31
- data/docs/usage/queues.rst +8 -8
- data/docs/usage/recordings.rst +12 -10
- data/docs/usage/sip.rst +15 -14
- data/docs/usage/taskrouter-tokens.rst +98 -0
- data/docs/usage/taskrouter.rst +226 -0
- data/docs/usage/token-generation.rst +19 -4
- data/docs/usage/transcriptions.rst +3 -2
- data/docs/usage/twiml.rst +7 -7
- data/docs/usage/validation.rst +39 -3
- data/examples/examples.rb +44 -20
- data/examples/print-call-log.rb +1 -1
- data/lib/rack/twilio_webhook_authentication.rb +47 -0
- data/lib/twilio-ruby/rest/accounts.rb +2 -1
- data/lib/twilio-ruby/rest/addresses/dependent_phone_numbers.rb +6 -0
- data/lib/twilio-ruby/rest/addresses.rb +12 -0
- data/lib/twilio-ruby/rest/base_client.rb +127 -0
- data/lib/twilio-ruby/rest/call_feedback.rb +28 -0
- data/lib/twilio-ruby/rest/call_feedback_summary.rb +13 -0
- data/lib/twilio-ruby/rest/calls.rb +10 -5
- data/lib/twilio-ruby/rest/client.rb +44 -109
- data/lib/twilio-ruby/rest/conferences/participants.rb +2 -2
- data/lib/twilio-ruby/rest/incoming_phone_numbers.rb +1 -1
- data/lib/twilio-ruby/rest/instance_resource.rb +2 -16
- data/lib/twilio-ruby/rest/list_resource.rb +20 -30
- data/lib/twilio-ruby/rest/lookups/phone_numbers.rb +17 -0
- data/lib/twilio-ruby/rest/lookups_client.rb +99 -0
- data/lib/twilio-ruby/rest/messages.rb +5 -0
- data/lib/twilio-ruby/rest/next_gen_list_resource.rb +36 -0
- data/lib/twilio-ruby/rest/outgoing_caller_ids.rb +1 -1
- data/lib/twilio-ruby/rest/queues/members.rb +1 -1
- data/lib/twilio-ruby/rest/sip.rb +1 -3
- data/lib/twilio-ruby/rest/sms/messages.rb +23 -0
- data/lib/twilio-ruby/rest/task_router/activities.rb +8 -0
- data/lib/twilio-ruby/rest/task_router/events.rb +8 -0
- data/lib/twilio-ruby/rest/task_router/reservations.rb +8 -0
- data/lib/twilio-ruby/rest/task_router/statistics.rb +26 -0
- data/lib/twilio-ruby/rest/task_router/task_queues.rb +17 -0
- data/lib/twilio-ruby/rest/task_router/task_queues_statistics.rb +15 -0
- data/lib/twilio-ruby/rest/task_router/tasks.rb +15 -0
- data/lib/twilio-ruby/rest/task_router/workers.rb +13 -0
- data/lib/twilio-ruby/rest/task_router/workers_statistics.rb +8 -0
- data/lib/twilio-ruby/rest/task_router/workflow_statistics.rb +7 -0
- data/lib/twilio-ruby/rest/task_router/workflows.rb +11 -0
- data/lib/twilio-ruby/rest/task_router/workspace_statistics.rb +7 -0
- data/lib/twilio-ruby/rest/task_router/workspaces.rb +17 -0
- data/lib/twilio-ruby/rest/task_router_client.rb +176 -0
- data/lib/twilio-ruby/rest/tokens.rb +7 -0
- data/lib/twilio-ruby/rest/usage/records.rb +2 -2
- data/lib/twilio-ruby/rest/utils.rb +35 -11
- data/lib/twilio-ruby/task_router/capability.rb +87 -0
- data/lib/twilio-ruby/task_router.rb +0 -0
- data/lib/twilio-ruby/twiml/response.rb +1 -0
- data/lib/twilio-ruby/util/capability.rb +10 -7
- data/lib/twilio-ruby/util/client_config.rb +29 -0
- data/lib/twilio-ruby/util/configuration.rb +7 -0
- data/lib/twilio-ruby/util/request_validator.rb +18 -3
- data/lib/twilio-ruby/version.rb +1 -1
- data/lib/twilio-ruby.rb +48 -0
- data/spec/rack/twilio_webhook_authentication_spec.rb +110 -0
- data/spec/rest/account_spec.rb +51 -20
- data/spec/rest/address_spec.rb +11 -0
- data/spec/rest/call_feedback_spec.rb +12 -0
- data/spec/rest/call_feedback_summary_spec.rb +9 -0
- data/spec/rest/call_spec.rb +8 -4
- data/spec/rest/client_spec.rb +209 -51
- data/spec/rest/conference_spec.rb +4 -2
- data/spec/rest/instance_resource_spec.rb +4 -4
- data/spec/rest/lookups/phone_number_spec.rb +8 -0
- data/spec/rest/message_spec.rb +2 -2
- data/spec/rest/numbers_spec.rb +25 -13
- data/spec/rest/queue_spec.rb +4 -2
- data/spec/rest/recording_spec.rb +4 -2
- data/spec/rest/sms/message_spec.rb +37 -0
- data/spec/rest/sms/messages_spec.rb +31 -0
- data/spec/rest/task_router/reservation_spec.rb +9 -0
- data/spec/rest/task_router/task_queue_spec.rb +9 -0
- data/spec/rest/token_spec.rb +7 -0
- data/spec/rest/utils_spec.rb +45 -0
- data/spec/spec_helper.rb +12 -3
- data/spec/support/fakeweb.rb +2 -0
- data/spec/task_router_spec.rb +114 -0
- data/spec/twilio_spec.rb +15 -0
- data/spec/util/capability_spec.rb +167 -118
- data/spec/util/client_config_spec.rb +21 -0
- data/spec/util/configuration_spec.rb +15 -0
- data/spec/util/request_validator_spec.rb +31 -3
- data/spec/util/url_encode_spec.rb +2 -2
- data/twilio-ruby.gemspec +28 -27
- metadata +93 -71
- data/CHANGES +0 -47
data/docs/usage/accounts.rst
CHANGED
@@ -28,7 +28,7 @@ Right now the only valid attribute is :attr:`friendly_name`.
|
|
28
28
|
|
29
29
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
30
30
|
@account = @client.accounts.get(account_sid)
|
31
|
-
@account.update(
|
31
|
+
@account.update(friendly_name: "My Awesome Account")
|
32
32
|
|
33
33
|
|
34
34
|
Creating Subaccounts
|
@@ -45,7 +45,7 @@ Subaccounts are easy to make.
|
|
45
45
|
auth_token = "YYYYYYYYYYYYYYYYYY"
|
46
46
|
|
47
47
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
48
|
-
@subaccount = @client.accounts.create(
|
48
|
+
@subaccount = @client.accounts.create(name: "My Awesome SubAccount")
|
49
49
|
|
50
50
|
|
51
51
|
Managing Subaccounts
|
@@ -70,20 +70,20 @@ Client X hasn't paid you recently, so let's suspend their account.
|
|
70
70
|
|
71
71
|
.. code-block:: ruby
|
72
72
|
|
73
|
-
@subaccount.update(
|
73
|
+
@subaccount.update(status: 'suspended')
|
74
74
|
|
75
75
|
If it was just a misunderstanding, reenable their account.
|
76
76
|
|
77
77
|
.. code-block:: ruby
|
78
78
|
|
79
|
-
@subaccount.update(
|
79
|
+
@subaccount.update(status: 'active')
|
80
80
|
|
81
81
|
Otherwise, close their account permanently.
|
82
82
|
|
83
83
|
.. code-block:: ruby
|
84
84
|
|
85
|
-
@subaccount.update(
|
85
|
+
@subaccount.update(status: 'closed')
|
86
86
|
|
87
87
|
.. warning::
|
88
|
-
This action can't be undone.
|
88
|
+
This action can't be undone.
|
89
89
|
|
@@ -0,0 +1,101 @@
|
|
1
|
+
.. module:: twilio.rest.resources
|
2
|
+
|
3
|
+
=========
|
4
|
+
Addresses
|
5
|
+
=========
|
6
|
+
|
7
|
+
An Address instance resource represents your or your customer’s physical
|
8
|
+
location within a country. Around the world, some local authorities require the
|
9
|
+
name and address of the user to be on file with Twilio to purchase and own a
|
10
|
+
phone number.
|
11
|
+
|
12
|
+
For more information, see the `Address REST Resource
|
13
|
+
<http://www.twilio.com/docs/api/rest/address`_ documentation.
|
14
|
+
|
15
|
+
Creating an Address
|
16
|
+
-------------------
|
17
|
+
|
18
|
+
Addresses contain the name of your company or your customer’s company in
|
19
|
+
addition to location information and an optional friendly name.
|
20
|
+
|
21
|
+
.. code-block:: ruby
|
22
|
+
|
23
|
+
require 'twilio-ruby'
|
24
|
+
|
25
|
+
# To find these visit https://www.twilio.com/user/account
|
26
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
27
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
28
|
+
|
29
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
30
|
+
@address = @client.addresses.create(
|
31
|
+
friendly_name: "Homer",
|
32
|
+
customer_name: "Homer Simpson",
|
33
|
+
street: "742 Evergreen Terrace",
|
34
|
+
city: "Springfield",
|
35
|
+
region "IL",
|
36
|
+
postal_code: "62701",
|
37
|
+
iso_country: "US"
|
38
|
+
)
|
39
|
+
|
40
|
+
Listing Addresses
|
41
|
+
-----------------
|
42
|
+
|
43
|
+
The following code will print out the :attr:`customer_name` for each :class:`Address`.
|
44
|
+
|
45
|
+
.. code-block:: ruby
|
46
|
+
|
47
|
+
@addresses = @client.addresses.list()
|
48
|
+
@addresses.each do |address|
|
49
|
+
puts address.customer_name
|
50
|
+
end
|
51
|
+
|
52
|
+
Filtering Addresses
|
53
|
+
-------------------
|
54
|
+
|
55
|
+
The list of Addresses can be filtered on :attr:`friendly_name`,
|
56
|
+
:attr:`customer_name`, and/or :attr:`iso_country`.
|
57
|
+
|
58
|
+
.. code-block:: ruby
|
59
|
+
|
60
|
+
@addresses = @client.addresses.list(iso_country: 'AU')
|
61
|
+
@addresses.each do |address|
|
62
|
+
puts address.customer_name
|
63
|
+
end
|
64
|
+
|
65
|
+
Updating an Address
|
66
|
+
-------------------
|
67
|
+
|
68
|
+
All Address attributes other than :attr:`iso_country` can be updated.
|
69
|
+
To create an Address with a different country, see the "Creating an Address" section.
|
70
|
+
|
71
|
+
.. code-block:: ruby
|
72
|
+
|
73
|
+
@sid = 'AD123' # the address you'd like to update
|
74
|
+
@address = @client.addresses.get(@sid)
|
75
|
+
@address.update(customer_name: "Marge Simpson")
|
76
|
+
|
77
|
+
Deleting an Address
|
78
|
+
-------------------
|
79
|
+
|
80
|
+
.. code-block:: ruby
|
81
|
+
|
82
|
+
address_sid = 'AD123'
|
83
|
+
@address = @client.addresses.get(address_sid)
|
84
|
+
@address.delete()
|
85
|
+
|
86
|
+
Listing Dependent Phone Numbers
|
87
|
+
-------------------------------
|
88
|
+
|
89
|
+
Twilio will not permit you to delete an Address if it is the sole
|
90
|
+
Address resource on your account that satisfies the address requirements
|
91
|
+
for one or more of your purchased phone numbers.
|
92
|
+
|
93
|
+
To see which phone numbers depend on a given address:
|
94
|
+
|
95
|
+
.. code-block:: ruby
|
96
|
+
|
97
|
+
address_sid = 'AD123'
|
98
|
+
@address = @client.addresses.get(address_sid)
|
99
|
+
@address.dependent_phone_numbers.list.each do |number|
|
100
|
+
puts number.sid
|
101
|
+
end
|
data/docs/usage/applications.rst
CHANGED
@@ -26,8 +26,8 @@ The following code will print out the :attr:`friendly_name` for each :class:`App
|
|
26
26
|
auth_token = "YYYYYYYYYYYYYYYYYY"
|
27
27
|
|
28
28
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
29
|
-
@client.
|
30
|
-
|
29
|
+
@client.applications.each do |app|
|
30
|
+
puts app.friendly_name
|
31
31
|
end
|
32
32
|
|
33
33
|
|
@@ -45,8 +45,8 @@ You can filter applications by FriendlyName
|
|
45
45
|
auth_token = "YYYYYYYYYYYYYYYYYY"
|
46
46
|
|
47
47
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
48
|
-
@client.
|
49
|
-
|
48
|
+
@client.applications.list(friendly_name: 'FOO').each do |app|
|
49
|
+
puts app.sid
|
50
50
|
end
|
51
51
|
|
52
52
|
|
@@ -66,8 +66,9 @@ accepts many other arguments for url configuration.
|
|
66
66
|
auth_token = "YYYYYYYYYYYYYYYYYY"
|
67
67
|
|
68
68
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
69
|
-
@application = @client.
|
70
|
-
|
69
|
+
@application = @client.applications.create(
|
70
|
+
friendly_name: "My New App"
|
71
|
+
)
|
71
72
|
|
72
73
|
Updating an Application
|
73
74
|
------------------------
|
@@ -85,9 +86,8 @@ Updating an Application
|
|
85
86
|
url = "http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient"
|
86
87
|
app_sid = 'AP123' # the app you'd like to update
|
87
88
|
|
88
|
-
@application = @client.
|
89
|
-
@application.update(
|
90
|
-
|
89
|
+
@application = @client.applications.get(app_sid)
|
90
|
+
@application.update(voice_url: url)
|
91
91
|
|
92
92
|
Deleting an Application
|
93
93
|
-------------------------
|
@@ -103,6 +103,6 @@ Deleting an Application
|
|
103
103
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
104
104
|
|
105
105
|
app_sid = 'AP123' # the app you'd like to delete
|
106
|
-
@client.
|
106
|
+
@client.applications.get(app_sid)
|
107
107
|
@application.delete()
|
108
108
|
|
data/docs/usage/basics.rst
CHANGED
@@ -27,6 +27,19 @@ Once you have your credentials, you can create create a new :class:`Client` and
|
|
27
27
|
|
28
28
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
29
29
|
|
30
|
+
You can also configure the client using the top level configure method, like so:
|
31
|
+
|
32
|
+
.. code-block:: ruby
|
33
|
+
|
34
|
+
require 'twilio-ruby'
|
35
|
+
|
36
|
+
Twilio.configure do |config|
|
37
|
+
config.account_sid = "ACXXXXXXXXXXXXXXXXX"
|
38
|
+
config.auth_token = "YYYYYYYYYYYYYYYYYY"
|
39
|
+
end
|
40
|
+
|
41
|
+
@client = Twilio::REST::Client.new
|
42
|
+
|
30
43
|
|
31
44
|
Listing Resources
|
32
45
|
-------------------
|
@@ -43,7 +56,7 @@ The :class:`Client` gives you access to various list resources.
|
|
43
56
|
auth_token = "YYYYYYYYYYYYYYYYYY"
|
44
57
|
|
45
58
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
46
|
-
@calls = @client.
|
59
|
+
@calls = @client.calls.list()
|
47
60
|
|
48
61
|
:meth:`ListResource.list` accepts paging arguments.
|
49
62
|
The following will return page 3 with page size of 25.
|
@@ -57,7 +70,7 @@ The following will return page 3 with page size of 25.
|
|
57
70
|
auth_token = "YYYYYYYYYYYYYYYYYY"
|
58
71
|
|
59
72
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
60
|
-
@calls = @client.
|
73
|
+
@calls = @client.calls.list(page: 3, page_size: 25)
|
61
74
|
|
62
75
|
|
63
76
|
Get an Individual Resource
|
@@ -76,7 +89,7 @@ Provide the :attr:`sid` of the resource you'd like to get.
|
|
76
89
|
|
77
90
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
78
91
|
|
79
|
-
@call = @client.
|
92
|
+
@call = @client.calls.get("CA123")
|
80
93
|
puts @call.to
|
81
94
|
|
82
95
|
|
@@ -97,6 +110,6 @@ and then call :meth:`delete` on it.
|
|
97
110
|
|
98
111
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
99
112
|
|
100
|
-
@recording = @client.
|
113
|
+
@recording = @client.recordings.get("RC123")
|
101
114
|
@recording.delete()
|
102
115
|
|
data/docs/usage/caller-ids.rst
CHANGED
@@ -19,7 +19,9 @@ Validating a phone number is quick and easy.
|
|
19
19
|
auth_token = "YYYYYYYYYYYYYYYYYY"
|
20
20
|
|
21
21
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
22
|
-
@response = @client.
|
22
|
+
@response = @client.outgoing_caller_ids.create(
|
23
|
+
phone_number: "+44 9876543212"
|
24
|
+
)
|
23
25
|
puts @response.validation_code
|
24
26
|
|
25
27
|
Twilio will call the provided number and wait for the validation code to be
|
@@ -40,6 +42,6 @@ Deleting a phone number is quick and easy.
|
|
40
42
|
|
41
43
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
42
44
|
|
43
|
-
@response = @client.
|
45
|
+
@response = @client.outgoing_caller_ids.list(phone_number: "+15555555555")
|
44
46
|
@callerid = response[0]
|
45
47
|
@callerid.delete()
|
data/docs/usage/conferences.rst
CHANGED
@@ -20,10 +20,10 @@ Listing Conferences
|
|
20
20
|
auth_token = "YYYYYYYYYYYYYYYYYY"
|
21
21
|
|
22
22
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
23
|
-
@conferences = @client.
|
23
|
+
@conferences = @client.conferences.list()
|
24
24
|
|
25
25
|
@conferences.each do |conference|
|
26
|
-
|
26
|
+
puts conference.sid
|
27
27
|
end
|
28
28
|
|
29
29
|
|
@@ -43,10 +43,10 @@ will return a list of all in-progress conferences and print their friendly name.
|
|
43
43
|
auth_token = "YYYYYYYYYYYYYYYYYY"
|
44
44
|
|
45
45
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
46
|
-
@conferences = @client.
|
47
|
-
|
46
|
+
@conferences = @client.conferences.list(status: "in-progress")
|
47
|
+
|
48
48
|
@conference.each do |conference|
|
49
|
-
|
49
|
+
puts conference.friendly_name
|
50
50
|
end
|
51
51
|
|
52
52
|
|
@@ -64,10 +64,10 @@ Each :class:`Conference` has a :attr:`participants` instance which represents al
|
|
64
64
|
auth_token = "YYYYYYYYYYYYYYYYYY"
|
65
65
|
|
66
66
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
67
|
-
@conference = @client.
|
67
|
+
@conference = @client.conferences.get("CF123")
|
68
68
|
|
69
69
|
@conference.participants.list.each.do |paricipant|
|
70
|
-
|
70
|
+
puts participant.sid
|
71
71
|
end
|
72
72
|
|
73
73
|
:class:`Conferences` and :class:`Participants` are subclasses of :class:`ListResource`.
|
@@ -94,15 +94,15 @@ code kicks out the first participant and mutes the rest.
|
|
94
94
|
auth_token = "YYYYYYYYYYYYYYYYYY"
|
95
95
|
|
96
96
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
97
|
-
@participants = @client.
|
97
|
+
@participants = @client.conferences.get("CF123").participants.list()
|
98
98
|
|
99
|
-
if @participants.empty?
|
100
|
-
return
|
99
|
+
return if @participants.empty?
|
101
100
|
|
102
101
|
# Kick the first person out
|
103
102
|
@participants.pop().kick()
|
104
103
|
|
105
104
|
# And mute the rest
|
106
105
|
@participants.each do |participant|
|
107
|
-
|
106
|
+
participant.mute()
|
107
|
+
end
|
108
108
|
|
data/docs/usage/errors.rst
CHANGED
@@ -18,12 +18,12 @@ handled appropriately.
|
|
18
18
|
auth_token = "YYYYYYYYYYYYYYYYYY"
|
19
19
|
|
20
20
|
begin
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
22
|
+
client.messages.create({
|
23
|
+
from: '+1234567890',
|
24
|
+
to: '+1234567890',
|
25
|
+
body: 'Hello world'
|
26
|
+
})
|
27
27
|
rescue Twilio::REST::RequestError => e
|
28
|
-
|
28
|
+
puts e.message
|
29
29
|
end
|
data/docs/usage/messages.rst
CHANGED
@@ -24,9 +24,11 @@ Send a text message in only a few lines of code.
|
|
24
24
|
|
25
25
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
26
26
|
|
27
|
-
@message = @client.
|
28
|
-
|
29
|
-
|
27
|
+
@message = @client.messages.create(
|
28
|
+
to: "+13216851234",
|
29
|
+
from: "+15555555555",
|
30
|
+
body: "Hello!"
|
31
|
+
)
|
30
32
|
|
31
33
|
If you want to send a message from a `short code
|
32
34
|
<http://www.twilio.com/api/sms/short-codes>`_ on Twilio, just set :attr:`from`
|
@@ -48,24 +50,27 @@ To send a picture, set :attr:`media_url` to the url of the picture you wish to s
|
|
48
50
|
|
49
51
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
50
52
|
|
51
|
-
@message = @client.
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
@message = @client.messages.create(
|
54
|
+
to: "+15558676309",
|
55
|
+
from: "+15555555555",
|
56
|
+
body: "Jenny I need you!",
|
57
|
+
media_url: "http://twilio.com/heart.jpg"
|
58
|
+
)
|
55
59
|
|
56
60
|
You can send multiple pictures in the same message by setting :attr:`media_url` to
|
57
61
|
an array of urls.
|
58
62
|
|
59
63
|
.. code-block:: ruby
|
60
64
|
|
61
|
-
@message = @client.
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
@message = @client.messages.create(
|
66
|
+
to: "+15558676309",
|
67
|
+
from: "+15555555555",
|
68
|
+
body: "Jenny I need you!",
|
69
|
+
media_url: [
|
70
|
+
"http://twilio.com/heart.jpg",
|
71
|
+
"http://twilio.com/rose.jpg"
|
72
|
+
]
|
73
|
+
)
|
69
74
|
|
70
75
|
Retrieving Sent Messages
|
71
76
|
-------------------------
|
@@ -80,9 +85,29 @@ Retrieving Sent Messages
|
|
80
85
|
|
81
86
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
82
87
|
|
83
|
-
@client.
|
84
|
-
|
88
|
+
@client.messages.list.each do |message|
|
89
|
+
puts message.body
|
90
|
+
end
|
91
|
+
|
92
|
+
Redacting or Deleting Messages
|
93
|
+
------------------------------
|
94
|
+
|
95
|
+
.. code-block:: ruby
|
96
|
+
|
97
|
+
require 'twilio-ruby'
|
98
|
+
|
99
|
+
# To find these visit https://www.twilio.com/user/account
|
100
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
101
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
102
|
+
|
103
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
104
|
+
@msg_sid = 'MM123'
|
105
|
+
@msg = @client.messages.get('MM123')
|
106
|
+
# Deletes the Body field contents
|
107
|
+
@msg.redact
|
85
108
|
|
109
|
+
# Removes the entire Message record
|
110
|
+
@msg.delete
|
86
111
|
|
87
112
|
Filtering Your Messages
|
88
113
|
-------------------------
|
@@ -101,9 +126,12 @@ The following will only show messages to "+5466758723" on January 1st, 2011.
|
|
101
126
|
|
102
127
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
103
128
|
|
104
|
-
@messages = @client.
|
129
|
+
@messages = @client.messages.list(
|
130
|
+
to: "+5466758723",
|
131
|
+
date_sent: "2011-01-01"
|
132
|
+
)
|
105
133
|
|
106
134
|
@messages.each do |message|
|
107
|
-
|
108
|
-
|
135
|
+
puts message.body
|
136
|
+
end
|
109
137
|
|
@@ -24,8 +24,9 @@ current :class:`Notification` resources.
|
|
24
24
|
|
25
25
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
26
26
|
|
27
|
-
@client.
|
28
|
-
|
27
|
+
@client.notifications.list.each do |notification|
|
28
|
+
puts notification.more_info
|
29
|
+
end
|
29
30
|
|
30
31
|
You can filter transcriptions by :attr:`log` and :attr:`message_date`.
|
31
32
|
The :attr:`log` value is 0 for `ERROR` and 1 for `WARNING`.
|
@@ -42,8 +43,9 @@ The :attr:`log` value is 0 for `ERROR` and 1 for `WARNING`.
|
|
42
43
|
|
43
44
|
ERROR = 0
|
44
45
|
|
45
|
-
@client.
|
46
|
-
|
46
|
+
@client.notifications.list(log=ERROR).each do |notification|
|
47
|
+
puts notification.error_code
|
48
|
+
end
|
47
49
|
|
48
50
|
.. note:: Due to the potentially voluminous amount of data in a notification,
|
49
51
|
the full HTTP request and response data is only returned in the
|
data/docs/usage/phone-calls.rst
CHANGED
@@ -25,9 +25,11 @@ outputs valid `TwiML <http://www.twilio.com/docs/api/twiml/>`_.
|
|
25
25
|
auth_token = "YYYYYYYYYYYYYYYYYY"
|
26
26
|
|
27
27
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
28
|
-
@call = @client.
|
29
|
-
|
30
|
-
|
28
|
+
@call = @client.calls.create(
|
29
|
+
to: "9991231234",
|
30
|
+
from: "9991231234",
|
31
|
+
url: "http://foo.com/call.xml"
|
32
|
+
)
|
31
33
|
puts @call.length
|
32
34
|
puts @call.sid
|
33
35
|
|
@@ -48,8 +50,25 @@ you can use the client to retrieve that record.
|
|
48
50
|
|
49
51
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
50
52
|
sid = "CA12341234"
|
51
|
-
@call = @client.
|
53
|
+
@call = @client.calls.get(sid)
|
52
54
|
|
55
|
+
Delete a Call Record
|
56
|
+
--------------------
|
57
|
+
|
58
|
+
.. code-block:: ruby
|
59
|
+
|
60
|
+
require 'twilio-ruby'
|
61
|
+
|
62
|
+
# To find these visit https://www.twilio.com/user/account
|
63
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
64
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
65
|
+
|
66
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
67
|
+
sid = "CA12341234"
|
68
|
+
@call = @client.calls.get(sid)
|
69
|
+
|
70
|
+
# Removes the entire record from Twilio's storage
|
71
|
+
@call.delete
|
53
72
|
|
54
73
|
Accessing Specific Call Resources
|
55
74
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
@@ -69,7 +88,7 @@ just like the :class:`Calls` resource itself.
|
|
69
88
|
|
70
89
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
71
90
|
sid = "CA12341234"
|
72
|
-
@call = @client.
|
91
|
+
@call = @client.calls.get(sid)
|
73
92
|
|
74
93
|
puts @call.notifications.list()
|
75
94
|
puts @call.recordings.list()
|
@@ -89,9 +108,9 @@ However, what if you only have a `CallSid`, and not the actual
|
|
89
108
|
|
90
109
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
91
110
|
sid = "CA24234"
|
92
|
-
puts @client.notifications.list(
|
93
|
-
puts @client.recordings.list(
|
94
|
-
puts @client.transcriptions.list(
|
111
|
+
puts @client.notifications.list(call: sid)
|
112
|
+
puts @client.recordings.list(call: sid)
|
113
|
+
puts @client.transcriptions.list(call: sid)
|
95
114
|
|
96
115
|
|
97
116
|
Modifying Live Calls
|
@@ -109,10 +128,10 @@ redirect them as necessary
|
|
109
128
|
auth_token = "YYYYYYYYYYYYYYYYYY"
|
110
129
|
|
111
130
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
112
|
-
@calls = @client.
|
131
|
+
@calls = @client.calls.list(status: "in-progress")
|
113
132
|
|
114
133
|
@calls.each do |call|
|
115
|
-
|
134
|
+
call.redirect_to("http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient")
|
116
135
|
end
|
117
136
|
|
118
137
|
|
@@ -127,10 +146,10 @@ Ending all live calls is also possible
|
|
127
146
|
auth_token = "YYYYYYYYYYYYYYYYYY"
|
128
147
|
|
129
148
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
130
|
-
@calls = @client.
|
149
|
+
@calls = @client.calls.list(status: "in-progress")
|
131
150
|
|
132
151
|
@calls.each do |call|
|
133
|
-
|
152
|
+
call.hangup()
|
134
153
|
end
|
135
154
|
|
136
155
|
Note that :meth:`hangup` will also cancel calls currently queued.
|
@@ -148,7 +167,7 @@ resource to update the record without having to use :meth:`get` first.
|
|
148
167
|
|
149
168
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
150
169
|
sid = "CA12341234"
|
151
|
-
@client.
|
170
|
+
@client.calls.get(sid).redirect_to("http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient")
|
152
171
|
|
153
172
|
Hanging up the call also works.
|
154
173
|
|
@@ -162,5 +181,5 @@ Hanging up the call also works.
|
|
162
181
|
|
163
182
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
164
183
|
sid = "CA12341234"
|
165
|
-
@client.
|
184
|
+
@client.calls.get(sid).hangup()
|
166
185
|
|