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.
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
@@ -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({:friendly_name => "My Awesome Account"})
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({:name => "My Awesome SubAccount"})
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({:status => 'suspended'}
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({:status => 'active'}
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({:status => 'closed'}
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
@@ -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.account.applications.each do |app|
30
- puts app.friendly_name
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.account.applications.list({:friendly_name => 'FOO'})}.each do |app|
49
- puts app.sid
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.account.applications.create({:friendly_name => "My New App"})
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.account.applications.get(app_sid)
89
- @application.update({:voice_url => url})
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.account.applications.get(app_sid)
106
+ @client.applications.get(app_sid)
107
107
  @application.delete()
108
108
 
@@ -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.account.calls.list()
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.account.calls.list(:page=>3, :page_size=>25)
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.account.calls.get("CA123")
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.account.recordings.get("RC123")
113
+ @recording = @client.recordings.get("RC123")
101
114
  @recording.delete()
102
115
 
@@ -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.account.outgoing_caller_ids.create(:phone_number => "+44 9876543212")
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.account.outgoing_caller_ids.list(:phone_number => "+15555555555")
45
+ @response = @client.outgoing_caller_ids.list(phone_number: "+15555555555")
44
46
  @callerid = response[0]
45
47
  @callerid.delete()
@@ -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.account.conferences.list()
23
+ @conferences = @client.conferences.list()
24
24
 
25
25
  @conferences.each do |conference|
26
- puts conference.sid
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.account.conferences.list({:status => "in-progress"})
47
-
46
+ @conferences = @client.conferences.list(status: "in-progress")
47
+
48
48
  @conference.each do |conference|
49
- puts conference.friendly_name
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.account.conferences.get("CF123")
67
+ @conference = @client.conferences.get("CF123")
68
68
 
69
69
  @conference.participants.list.each.do |paricipant|
70
- puts participant.sid
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.account.conferences.get("CF123").participants.list()
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
- participant.mute()
106
+ participant.mute()
107
+ end
108
108
 
@@ -18,12 +18,12 @@ handled appropriately.
18
18
  auth_token = "YYYYYYYYYYYYYYYYYY"
19
19
 
20
20
  begin
21
- @client = Twilio::REST::Client.new account_sid, auth_token
22
- client.account.messages.create({
23
- :from => '+1234567890',
24
- :to => '+1234567890',
25
- :body => 'Hello world'
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
- puts e.message
28
+ puts e.message
29
29
  end
@@ -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.account.messages.create({:to => "+13216851234",
28
- :from => "+15555555555",
29
- :body => "Hello!"})
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.account.messages.create({:to => "+15558676309",
52
- :from => "+15555555555",
53
- :body => "Jenny I need you!",
54
- :media_url => "http://twilio.com/heart.jpg"})
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.account.messages.create({:to => "+15558676309",
62
- :from => "+15555555555",
63
- :body => "Jenny I need you!",
64
- :media_url => [
65
- "http://twilio.com/heart.jpg",
66
- "http://twilio.com/rose.jpg"
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.account.messages.list.each do |message|
84
- puts message.body
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.account.messages.list({:to => "+5466758723", :date_sent => "2011-01-01"})
129
+ @messages = @client.messages.list(
130
+ to: "+5466758723",
131
+ date_sent: "2011-01-01"
132
+ )
105
133
 
106
134
  @messages.each do |message|
107
- puts message.body
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.account.notifications.list().each do |notification|:
28
- puts notification.more_info
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.account.notifications.list(log=ERROR).each do |notification|:
46
- puts notification.error_code
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
@@ -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.account.calls.create({:to => "9991231234",
29
- :from => "9991231234",
30
- :url => "http://foo.com/call.xml"})
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.account.calls.get(sid)
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.account.calls.get(sid)
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({:call => sid})
93
- puts @client.recordings.list({:call => sid})
94
- puts @client.transcriptions.list({:call => sid})
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.account.calls.list({:status => "in-progress"})
131
+ @calls = @client.calls.list(status: "in-progress")
113
132
 
114
133
  @calls.each do |call|
115
- call.redirect_to("http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient")
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.account.calls.list({:status => "in-progress"})
149
+ @calls = @client.calls.list(status: "in-progress")
131
150
 
132
151
  @calls.each do |call|
133
- call.hangup()
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.account.calls.get(sid).redirect_to("http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient")
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.account.calls.get(sid).hangup()
184
+ @client.calls.get(sid).hangup()
166
185