twilio-ruby 3.11.5 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. checksums.yaml +13 -5
  2. data/.gitignore +1 -1
  3. data/.travis.yml +20 -9
  4. data/AUTHORS.md +32 -25
  5. data/CHANGES.md +203 -0
  6. data/Gemfile +8 -1
  7. data/{LICENSE → LICENSE.md} +4 -2
  8. data/Makefile +1 -2
  9. data/README.md +70 -39
  10. data/Rakefile +8 -10
  11. data/docs/faq.rst +3 -3
  12. data/docs/getting-started.rst +17 -12
  13. data/docs/index.rst +15 -0
  14. data/docs/usage/accounts.rst +6 -6
  15. data/docs/usage/addresses.rst +101 -0
  16. data/docs/usage/applications.rst +10 -10
  17. data/docs/usage/basics.rst +17 -4
  18. data/docs/usage/caller-ids.rst +4 -2
  19. data/docs/usage/conferences.rst +11 -11
  20. data/docs/usage/errors.rst +7 -7
  21. data/docs/usage/messages.rst +48 -20
  22. data/docs/usage/notifications.rst +6 -4
  23. data/docs/usage/phone-calls.rst +33 -14
  24. data/docs/usage/phone-numbers.rst +45 -31
  25. data/docs/usage/queues.rst +8 -8
  26. data/docs/usage/recordings.rst +12 -10
  27. data/docs/usage/sip.rst +15 -14
  28. data/docs/usage/taskrouter-tokens.rst +98 -0
  29. data/docs/usage/taskrouter.rst +226 -0
  30. data/docs/usage/token-generation.rst +19 -4
  31. data/docs/usage/transcriptions.rst +3 -2
  32. data/docs/usage/twiml.rst +7 -7
  33. data/docs/usage/validation.rst +39 -3
  34. data/examples/examples.rb +44 -20
  35. data/examples/print-call-log.rb +1 -1
  36. data/lib/rack/twilio_webhook_authentication.rb +47 -0
  37. data/lib/twilio-ruby/rest/accounts.rb +2 -1
  38. data/lib/twilio-ruby/rest/addresses/dependent_phone_numbers.rb +6 -0
  39. data/lib/twilio-ruby/rest/addresses.rb +12 -0
  40. data/lib/twilio-ruby/rest/base_client.rb +127 -0
  41. data/lib/twilio-ruby/rest/call_feedback.rb +28 -0
  42. data/lib/twilio-ruby/rest/call_feedback_summary.rb +13 -0
  43. data/lib/twilio-ruby/rest/calls.rb +10 -5
  44. data/lib/twilio-ruby/rest/client.rb +44 -109
  45. data/lib/twilio-ruby/rest/conferences/participants.rb +2 -2
  46. data/lib/twilio-ruby/rest/incoming_phone_numbers.rb +1 -1
  47. data/lib/twilio-ruby/rest/instance_resource.rb +2 -16
  48. data/lib/twilio-ruby/rest/list_resource.rb +20 -30
  49. data/lib/twilio-ruby/rest/lookups/phone_numbers.rb +17 -0
  50. data/lib/twilio-ruby/rest/lookups_client.rb +99 -0
  51. data/lib/twilio-ruby/rest/messages.rb +5 -0
  52. data/lib/twilio-ruby/rest/next_gen_list_resource.rb +36 -0
  53. data/lib/twilio-ruby/rest/outgoing_caller_ids.rb +1 -1
  54. data/lib/twilio-ruby/rest/queues/members.rb +1 -1
  55. data/lib/twilio-ruby/rest/sip.rb +1 -3
  56. data/lib/twilio-ruby/rest/sms/messages.rb +23 -0
  57. data/lib/twilio-ruby/rest/task_router/activities.rb +8 -0
  58. data/lib/twilio-ruby/rest/task_router/events.rb +8 -0
  59. data/lib/twilio-ruby/rest/task_router/reservations.rb +8 -0
  60. data/lib/twilio-ruby/rest/task_router/statistics.rb +26 -0
  61. data/lib/twilio-ruby/rest/task_router/task_queues.rb +17 -0
  62. data/lib/twilio-ruby/rest/task_router/task_queues_statistics.rb +15 -0
  63. data/lib/twilio-ruby/rest/task_router/tasks.rb +15 -0
  64. data/lib/twilio-ruby/rest/task_router/workers.rb +13 -0
  65. data/lib/twilio-ruby/rest/task_router/workers_statistics.rb +8 -0
  66. data/lib/twilio-ruby/rest/task_router/workflow_statistics.rb +7 -0
  67. data/lib/twilio-ruby/rest/task_router/workflows.rb +11 -0
  68. data/lib/twilio-ruby/rest/task_router/workspace_statistics.rb +7 -0
  69. data/lib/twilio-ruby/rest/task_router/workspaces.rb +17 -0
  70. data/lib/twilio-ruby/rest/task_router_client.rb +176 -0
  71. data/lib/twilio-ruby/rest/tokens.rb +7 -0
  72. data/lib/twilio-ruby/rest/usage/records.rb +2 -2
  73. data/lib/twilio-ruby/rest/utils.rb +35 -11
  74. data/lib/twilio-ruby/task_router/capability.rb +87 -0
  75. data/lib/twilio-ruby/task_router.rb +0 -0
  76. data/lib/twilio-ruby/twiml/response.rb +1 -0
  77. data/lib/twilio-ruby/util/capability.rb +10 -7
  78. data/lib/twilio-ruby/util/client_config.rb +29 -0
  79. data/lib/twilio-ruby/util/configuration.rb +7 -0
  80. data/lib/twilio-ruby/util/request_validator.rb +18 -3
  81. data/lib/twilio-ruby/version.rb +1 -1
  82. data/lib/twilio-ruby.rb +48 -0
  83. data/spec/rack/twilio_webhook_authentication_spec.rb +110 -0
  84. data/spec/rest/account_spec.rb +51 -20
  85. data/spec/rest/address_spec.rb +11 -0
  86. data/spec/rest/call_feedback_spec.rb +12 -0
  87. data/spec/rest/call_feedback_summary_spec.rb +9 -0
  88. data/spec/rest/call_spec.rb +8 -4
  89. data/spec/rest/client_spec.rb +209 -51
  90. data/spec/rest/conference_spec.rb +4 -2
  91. data/spec/rest/instance_resource_spec.rb +4 -4
  92. data/spec/rest/lookups/phone_number_spec.rb +8 -0
  93. data/spec/rest/message_spec.rb +2 -2
  94. data/spec/rest/numbers_spec.rb +25 -13
  95. data/spec/rest/queue_spec.rb +4 -2
  96. data/spec/rest/recording_spec.rb +4 -2
  97. data/spec/rest/sms/message_spec.rb +37 -0
  98. data/spec/rest/sms/messages_spec.rb +31 -0
  99. data/spec/rest/task_router/reservation_spec.rb +9 -0
  100. data/spec/rest/task_router/task_queue_spec.rb +9 -0
  101. data/spec/rest/token_spec.rb +7 -0
  102. data/spec/rest/utils_spec.rb +45 -0
  103. data/spec/spec_helper.rb +12 -3
  104. data/spec/support/fakeweb.rb +2 -0
  105. data/spec/task_router_spec.rb +114 -0
  106. data/spec/twilio_spec.rb +15 -0
  107. data/spec/util/capability_spec.rb +167 -118
  108. data/spec/util/client_config_spec.rb +21 -0
  109. data/spec/util/configuration_spec.rb +15 -0
  110. data/spec/util/request_validator_spec.rb +31 -3
  111. data/spec/util/url_encode_spec.rb +2 -2
  112. data/twilio-ruby.gemspec +28 -27
  113. metadata +93 -71
  114. data/CHANGES +0 -47
@@ -15,7 +15,7 @@ Searching and Buying a Number
15
15
  --------------------------------
16
16
 
17
17
  Finding numbers to buy couldn't be easier.
18
- We first search for a number in area code 530.
18
+ We first search for a US number in area code 530.
19
19
  Once we find one, we'll purchase it for our account.
20
20
 
21
21
  .. code-block:: ruby
@@ -27,12 +27,13 @@ Once we find one, we'll purchase it for our account.
27
27
  auth_token = "YYYYYYYYYYYYYYYYYY"
28
28
 
29
29
  @client = Twilio::REST::Client.new account_sid, auth_token
30
- numbers = @client.account.available_phone_numbers.list(:area_code=>"530")
30
+ numbers = @client.available_phone_numbers.get('US').list(area_code: "530")
31
31
 
32
- if numbers:
33
- numbers[0].purchase()
34
- else:
35
- print "No numbers in 530 available"
32
+ if numbers.any?
33
+ numbers[0].purchase()
34
+ else
35
+ puts "No numbers in 530 available"
36
+ end
36
37
 
37
38
 
38
39
  Local, Toll-Free, and Mobile Numbers
@@ -51,13 +52,13 @@ You can search for numbers for a given type.
51
52
  .. code-block:: ruby
52
53
 
53
54
  # local
54
- numbers = @client.account.available_phone_numbers.local.list()
55
+ numbers = @client.available_phone_numbers.get('US').local.list()
55
56
 
56
57
  # toll free
57
- numbers = @client.account.available_phone_numbers.toll_free.list()
58
+ numbers = @client.available_phone_numbers.get('US').toll_free.list()
58
59
 
59
60
  # mobile
60
- numbers = @client.account.available_phone_numbers.mobile.list()
61
+ numbers = @client.available_phone_numbers.get('UK').mobile.list()
61
62
 
62
63
  Numbers Containing Words
63
64
  ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -67,26 +68,16 @@ The following example will find any phone number with "FOO" in it.
67
68
 
68
69
  .. code-block:: ruby
69
70
 
70
- numbers = @client.account.available_phone_numbers.list(:contains=>"FOO")
71
+ numbers = @client.available_phone_numbers.get('US').list(contains: "FOO")
71
72
 
72
73
  You can use the ''*'' wildcard to match any character. The following example finds any phone number that matches the pattern ''D*D''.
73
74
 
74
75
  .. code-block:: ruby
75
76
 
76
- numbers = @client.account.available_phone_numbers.list(:contains=>"D*D")
77
-
78
-
79
- International Numbers
80
- ^^^^^^^^^^^^^^^^^^^^^^^^^^
81
-
82
- By default, the client library will look for US numbers. Set the
83
- :data:`country` keyword to a country code of your choice to search for
84
- international numbers.
85
-
86
- .. code-block:: ruby
87
-
88
- numbers = @client.account.available_phone_numbers.list(:country=>"FR")
77
+ numbers = @client.available_phone_numbers.get('US').list(contains: "D*D")
89
78
 
79
+ Other Number Searches
80
+ ^^^^^^^^^^^^^^^^^^^^^
90
81
 
91
82
  :meth:`PhoneNumbers.search` method has plenty of other options to augment your search :
92
83
 
@@ -100,6 +91,25 @@ The `AvailablePhoneNumbers REST Resource
100
91
  <http://www.twilio.com/docs/api/rest/available-phone-numbers>`_ documentation
101
92
  has more information on the various search options.
102
93
 
94
+ Numbers Requiring Addresses
95
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
96
+
97
+ Some phone numbers require you to have an address on file with Twilio to satisfy legal
98
+ requirements before they can be purchased. By default, the client library will
99
+ include numbers in the result lists regardless of their address requirements; you can
100
+ filter these numbers out when searching for phone numbers to purchase.
101
+
102
+ .. code-block:: ruby
103
+
104
+ # Exclude all numbers requiring addresses
105
+ numbers = @client.available_phone_numbers.get('AU').list(exclude_all_address_required: true)
106
+
107
+ # Exclude numbers requiring local addresses
108
+ numbers = @client.available_phone_numbers.get('AU').list(exclude_local_address_required: true)
109
+
110
+ # Exclude numbers requiring foreign addresses
111
+ numbers = @client.available_phone_numbers.get('AU').list(exclude_foreign_address_required: true)
112
+
103
113
 
104
114
  Buying a Number
105
115
  ---------------
@@ -115,7 +125,9 @@ If you've found a phone number you want, you can purchase the number.
115
125
  auth_token = "YYYYYYYYYYYYYYYYYY"
116
126
 
117
127
  @client = Twilio::REST::Client.new account_sid, auth_token
118
- @number = @client.account.phone_numbers.purchase({:phone_number => "+15305431234"})
128
+ @number = @client.available_phone_numbers.purchase(
129
+ phone_number: "+15305431234"
130
+ )
119
131
 
120
132
  However, it's easier to purchase numbers after finding them using search (as
121
133
  shown in the first example).
@@ -138,11 +150,13 @@ listed in the `IncomingPhoneNumbers Resource documentation
138
150
  auth_token = "YYYYYYYYYYYYYYYYYY"
139
151
 
140
152
  @client = Twilio::REST::Client.new account_sid, auth_token
141
- @client.account.phone_numbers.list(api_version="2010-04-01").each do |number|
142
- number.update({:voice_url => "http://twimlets.com/holdmusic?" +
143
- "Bucket=com.twilio.music.ambient",
144
- :status_callback => "http://example.com/callback"})
145
-
153
+ @client.available_phone_numbers.list.each do |number|
154
+ number.update(
155
+ voice_url: "http://twimlets.com/holdmusic?" \
156
+ "Bucket=com.twilio.music.ambient",
157
+ status_callback: "http://example.com/callback"
158
+ )
159
+ end
146
160
 
147
161
  Changing Applications
148
162
  ----------------------
@@ -161,8 +175,8 @@ An :class:`Application` encapsulates all necessary URLs for use with phone numbe
161
175
 
162
176
  phone_sid = "PNXXXXXXXXXXXXXXXXX"
163
177
 
164
- @number = @client.account.phone_numbers.get(phone_sid)
165
- @number.update(:sms_application_sid => "APXXXXXXXXXXXXXXXXXX")
178
+ @number = @client.available_phone_numbers.get(phone_sid)
179
+ @number.update(sms_application_sid: "APXXXXXXXXXXXXXXXXXX")
166
180
 
167
181
  See :doc:`/usage/applications` for instructions on updating and maintaining Applications.
168
182
 
@@ -22,10 +22,10 @@ Listing Queues
22
22
  auth_token = "YYYYYYYYYYYYYYYYYY"
23
23
 
24
24
  @client = Twilio::REST::Client.new account_sid, auth_token
25
- @queues = @client.account.queues.list()
26
-
25
+ @queues = @client.queues.list
26
+
27
27
  @queues.each do |queue|
28
- puts queue.sid
28
+ puts queue.sid
29
29
  end
30
30
 
31
31
 
@@ -44,10 +44,10 @@ represents all current calls in the queue.
44
44
  auth_token = "YYYYYYYYYYYYYYYYYY"
45
45
 
46
46
  @client = Twilio::REST::Client.new account_sid, auth_token
47
- @queue = @client.account.queues.get("QU123")
47
+ @queue = @client.queues.get("QU123")
48
48
 
49
49
  @queue.members.list().each do |member|
50
- print member.call_sid
50
+ puts member.call_sid
51
51
  end
52
52
 
53
53
 
@@ -74,8 +74,8 @@ first call in the queue.
74
74
 
75
75
  queue_sid = "QUAAAAAAAAAAAAA"
76
76
  call_sid = "CAXXXXXXXXXXXXXX"
77
-
78
- @members = @client.account.queues.get(queue_sid).members
77
+
78
+ @members = @client.queues.get(queue_sid).members
79
79
 
80
80
  # Get the first call in the queue
81
81
  puts members.front.date_enqueued
@@ -106,7 +106,7 @@ default values are 'Front' and 'GET'
106
106
 
107
107
  queue_sid = "QUAAAAAAAAAAAAA"
108
108
 
109
- @members = @client.account.queues.get(queue_sid).members
109
+ @members = @client.queues.get(queue_sid).members
110
110
 
111
111
  # Dequeue the first call in the queue
112
112
  puts @members.dequeue('http://www.twilio.com/welcome/call')
@@ -14,7 +14,7 @@ Audio Formats
14
14
 
15
15
  Each :class:`Recording` has a few special methods. To get the url
16
16
  for the wav format of this recording, use :meth:`Recording.wav`. For the
17
- mp3 format, use :meth:`Recording.mp3`. To make requests for either of
17
+ mp3 format, use :meth:`Recording.mp3`. To make requests for either of
18
18
  these formats use the same method with a '!' appended. These methods
19
19
  both take a block to be executed as soon as the response returns.
20
20
 
@@ -35,11 +35,12 @@ for each :class:`Recording`.
35
35
 
36
36
  @client = Twilio::REST::Client.new account_sid, auth_token
37
37
 
38
- @client.account.recordings.list().each do |recording|
39
- puts recording.duration
38
+ @client.recordings.list().each do |recording|
39
+ puts recording.duration
40
+ end
40
41
 
41
42
  You can filter recordings by CallSid by passing the Sid as :attr:`call`.
42
- Filter recordings using :attr:`before` and :attr:`after` dates.
43
+ Filter recordings using :attr:`DateCreated<` and :attr:`DateCreated>` dates.
43
44
 
44
45
  The following will only show recordings made before January 1, 2011.
45
46
 
@@ -52,9 +53,9 @@ The following will only show recordings made before January 1, 2011.
52
53
  auth_token = "YYYYYYYYYYYYYYYYYY"
53
54
 
54
55
  @client = Twilio::REST::Client.new account_sid, auth_token
55
- @client.account.recordings.list(before=date(2011,1,1)).each do |recording|:
56
- puts recording.duration
57
-
56
+ @client.recordings.list('DateCreated<' => '2011-01-01').each do |recording|
57
+ puts recording.duration
58
+ end
58
59
 
59
60
  Deleting Recordings
60
61
  ---------------------
@@ -70,7 +71,7 @@ The :class:`Recordings` resource allows you to delete unnecessary recordings.
70
71
  auth_token = "YYYYYYYYYYYYYYYYYY"
71
72
 
72
73
  @client = Twilio::REST::Client.new account_sid, auth_token
73
- @client.account.recordings.get("RC123").delete()
74
+ @client.recordings.get("RC123").delete()
74
75
 
75
76
 
76
77
  Accessing Related Transcptions
@@ -89,8 +90,9 @@ with this recording.
89
90
  auth_token = "YYYYYYYYYYYYYYYYYY"
90
91
 
91
92
  @client = Twilio::REST::Client.new account_sid, auth_token
92
- @recording = @client.account.recordings.get("RC123")
93
+ @recording = @client.recordings.get("RC123")
93
94
 
94
95
  @recording.transcriptions.list().each do |transcription|
95
- puts transcription.transcription_text
96
+ puts transcription.transcription_text
97
+ end
96
98
 
data/docs/usage/sip.rst CHANGED
@@ -26,10 +26,10 @@ under sip.twilio.com.
26
26
 
27
27
  @client = Twilio::REST::Client.new account_sid, auth_token
28
28
 
29
- @domain = @client.account.sip.domains.create(
30
- {:friendly_name => "The Office Domain",
31
- :voice_url => "http://example.com/voice",
32
- :domain_name => "dunder-mifflin-scranton.sip.twilio.com",}
29
+ @domain = @client.sip.domains.create(
30
+ friendly_name: "The Office Domain",
31
+ voice_url: "http://example.com/voice"
32
+ domain_name: "dunder-mifflin-scranton.sip.twilio.com"
33
33
  )
34
34
  puts @domain.sid
35
35
 
@@ -38,7 +38,7 @@ Creating a new IpAccessControlList
38
38
 
39
39
  To control access to your new domain, you'll need to explicitly grant access
40
40
  to individual ip addresses. To do this, you'll first need to create an
41
- :class:`IpAccessControlList` to hold the ip addresses you wish to allow.
41
+ :class:`IpAccessControlList` to hold the ip addresses you wish to allow.
42
42
 
43
43
  .. code-block:: ruby
44
44
 
@@ -50,8 +50,8 @@ to individual ip addresses. To do this, you'll first need to create an
50
50
 
51
51
  @client = Twilio::REST::Client.new account_sid, auth_token
52
52
 
53
- @ip_acl = @client.account.sip.ip_access_control_lists.create(
54
- {:friendly_name => "The Office IpAccessControlList",}
53
+ @ip_acl = @client.sip.ip_access_control_lists.create(
54
+ friendly_name: "The Office IpAccessControlList"
55
55
  )
56
56
  puts @ip_acl.sid
57
57
 
@@ -70,11 +70,11 @@ Now it's time to add an :class:`IpAddress` to your new :class:`IpAccessControlLi
70
70
 
71
71
  @client = Twilio::REST::Client.new account_sid, auth_token
72
72
 
73
- @ip_address = @client.account.sip.ip_access_control_lists.get(
74
- "AL456", # IpAccessControlList sid
73
+ @ip_address = @client.sip.ip_access_control_lists.get(
74
+ "AL456", # IpAccessControlList sid
75
75
  ).ip_addresses.create(
76
- {:friendly_name => "Dwights's Computer",
77
- :ip_address => "192.168.1.42",}
76
+ friendly_name: "Dwights's Computer",
77
+ ip_address: "192.168.1.42"
78
78
  )
79
79
  puts @ip_address.sid
80
80
 
@@ -94,10 +94,11 @@ associate them. To do this, create an :class:`IpAccessControlListMapping`.
94
94
 
95
95
  @client = Twilio::REST::Client.new account_sid, auth_token
96
96
 
97
- @ip_acl_mapping = @client.account.sip.domains.get(
98
- "SD456", # SIP Domain sid
97
+ @ip_acl_mapping = @client.sip.domains.get(
98
+ "SD456", # SIP Domain sid
99
99
  ).ip_access_control_list_mappings.create(
100
- {:ip_access_control_list_sid => "AL789"})
100
+ ip_access_control_list_sid: "AL789"
101
+ )
101
102
 
102
103
  puts @ip_acl_mapping.sid
103
104
 
@@ -0,0 +1,98 @@
1
+ .. module:: twilio.task_router
2
+
3
+ ============================
4
+ TaskRouter Capability Tokens
5
+ ============================
6
+
7
+
8
+ TaskRouter's Worker.js library lets you add `TaskRouter
9
+ <https://www.twilio.com/docs/taskrouter>`_ Worker Activity controls
10
+ and event notifications to your web applications. Worker.js uses a Websocket
11
+ connection to TaskRouter to receive realtime notifications of Worker
12
+ Reservations and Task details, and provides a simple API for modifying a
13
+ Worker's current Activity.
14
+
15
+ TaskRouter uses Twilio capability tokens to delegate scoped access to
16
+ TaskRouter resources to your JavaScript application. Twilio capability tokens
17
+ conform to the JSON Web Token (commonly referred to as a JWT and pronounced
18
+ "jot") standard, which allow for limited-time use of credentials by a third
19
+ party. Your web server needs to generate a Twilio capability token and provide
20
+ it to your JavaScript application in order to register a TaskRouter worker.
21
+
22
+ :class:`Capability` is responsible for the creation of these
23
+ capability tokens. You'll need your Twilio AccountSid and AuthToken,
24
+ the Sid of the Workspace you want to authorize access to, and the Sid
25
+ of the Worker you're granting authorization for.
26
+
27
+ .. code-block:: ruby
28
+
29
+ require 'twilio-ruby'
30
+
31
+ # Get these values from https://twilio.com/user/account
32
+ account_sid = "AC123"
33
+ auth_token = "secret"
34
+
35
+ # Create a Workspace and Worker in the TaskRouter account portal
36
+ # or through the TaskRouter API
37
+ worker_sid = "WK789"
38
+ worker_sid = "WK789"
39
+
40
+ @capability = Twilio::TaskRouter::Capability.new account_sid, auth_token, workspace_sid, worker_sid
41
+
42
+
43
+ By default, the Capability object will allow the Worker.js process to
44
+ read from and write to the websockets used to communicate events, and also
45
+ to fetch the list of available activities in the workspace.
46
+
47
+ There are three additional permissions you can grant using the Capability
48
+ token, and in most cases you'll want to allow all of them for your application:
49
+
50
+
51
+ Attribute Fetch
52
+ ===============
53
+
54
+ This authorizes requests to retrieve the registered Worker's attributes from
55
+ the TaskRouter API.
56
+
57
+ .. code-block:: ruby
58
+
59
+ @capability.allow_worker_fetch_attributes
60
+
61
+
62
+ Worker Activity Update
63
+ ======================
64
+
65
+ This authorizes updates to the registered Worker's current Activity.
66
+
67
+ .. code-block:: ruby
68
+
69
+ @capability.allow_worker_activity_updates
70
+
71
+
72
+ Task Reservation Update
73
+ =======================
74
+
75
+ This authorizes updates to a Task's reservation status.
76
+
77
+ .. code-block:: ruby
78
+
79
+ @capability.allow_task_reservation_updates
80
+
81
+
82
+ Generate a Token
83
+ ================
84
+
85
+ .. code-block:: ruby
86
+
87
+ token = @capability.generate_token
88
+
89
+ By default, this token will expire in one hour. If you'd like to change the
90
+ token expiration, :meth:`generate_token` takes an optional :attr:`ttl`
91
+ argument.
92
+
93
+ .. code-block:: ruby
94
+
95
+ token = @capability.generate_token(600)
96
+
97
+ This token will now expire in 10 minutes. If you haven't guessed already,
98
+ :attr:`ttl` is expressed in seconds.
@@ -0,0 +1,226 @@
1
+ .. module:: twilio.rest.resources.task_router
2
+
3
+ ==========
4
+ TaskRouter
5
+ ==========
6
+
7
+ Twilio TaskRouter is a system for distributing tasks such as phone calls,
8
+ leads, support tickets, and other work items to the people and processes that
9
+ can best handle them.
10
+
11
+ For more information, see the `TaskRouter documentation
12
+ <https://www.twilio.com/docs/taskrouter>_`.
13
+
14
+
15
+ Creating a Workspace
16
+ --------------------
17
+
18
+ A Workspace is a container for your Tasks, Workers, TaskQueues, Workflows and
19
+ Activities. Each of these items exists within a single Workspace and will not
20
+ be shared across Workspaces.
21
+
22
+ The following code will create a new :class:`Workspace` resource and print
23
+ its unique ID.
24
+
25
+ .. code-block:: ruby
26
+
27
+ require 'twilio-ruby'
28
+
29
+ # To find these visit https://www.twilio.com/user/account
30
+ ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
31
+ AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
32
+ # You can create a workspace through the portal, or put a fake value
33
+ # here to create your first workspace with the Ruby library
34
+ WORKSPACE_SID = "WSZZZZZZZZZ"
35
+
36
+ @client = Twilio::REST::TaskRouterClient.new ACCOUNT_SID, AUTH_TOKEN, WORKSPACE_SID
37
+
38
+ @workspace = @client.workspaces.create(
39
+ friendly_name: "Customer Support",
40
+ template: "FIFO", # Sets up default activities and a FIFO TaskQueue
41
+ )
42
+ puts @workspace.sid
43
+
44
+
45
+ Workflows
46
+ ---------
47
+
48
+ Workflows control how tasks will be prioritized and routed into TaskQueues, and
49
+ how Tasks should escalate in priority or move across queues over time.
50
+ Workflows are described in a simple JSON format and can be modified through the
51
+ REST API or through the account portal.
52
+
53
+ The following code will create a new :class:`Workflow` resource and print its
54
+ unique ID:
55
+
56
+ .. code-block:: ruby
57
+
58
+ require 'twilio-ruby'
59
+
60
+ # To find these visit https://www.twilio.com/user/account
61
+ ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
62
+ AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
63
+
64
+ # See previous examples to create a Workspace
65
+ WORKSPACE_SID = "WSZZZZZZZZZZZZZZ"
66
+
67
+ # Some JSON to configure the Workflow. See the documentation at
68
+ # http://www.twilio.com/docs/taskrouter for more details.
69
+ CONFIG = <<-EOS
70
+ {
71
+ "task_routing":{
72
+ "filters":[
73
+ {
74
+ "friendly_name":"Gold Tickets",
75
+ "expression":"customer_value == 'Gold' AND type == 'ticket'",
76
+ "targets":[
77
+ {
78
+ "task_queue_sid":"WQ0123456789abcdef0123456789abcdef",
79
+ "priority":"2"
80
+ }
81
+ ]
82
+ }
83
+ ],
84
+ "default_filter":{
85
+ "task_queue_sid":"WQabcdef01234567890123456789abcdef"
86
+ }
87
+ }
88
+ }
89
+ EOS
90
+
91
+ @client = Twilio::REST::TaskRouterClient.new ACCOUNT_SID, AUTH_TOKEN, WORKSPACE_SID
92
+
93
+ @workspace = @client.workflows.create(
94
+ friendly_name: "Incoming Call Flow",
95
+ assignment_callback_url: "https://example.com/callback",
96
+ fallback_assignment_callback_url: "https://example.com/callback2",
97
+ configuration: CONFIG
98
+ )
99
+ puts @workspace.sid
100
+
101
+
102
+ Activities
103
+ ----------
104
+
105
+ Activities describe the current status of your Workers, which determines
106
+ whether they are eligible to receive task assignments. Workers are always set
107
+ to a single Activity.
108
+
109
+ To create a new :class:`Activity`:
110
+
111
+ .. code-block:: ruby
112
+
113
+ require 'twilio-ruby'
114
+
115
+ # To find these visit https://www.twilio.com/user/account
116
+ ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
117
+ AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
118
+
119
+ # See previous examples to create a Workspace
120
+ WORKSPACE_SID = "WSZZZZZZZZZZZZZZ"
121
+
122
+ @client = Twilio::REST::TaskRouterClient.new ACCOUNT_SID, AUTH_TOKEN, WORKSPACE_SID
123
+
124
+ @activity = @client.activities.create(
125
+ friendly_name: "Coffee Break",
126
+ available: false # Whether workers are available to handle tasks during this activity
127
+ )
128
+ puts @activity.sid
129
+
130
+
131
+ Workers
132
+ -------
133
+
134
+ Workers represent an entity that is able to perform tasks, such as an agent
135
+ working in a call center, or a salesperson handling leads.
136
+
137
+ To create a new :class:`Worker`:
138
+
139
+ .. code-block:: ruby
140
+
141
+ require 'twilio-ruby'
142
+
143
+ # To find these visit https://www.twilio.com/user/account
144
+ ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
145
+ AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
146
+
147
+ # See previous examples to create a Workspace
148
+ WORKSPACE_SID = "WSZZZZZZZZZZZZZZ"
149
+
150
+ @client = Twilio::REST::TaskRouterClient.new ACCOUNT_SID, AUTH_TOKEN, WORKSPACE_SID
151
+
152
+ @worker = @client.workers.create(
153
+ friendly_name:"Jamie",
154
+ attributes:'{"phone": "+14155551234", "languages": ["EN", "ES"]}'
155
+ )
156
+ puts @worker.sid
157
+
158
+
159
+ TaskQueues
160
+ ----------
161
+
162
+ TaskQueues are the resource you use to categorize Tasks and describe which
163
+ Workers are eligible to handle those Tasks. As your Workflows process Tasks,
164
+ those Tasks will pass through one or more TaskQueues until the Task is assigned
165
+ and accepted by an eligible Worker.
166
+
167
+ To create a new :class:`TaskQueue`:
168
+
169
+ .. code-block:: ruby
170
+
171
+ require 'twilio-ruby'
172
+
173
+ # To find these visit https://www.twilio.com/user/account
174
+ ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
175
+ AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
176
+
177
+ # See previous examples to create a Workspace
178
+ WORKSPACE_SID = "WSZZZZZZZZZZZZZZ"
179
+
180
+ @client = Twilio::REST::TaskRouterClient.new ACCOUNT_SID, AUTH_TOKEN, WORKSPACE_SID
181
+
182
+ @queue = @client.task_queues.create(
183
+ friendly_name: "Sales",
184
+ # The Activity to assign workers when a task is reserved for them
185
+ reservation_activity_sid: "WA11111111111",
186
+ # The Activity to assign workers when a task is assigned to them
187
+ assignment_activity_sid: "WA222222222222",
188
+ )
189
+ puts @queue.sid
190
+
191
+
192
+ Tasks
193
+ -----
194
+
195
+ A Task instance resource represents a single item of work waiting to be
196
+ processed.
197
+
198
+ To create a new :class:`Task` via the REST API:
199
+
200
+ .. code-block:: ruby
201
+
202
+ # To find these visit https://www.twilio.com/user/account
203
+ ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
204
+ AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
205
+
206
+ # See previous examples to create a Workspace
207
+ WORKSPACE_SID = "WSZZZZZZZZZZZZZZ"
208
+
209
+ @client = Twilio::REST::TaskRouterClient.new ACCOUNT_SID, AUTH_TOKEN, WORKSPACE_SID
210
+
211
+ # Some JSON containing attributes for this task. User-defined.
212
+ TASK_ATTRIBUTES = <<-EOS
213
+ {
214
+ "type": "call",
215
+ "contact": "+15558675309",
216
+ "customer-value": "gold",
217
+ "task-reason": "support",
218
+ "callSid": "CA42ed11..."
219
+ }
220
+ EOS
221
+
222
+ @task = @client.create(
223
+ attributes: TASK_ATTRIBUTES,
224
+ assignment_status: 'pending',
225
+ )
226
+ puts @task.sid
@@ -14,14 +14,14 @@ Twilio Client.
14
14
  Capability tokens are used by `Twilio Client
15
15
  <http://www.twilio.com/api/client>`_ to provide connection
16
16
  security and authorization. The `Capability Token documentation
17
- <http://www.twilio.com/docs/tokens>`_ explains in depth the purpose and
17
+ <https://www.twilio.com/docs/client/capability-tokens>`_ explains in depth the purpose and
18
18
  features of these tokens.
19
19
 
20
- :class:`TwilioCapability` is responsible for the creation of these capability
21
- tokens. You'll need your Twilio AccountSid and AuthToken.
20
+ :class:`Twilio::Util::Capability` is responsible for the creation of these
21
+ capability tokens. You'll need your Twilio AccountSid and AuthToken.
22
22
 
23
23
  .. code-block:: ruby
24
-
24
+
25
25
  require 'twilio-ruby'
26
26
 
27
27
  # Find these values at twilio.com/user/account
@@ -30,6 +30,21 @@ tokens. You'll need your Twilio AccountSid and AuthToken.
30
30
 
31
31
  @capability = Twilio::Util::Capability.new account_sid, auth_token
32
32
 
33
+ You can also configure capability tokens using the top level configure method,
34
+ like so:
35
+
36
+ .. code-block:: ruby
37
+
38
+ require 'twilio-ruby'
39
+
40
+ Twilio.configure do |config|
41
+ config.account_sid = "ACXXXXXXXXXXXXXXXXX"
42
+ config.auth_token = "YYYYYYYYYYYYYYYYYY"
43
+ end
44
+
45
+ @capability = Twilio::Util::Capability.new
46
+
47
+
33
48
 
34
49
  Allow Incoming Connections
35
50
  ==============================
@@ -26,6 +26,7 @@ The following code will print out the length of each :class:`Transcription`.
26
26
  auth_token = "YYYYYYYYYYYYYYYYYY"
27
27
 
28
28
  @client = Twilio::REST::Client.new account_sid, auth_token
29
- @client.account.transcriptions.list().each do |transcription|
30
- puts transcription.duration
29
+ @client.transcriptions.list().each do |transcription|
30
+ puts transcription.duration
31
+ end
31
32