restcomm-ruby 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. data/AUTHORS.md +38 -0
  2. data/CHANGES.md +171 -0
  3. data/Gemfile +11 -0
  4. data/LICENSE +662 -0
  5. data/LICENSE.md +19 -0
  6. data/Makefile +12 -0
  7. data/README.md +155 -0
  8. data/Rakefile +10 -0
  9. data/conf/cacert.pem +3376 -0
  10. data/docs/Makefile +130 -0
  11. data/docs/_themes/LICENSE +45 -0
  12. data/docs/_themes/README.rst +25 -0
  13. data/docs/_themes/flask_theme_support.py +86 -0
  14. data/docs/_themes/kr/layout.html +32 -0
  15. data/docs/_themes/kr/relations.html +19 -0
  16. data/docs/_themes/kr/static/flasky.css_t +469 -0
  17. data/docs/_themes/kr/static/small_flask.css +70 -0
  18. data/docs/_themes/kr/theme.conf +7 -0
  19. data/docs/_themes/kr_small/layout.html +22 -0
  20. data/docs/_themes/kr_small/static/flasky.css_t +287 -0
  21. data/docs/_themes/kr_small/theme.conf +10 -0
  22. data/docs/changelog.rst +1 -0
  23. data/docs/conf.py +266 -0
  24. data/docs/faq.rst +42 -0
  25. data/docs/getting-started.rst +100 -0
  26. data/docs/index.rst +109 -0
  27. data/docs/make.bat +170 -0
  28. data/docs/src/pip-delete-this-directory.txt +5 -0
  29. data/docs/usage/accounts.rst +96 -0
  30. data/docs/usage/addresses.rst +102 -0
  31. data/docs/usage/applications.rst +111 -0
  32. data/docs/usage/basics.rst +120 -0
  33. data/docs/usage/caller-ids.rst +47 -0
  34. data/docs/usage/conferences.rst +112 -0
  35. data/docs/usage/errors.rst +31 -0
  36. data/docs/usage/messages.rst +142 -0
  37. data/docs/usage/notifications.rst +72 -0
  38. data/docs/usage/phone-calls.rst +193 -0
  39. data/docs/usage/phone-numbers.rst +192 -0
  40. data/docs/usage/queues.rst +117 -0
  41. data/docs/usage/recordings.rst +102 -0
  42. data/docs/usage/sip.rst +108 -0
  43. data/docs/usage/token-generation.rst +96 -0
  44. data/docs/usage/transcriptions.rst +34 -0
  45. data/docs/usage/twiml.rst +69 -0
  46. data/docs/usage/validation.rst +107 -0
  47. data/examples/examples.rb +200 -0
  48. data/examples/print-call-log.rb +25 -0
  49. data/lib/rack/restcomm_webhook_authentication.rb +47 -0
  50. data/lib/restcomm-ruby.rb +103 -0
  51. data/lib/restcomm-ruby/rest/accounts.rb +17 -0
  52. data/lib/restcomm-ruby/rest/addresses.rb +12 -0
  53. data/lib/restcomm-ruby/rest/addresses/dependent_phone_numbers.rb +6 -0
  54. data/lib/restcomm-ruby/rest/applications.rb +6 -0
  55. data/lib/restcomm-ruby/rest/authorized_connect_apps.rb +6 -0
  56. data/lib/restcomm-ruby/rest/available_phone_numbers.rb +13 -0
  57. data/lib/restcomm-ruby/rest/available_phone_numbers/country.rb +10 -0
  58. data/lib/restcomm-ruby/rest/available_phone_numbers/local.rb +11 -0
  59. data/lib/restcomm-ruby/rest/available_phone_numbers/mobile.rb +11 -0
  60. data/lib/restcomm-ruby/rest/available_phone_numbers/toll_free.rb +11 -0
  61. data/lib/restcomm-ruby/rest/call_feedback.rb +28 -0
  62. data/lib/restcomm-ruby/rest/call_feedback_summary.rb +13 -0
  63. data/lib/restcomm-ruby/rest/calls.rb +37 -0
  64. data/lib/restcomm-ruby/rest/client.rb +555 -0
  65. data/lib/restcomm-ruby/rest/conferences.rb +12 -0
  66. data/lib/restcomm-ruby/rest/conferences/participants.rb +23 -0
  67. data/lib/restcomm-ruby/rest/connect_apps.rb +6 -0
  68. data/lib/restcomm-ruby/rest/errors.rb +14 -0
  69. data/lib/restcomm-ruby/rest/incoming_phone_numbers.rb +17 -0
  70. data/lib/restcomm-ruby/rest/incoming_phone_numbers/local.rb +13 -0
  71. data/lib/restcomm-ruby/rest/incoming_phone_numbers/mobile.rb +13 -0
  72. data/lib/restcomm-ruby/rest/incoming_phone_numbers/toll_free.rb +13 -0
  73. data/lib/restcomm-ruby/rest/instance_resource.rb +88 -0
  74. data/lib/restcomm-ruby/rest/list_resource.rb +132 -0
  75. data/lib/restcomm-ruby/rest/media.rb +14 -0
  76. data/lib/restcomm-ruby/rest/messages.rb +23 -0
  77. data/lib/restcomm-ruby/rest/next_gen_list_resource.rb +29 -0
  78. data/lib/restcomm-ruby/rest/notifications.rb +6 -0
  79. data/lib/restcomm-ruby/rest/outgoing_caller_ids.rb +25 -0
  80. data/lib/restcomm-ruby/rest/queues.rb +12 -0
  81. data/lib/restcomm-ruby/rest/queues/members.rb +29 -0
  82. data/lib/restcomm-ruby/rest/recordings.rb +35 -0
  83. data/lib/restcomm-ruby/rest/sandbox.rb +5 -0
  84. data/lib/restcomm-ruby/rest/sip.rb +10 -0
  85. data/lib/restcomm-ruby/rest/sip/credential_lists.rb +11 -0
  86. data/lib/restcomm-ruby/rest/sip/credential_lists/credentials.rb +6 -0
  87. data/lib/restcomm-ruby/rest/sip/domains.rb +12 -0
  88. data/lib/restcomm-ruby/rest/sip/domains/credential_list_mappings.rb +6 -0
  89. data/lib/restcomm-ruby/rest/sip/domains/ip_access_control_list_mappings.rb +6 -0
  90. data/lib/restcomm-ruby/rest/sip/ip_access_control_lists.rb +11 -0
  91. data/lib/restcomm-ruby/rest/sip/ip_access_control_lists/ip_addresses.rb +6 -0
  92. data/lib/restcomm-ruby/rest/sms.rb +11 -0
  93. data/lib/restcomm-ruby/rest/sms/messages.rb +39 -0
  94. data/lib/restcomm-ruby/rest/sms/short_codes.rb +8 -0
  95. data/lib/restcomm-ruby/rest/task_router/activities.rb +8 -0
  96. data/lib/restcomm-ruby/rest/task_router/events.rb +8 -0
  97. data/lib/restcomm-ruby/rest/task_router/reservations.rb +8 -0
  98. data/lib/restcomm-ruby/rest/task_router/task_queues.rb +8 -0
  99. data/lib/restcomm-ruby/rest/task_router/task_queues_statistics.rb +15 -0
  100. data/lib/restcomm-ruby/rest/task_router/tasks.rb +15 -0
  101. data/lib/restcomm-ruby/rest/task_router/workers.rb +8 -0
  102. data/lib/restcomm-ruby/rest/task_router/workers_statistics.rb +8 -0
  103. data/lib/restcomm-ruby/rest/task_router/workflow_statistics.rb +7 -0
  104. data/lib/restcomm-ruby/rest/task_router/workflows.rb +8 -0
  105. data/lib/restcomm-ruby/rest/task_router/workspace_statistics.rb +7 -0
  106. data/lib/restcomm-ruby/rest/task_router/workspaces.rb +15 -0
  107. data/lib/restcomm-ruby/rest/tokens.rb +7 -0
  108. data/lib/restcomm-ruby/rest/transcriptions.rb +6 -0
  109. data/lib/restcomm-ruby/rest/usage.rb +10 -0
  110. data/lib/restcomm-ruby/rest/usage/records.rb +21 -0
  111. data/lib/restcomm-ruby/rest/usage/triggers.rb +12 -0
  112. data/lib/restcomm-ruby/rest/utils.rb +49 -0
  113. data/lib/restcomm-ruby/task_router.rb +0 -0
  114. data/lib/restcomm-ruby/task_router/capability.rb +87 -0
  115. data/lib/restcomm-ruby/twiml/response.rb +16 -0
  116. data/lib/restcomm-ruby/util.rb +15 -0
  117. data/lib/restcomm-ruby/util/capability.rb +64 -0
  118. data/lib/restcomm-ruby/util/configuration.rb +7 -0
  119. data/lib/restcomm-ruby/util/request_validator.rb +37 -0
  120. data/lib/restcomm-ruby/version.rb +3 -0
  121. data/restcomm-ruby.gemspec +34 -0
  122. data/spec/rack/twilio_webhook_authentication_spec.rb +110 -0
  123. data/spec/rest/account_spec.rb +89 -0
  124. data/spec/rest/address_spec.rb +11 -0
  125. data/spec/rest/call_feedback_spec.rb +12 -0
  126. data/spec/rest/call_feedback_summary_spec.rb +9 -0
  127. data/spec/rest/call_spec.rb +22 -0
  128. data/spec/rest/client_spec.rb +258 -0
  129. data/spec/rest/conference_spec.rb +11 -0
  130. data/spec/rest/instance_resource_spec.rb +15 -0
  131. data/spec/rest/message_spec.rb +12 -0
  132. data/spec/rest/numbers_spec.rb +58 -0
  133. data/spec/rest/queue_spec.rb +11 -0
  134. data/spec/rest/recording_spec.rb +11 -0
  135. data/spec/rest/sms/message_spec.rb +37 -0
  136. data/spec/rest/sms/messages_spec.rb +36 -0
  137. data/spec/rest/task_router/reservation_spec.rb +9 -0
  138. data/spec/rest/task_router/task_queue_spec.rb +9 -0
  139. data/spec/rest/token_spec.rb +7 -0
  140. data/spec/rest/utils_spec.rb +45 -0
  141. data/spec/spec_helper.rb +15 -0
  142. data/spec/support/fakeweb.rb +2 -0
  143. data/spec/task_router_spec.rb +114 -0
  144. data/spec/twilio_spec.rb +15 -0
  145. data/spec/util/capability_spec.rb +186 -0
  146. data/spec/util/configuration_spec.rb +13 -0
  147. data/spec/util/request_validator_spec.rb +93 -0
  148. data/spec/util/url_encode_spec.rb +12 -0
  149. metadata +298 -0
@@ -0,0 +1,31 @@
1
+ Error Handling
2
+ ==============
3
+
4
+ Exceptions
5
+ ----------
6
+ If the Restcomm API returns a 400 or a 500 level HTTP response,
7
+ the restcomm-ruby library will throw a :class:`Restcomm::REST::RequestError`.
8
+ 400-level errors are normal during API operation ("Invalid number",
9
+ "Cannot deliver SMS to that number", for example) and should be
10
+ handled appropriately.
11
+
12
+ .. code-block:: ruby
13
+
14
+ require 'restcomm-ruby'
15
+
16
+ # To find these visit https://www.restcomm.com/user/account
17
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
18
+ auth_token = "YYYYYYYYYYYYYYYYYY"
19
+ host = "XXX.XXX.XXX.XXX"
20
+
21
+
22
+ begin
23
+ @client = Restcomm::REST::Client.new account_sid, auth_token, host
24
+ client.messages.create({
25
+ from: '+1234567890',
26
+ to: '+1234567890',
27
+ body: 'Hello world'
28
+ })
29
+ rescue Restcomm::REST::RequestError => e
30
+ puts e.message
31
+ end
@@ -0,0 +1,142 @@
1
+ .. module:: restcomm.rest.resources.sms_messages
2
+
3
+ ============
4
+ Messages
5
+ ============
6
+
7
+ For more information, see the
8
+ `Message REST Resource <http://docs.telestax.com/restcomm-pages/>`_
9
+ documentation.
10
+
11
+
12
+ Sending a Text Message
13
+ ----------------------
14
+
15
+ Send a text message in only a few lines of code.
16
+
17
+ .. code-block:: ruby
18
+
19
+ require 'restcomm-ruby'
20
+
21
+ # To find these visit http://docs.telestax.com/restcomm-pages/
22
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
23
+ auth_token = "YYYYYYYYYYYYYYYYYY"
24
+ host = "XXX.XXX.XXX.XXX"
25
+
26
+ @client = Restcomm::REST::Client.new account_sid, auth_token, host
27
+
28
+ @message = @client.messages.create(
29
+ to: "+13216851234",
30
+ from: "+15555555555",
31
+ body: "Hello!"
32
+ )
33
+
34
+ If you want to send a message from a `short code
35
+ <http://www.restcomm.com/api/sms/short-codes>`_ on Restcomm, just set :attr:`from`
36
+ to your short code's number.
37
+
38
+
39
+ Sending a Picture Message
40
+ -------------------------
41
+
42
+ To send a picture, set :attr:`media_url` to the url of the picture you wish to send.
43
+
44
+ .. code-block:: ruby
45
+
46
+ require 'restcomm-ruby'
47
+
48
+ # To find these visit http://docs.telestax.com/restcomm-pages/
49
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
50
+ auth_token = "YYYYYYYYYYYYYYYYYY"
51
+ host = "XXX.XXX.XXX.XXX"
52
+
53
+ @client = Restcomm::REST::Client.new account_sid, auth_token, host
54
+
55
+ @message = @client.messages.create(
56
+ to: "+15558676309",
57
+ from: "+15555555555",
58
+ body: "Jenny I need you!",
59
+ media_url: "http://restcomm.com/heart.jpg"
60
+ )
61
+
62
+ You can send multiple pictures in the same message by setting :attr:`media_url` to
63
+ an array of urls.
64
+
65
+ .. code-block:: ruby
66
+
67
+ @message = @client.messages.create(
68
+ to: "+15558676309",
69
+ from: "+15555555555",
70
+ body: "Jenny I need you!",
71
+ media_url: [
72
+ "http://restcomm.com/heart.jpg",
73
+ "http://restcomm.com/rose.jpg"
74
+ ]
75
+ )
76
+
77
+ Retrieving Sent Messages
78
+ -------------------------
79
+
80
+ .. code-block:: ruby
81
+
82
+ require 'restcomm-ruby'
83
+
84
+ # To find these visit http://docs.telestax.com/restcomm-pages/
85
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
86
+ auth_token = "YYYYYYYYYYYYYYYYYY"
87
+ host = "XXX.XXX.XXX.XXX"
88
+
89
+ @client = Restcomm::REST::Client.new account_sid, auth_token, host
90
+
91
+ @client.messages.list.each do |message|
92
+ puts message.body
93
+ end
94
+
95
+ Redacting or Deleting Messages
96
+ ------------------------------
97
+
98
+ .. code-block:: ruby
99
+
100
+ require 'restcomm-ruby'
101
+
102
+ # To find these visit http://docs.telestax.com/restcomm-pages/
103
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
104
+ auth_token = "YYYYYYYYYYYYYYYYYY"
105
+ host = "XXX.XXX.XXX.XXX"
106
+
107
+ @client = Restcomm::REST::Client.new account_sid, auth_token, host
108
+ @msg_sid = 'MM123'
109
+ @msg = @client.messages.get('MM123')
110
+ # Deletes the Body field contents
111
+ @msg.redact
112
+
113
+ # Removes the entire Message record
114
+ @msg.delete
115
+
116
+ Filtering Your Messages
117
+ -------------------------
118
+
119
+ The :meth:`list` methods supports filtering on :attr:`to`, :attr:`from`,
120
+ and :attr:`date_sent`.
121
+ The following will only show messages to "+5466758723" on January 1st, 2011.
122
+
123
+ .. code-block:: ruby
124
+
125
+ require 'restcomm-ruby'
126
+
127
+ # To find these visit http://docs.telestax.com/restcomm-pages/
128
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
129
+ auth_token = "YYYYYYYYYYYYYYYYYY"
130
+ host = "XXX.XXX.XXX.XXX"
131
+
132
+ @client = Restcomm::REST::Client.new account_sid, auth_token, host
133
+
134
+ @messages = @client.messages.list(
135
+ to: "+5466758723",
136
+ date_sent: "2011-01-01"
137
+ )
138
+
139
+ @messages.each do |message|
140
+ puts message.body
141
+ end
142
+
@@ -0,0 +1,72 @@
1
+ .. module:: restcomm.rest.resources
2
+
3
+ ====================
4
+ Notifications
5
+ ====================
6
+
7
+ For more information, see the `Notifications REST Resource
8
+ <http://www.restcomm.com/docs/api/rest/notification>`_ documentation.
9
+
10
+
11
+ Listing Your Notifications
12
+ ----------------------------
13
+
14
+ The following code will print out additional information about each of your
15
+ current :class:`Notification` resources.
16
+
17
+ .. code-block:: ruby
18
+
19
+ require 'restcomm-ruby'
20
+
21
+ # To find these visit https://www.restcomm.com/user/account
22
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
23
+ auth_token = "YYYYYYYYYYYYYYYYYY"
24
+
25
+ @client = Restcomm::REST::Client.new account_sid, auth_token
26
+
27
+ @client.notifications.list.each do |notification|
28
+ puts notification.more_info
29
+ end
30
+
31
+ You can filter transcriptions by :attr:`log` and :attr:`message_date`.
32
+ The :attr:`log` value is 0 for `ERROR` and 1 for `WARNING`.
33
+
34
+ .. code-block:: ruby
35
+
36
+ require 'restcomm-ruby'
37
+
38
+ # To find these visit https://www.restcomm.com/user/account
39
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
40
+ auth_token = "YYYYYYYYYYYYYYYYYY"
41
+
42
+ @client = Restcomm::REST::Client.new account_sid, auth_token
43
+
44
+ ERROR = 0
45
+
46
+ @client.notifications.list(log=ERROR).each do |notification|
47
+ puts notification.error_code
48
+ end
49
+
50
+ .. note:: Due to the potentially voluminous amount of data in a notification,
51
+ the full HTTP request and response data is only returned in the
52
+ :class:`Notification` instance resource representation.
53
+
54
+
55
+ Deleting Notifications
56
+ ------------------------
57
+
58
+ Your account can sometimes generate an inordinate amount of
59
+ :class:`Notification` resources. The :class:`Notifications` resource allows
60
+ you to delete unnecessary notifications.
61
+
62
+ .. code-block:: ruby
63
+
64
+ require 'restcomm-ruby'
65
+
66
+ # To find these visit https://www.restcomm.com/user/account
67
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
68
+ auth_token = "YYYYYYYYYYYYYYYYYY"
69
+
70
+ @client = Restcomm::REST::Client.new account_sid, auth_token
71
+ @client.notifications.get("NO123").delete()
72
+
@@ -0,0 +1,193 @@
1
+ .. module:: restcomm.rest
2
+ .. _phone-calls:
3
+
4
+ =====================
5
+ Phone Calls
6
+ =====================
7
+
8
+ The :class:`Calls` resource manages all interaction with Restcomm phone calls,
9
+ including the creation and termination of phone calls.
10
+
11
+
12
+ Making a Phone Call
13
+ -------------------
14
+
15
+ The :class:`Calls` resource allows you to make outgoing calls. Before a call
16
+ can be successfully started, you'll need a to set up a url endpoint which
17
+ outputs valid `RCML <http://docs.telestax.com/restcomm-pages/>`_.
18
+
19
+ .. code-block:: ruby
20
+
21
+ require 'restcomm-ruby'
22
+
23
+ # To find these visit http://docs.telestax.com/restcomm-pages/
24
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
25
+ auth_token = "YYYYYYYYYYYYYYYYYY"
26
+ host = "XXX.XXX.XXX.XXX"
27
+
28
+ @client = Restcomm::REST::Client.new account_sid, auth_token, host
29
+ @call = @client.calls.create(
30
+ to: "9991231234",
31
+ from: "9991231234",
32
+ url: "http://foo.com/call.xml"
33
+ )
34
+ puts @call.length
35
+ puts @call.sid
36
+
37
+
38
+ Retrieve a Call Record
39
+ -------------------------
40
+
41
+ If you already have a :class:`Call` sid,
42
+ you can use the client to retrieve that record.
43
+
44
+ .. code-block:: ruby
45
+
46
+ require 'restcomm-ruby'
47
+
48
+ # To find these visit http://docs.telestax.com/restcomm-pages/
49
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
50
+ auth_token = "YYYYYYYYYYYYYYYYYY"
51
+ host = "XXX.XXX.XXX.XXX"
52
+
53
+ @client = Restcomm::REST::Client.new account_sid, auth_token, host
54
+ sid = "CA12341234"
55
+ @call = @client.calls.get(sid)
56
+
57
+ Delete a Call Record
58
+ --------------------
59
+
60
+ .. code-block:: ruby
61
+
62
+ require 'restcomm-ruby'
63
+
64
+ # To find these visit http://docs.telestax.com/restcomm-pages/
65
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
66
+ auth_token = "YYYYYYYYYYYYYYYYYY"
67
+ host = "XXX.XXX.XXX.XXX"
68
+
69
+ @client = Restcomm::REST::Client.new account_sid, auth_token, host
70
+ sid = "CA12341234"
71
+ @call = @client.calls.get(sid)
72
+
73
+ # Removes the entire record from Restcomm's storage
74
+ @call.delete
75
+
76
+ Accessing Specific Call Resources
77
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78
+
79
+ Each :class:`Call` resource also has access to its `notifications`,
80
+ `recordings`, and `transcriptions`.
81
+ These attributes are :class:`ListResources`,
82
+ just like the :class:`Calls` resource itself.
83
+
84
+ .. code-block:: ruby
85
+
86
+ require 'restcomm-ruby'
87
+
88
+ # To find these visit http://docs.telestax.com/restcomm-pages/
89
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
90
+ auth_token = "YYYYYYYYYYYYYYYYYY"
91
+ host = "XXX.XXX.XXX.XXX"
92
+
93
+ @client = Restcomm::REST::Client.new account_sid, auth_token, host
94
+ sid = "CA12341234"
95
+ @call = @client.calls.get(sid)
96
+
97
+ puts @call.notifications.list()
98
+ puts @call.recordings.list()
99
+ puts @call.transcriptions.list()
100
+
101
+ However, what if you only have a `CallSid`, and not the actual
102
+ :class:`Resource`? No worries, as :meth:`list` can be filter based on a given
103
+ `CallSid`.
104
+
105
+ .. code-block:: ruby
106
+
107
+ require 'restcomm-ruby'
108
+
109
+ # To find these visit http://docs.telestax.com/restcomm-pages/
110
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
111
+ auth_token = "YYYYYYYYYYYYYYYYYY"
112
+ host = "XXX.XXX.XXX.XXX"
113
+
114
+ @client = Restcomm::REST::Client.new account_sid, auth_token, host
115
+ sid = "CA24234"
116
+ puts @client.notifications.list(call: sid)
117
+ puts @client.recordings.list(call: sid)
118
+ puts @client.transcriptions.list(call: sid)
119
+
120
+
121
+ Modifying Live Calls
122
+ --------------------
123
+
124
+ The :class:`Call` resource makes it easy to find current live calls and
125
+ redirect them as necessary
126
+
127
+ .. code-block:: ruby
128
+
129
+ require 'restcomm-ruby'
130
+
131
+ # To find these visit http://docs.telestax.com/restcomm-pages/
132
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
133
+ auth_token = "YYYYYYYYYYYYYYYYYY"
134
+ host = "XXX.XXX.XXX.XXX"
135
+
136
+ @client = Restcomm::REST::Client.new account_sid, auth_token, host
137
+ @calls = @client.calls.list(status: "in-progress")
138
+
139
+ @calls.each do |call|
140
+ call.redirect_to("http://twimlets.com/holdmusic?Bucket=com.restcomm.music.ambient")
141
+ end
142
+
143
+
144
+ Ending all live calls is also possible
145
+
146
+ .. code-block:: ruby
147
+
148
+ require 'restcomm-ruby'
149
+
150
+ # To find these visit http://docs.telestax.com/restcomm-pages/
151
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
152
+ auth_token = "YYYYYYYYYYYYYYYYYY"
153
+ host = "XXX.XXX.XXX.XXX"
154
+
155
+ @client = Restcomm::REST::Client.new account_sid, auth_token, host
156
+ @calls = @client.calls.list(status: "in-progress")
157
+
158
+ @calls.each do |call|
159
+ call.hangup()
160
+ end
161
+
162
+ Note that :meth:`hangup` will also cancel calls currently queued.
163
+
164
+ If you already have a :class:`Call` sid, you can use the :class:`Calls`
165
+ resource to update the record without having to use :meth:`get` first.
166
+
167
+ .. code-block:: ruby
168
+
169
+ require 'restcomm-ruby'
170
+
171
+ # To find these visit http://docs.telestax.com/restcomm-pages/
172
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
173
+ auth_token = "YYYYYYYYYYYYYYYYYY"
174
+ host = "XXX.XXX.XXX.XXX"
175
+
176
+ @client = Restcomm::REST::Client.new account_sid, auth_token, host
177
+ sid = "CA12341234"
178
+ @client.calls.get(sid).redirect_to("http://twimlets.com/holdmusic?Bucket=com.restcomm.music.ambient")
179
+
180
+ Hanging up the call also works.
181
+
182
+ .. code-block:: ruby
183
+
184
+ require 'restcomm-ruby'
185
+
186
+ # To find these visit http://docs.telestax.com/restcomm-pages/
187
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
188
+ auth_token = "YYYYYYYYYYYYYYYYYY"
189
+
190
+ @client = Restcomm::REST::Client.new account_sid, auth_token
191
+ sid = "CA12341234"
192
+ @client.calls.get(sid).hangup()
193
+
@@ -0,0 +1,192 @@
1
+ .. module:: restcomm.rest.resources
2
+
3
+ =================
4
+ Phone Numbers
5
+ =================
6
+
7
+ With Restcomm you can search and buy real phone numbers, just using the API.
8
+
9
+ For more information, see the
10
+ `IncomingPhoneNumbers REST Resource
11
+ <http://docs.telestax.com/restcomm-pages/>`_ documentation.
12
+
13
+
14
+ Searching and Buying a Number
15
+ --------------------------------
16
+
17
+ Finding numbers to buy couldn't be easier.
18
+ We first search for a US number in area code 530.
19
+ Once we find one, we'll purchase it for our account.
20
+
21
+ .. code-block:: ruby
22
+
23
+ require 'restcomm-ruby'
24
+
25
+ # To find these visit http://docs.telestax.com/restcomm-pages/
26
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
27
+ auth_token = "YYYYYYYYYYYYYYYYYY"
28
+ host = "XXX.XXX.XXX.XXX"
29
+
30
+ @client = Restcomm::REST::Client.new account_sid, auth_token, host
31
+ numbers = @client.available_phone_numbers.get('US').list(area_code: "530")
32
+
33
+ if numbers.any?
34
+ numbers[0].purchase()
35
+ else
36
+ puts "No numbers in 530 available"
37
+ end
38
+
39
+
40
+ Local, Toll-Free, and Mobile Numbers
41
+ ------------------------------------
42
+
43
+ By default, :meth:`PhoneNumbers.search` looks for local phone numbers. You can
44
+ search for different types of numbers by using a type subresource.
45
+
46
+ Available subresources for AvailablePhoneNumbers are:
47
+ - `local`
48
+ - `toll_free`
49
+ - `mobile`
50
+
51
+ You can search for numbers for a given type.
52
+
53
+ .. code-block:: ruby
54
+
55
+ # local
56
+ numbers = @client.available_phone_numbers.get('US').local.list()
57
+
58
+ # toll free
59
+ numbers = @client.available_phone_numbers.get('US').toll_free.list()
60
+
61
+ # mobile
62
+ numbers = @client.available_phone_numbers.get('UK').mobile.list()
63
+
64
+ Numbers Containing Words
65
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
66
+
67
+ Phone number search also supports looking for words inside phone numbers.
68
+ The following example will find any phone number with "FOO" in it.
69
+
70
+ .. code-block:: ruby
71
+
72
+ numbers = @client.available_phone_numbers.get('US').list(contains: "FOO")
73
+
74
+ You can use the ''*'' wildcard to match any character. The following example finds any phone number that matches the pattern ''D*D''.
75
+
76
+ .. code-block:: ruby
77
+
78
+ numbers = @client.available_phone_numbers.get('US').list(contains: "D*D")
79
+
80
+ Other Number Searches
81
+ ^^^^^^^^^^^^^^^^^^^^^
82
+
83
+ :meth:`PhoneNumbers.search` method has plenty of other options to augment your search :
84
+
85
+ - :data:`region`: When searching the US, show numbers in this state
86
+ - :data:`postal_code`: Only show numbers in this area code
87
+ - :data:`rate_center`: US only.
88
+ - :data:`near_lat_long`: Find numbers near this latitude and longitude.
89
+ - :data:`distance`: Search radius for a Near- query in miles.
90
+
91
+ The `AvailablePhoneNumbers REST Resource
92
+ <http://www.restcomm.com/docs/api/rest/available-phone-numbers>`_ documentation
93
+ has more information on the various search options.
94
+
95
+ Numbers Requiring Addresses
96
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
97
+
98
+ Some phone numbers require you to have an address on file with Restcomm to satisfy legal
99
+ requirements before they can be purchased. By default, the client library will
100
+ include numbers in the result lists regardless of their address requirements; you can
101
+ filter these numbers out when searching for phone numbers to purchase.
102
+
103
+ .. code-block:: ruby
104
+
105
+ # Exclude all numbers requiring addresses
106
+ numbers = @client.available_phone_numbers.get('AU').list(exclude_all_address_required: true)
107
+
108
+ # Exclude numbers requiring local addresses
109
+ numbers = @client.available_phone_numbers.get('AU').list(exclude_local_address_required: true)
110
+
111
+ # Exclude numbers requiring foreign addresses
112
+ numbers = @client.available_phone_numbers.get('AU').list(exclude_foreign_address_required: true)
113
+
114
+
115
+ Buying a Number
116
+ ---------------
117
+
118
+ If you've found a phone number you want, you can purchase the number.
119
+
120
+ .. code-block:: ruby
121
+
122
+ require 'restcomm-ruby'
123
+
124
+ # To find these visit http://docs.telestax.com/restcomm-pages/
125
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
126
+ auth_token = "YYYYYYYYYYYYYYYYYY"
127
+ host = "XXX.XXX.XXX.XXX"
128
+
129
+ @client = Restcomm::REST::Client.new account_sid, auth_token, host
130
+ @number = @client.available_phone_numbers.purchase(
131
+ phone_number: "+15305431234"
132
+ )
133
+
134
+ However, it's easier to purchase numbers after finding them using search (as
135
+ shown in the first example).
136
+
137
+
138
+ Updating Properties on a Number
139
+ -------------------------------
140
+
141
+ To update the properties on a phone number, call :meth:`update`
142
+ on the phone number object, with any of the parameters
143
+ listed in the `IncomingPhoneNumbers Resource documentation
144
+ <http://docs.telestax.com/restcomm-pages/>`_
145
+
146
+ .. code-block:: ruby
147
+
148
+ require 'restcomm-ruby'
149
+
150
+ # To find these visit http://docs.telestax.com/restcomm-pages/
151
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
152
+ auth_token = "YYYYYYYYYYYYYYYYYY"
153
+ host = "XXX.XXX.XXX.XXX"
154
+
155
+ @client = Restcomm::REST::Client.new account_sid, auth_token, host
156
+ @client.available_phone_numbers.list.each do |number|
157
+ number.update(
158
+ voice_url: "http://twimlets.com/holdmusic?" \
159
+ "Bucket=com.restcomm.music.ambient",
160
+ status_callback: "http://example.com/callback"
161
+ )
162
+ end
163
+
164
+ Changing Applications
165
+ ----------------------
166
+
167
+ An :class:`Application` encapsulates all necessary URLs for use with phone numbers. Update an application on a phone number using :meth:`update`.
168
+
169
+ .. code-block:: ruby
170
+
171
+ require 'restcomm-ruby'
172
+
173
+ # To find these visit http://docs.telestax.com/restcomm-pages/
174
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
175
+ auth_token = "YYYYYYYYYYYYYYYYYY"
176
+ host = "XXX.XXX.XXX.XXX"
177
+
178
+ @client = Restcomm::REST::Client.new account_sid, auth_token, host
179
+
180
+ phone_sid = "PNXXXXXXXXXXXXXXXXX"
181
+
182
+ @number = @client.available_phone_numbers.get(phone_sid)
183
+ @number.update(sms_application_sid: "APXXXXXXXXXXXXXXXXXX")
184
+
185
+ See :doc:`/usage/applications` for instructions on updating and maintaining Applications.
186
+
187
+
188
+ Validate a Phone Number
189
+ -----------------------
190
+
191
+ See validation instructions here: :doc:`/usage/caller-ids`:
192
+