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
@@ -1,3 +1,4 @@
1
+ require 'twilio-ruby/rest/base_client'
1
2
  module Twilio
2
3
  module REST
3
4
  ##
@@ -28,6 +29,12 @@ module Twilio
28
29
  #
29
30
  # @client.account.calls
30
31
  #
32
+ # For convenience, the resources of the default account are also available
33
+ # on the client object. So the following call is equivalent to the example
34
+ # above
35
+ #
36
+ # @client.calls
37
+ #
31
38
  # represents an account's call list.
32
39
  #
33
40
  # ==== @client.accounts
@@ -41,75 +48,51 @@ module Twilio
41
48
  # methods like ListResource#list to return a (possibly filtered) list of
42
49
  # accounts and ListResource#create to create a new account. Use
43
50
  # ListResource#get to grab a particular account once you know its sid.
44
- class Client
45
- include Twilio::Util
46
- include Twilio::REST::Utils
47
-
51
+ class Client < BaseClient
48
52
  API_VERSION = '2010-04-01'
49
53
 
50
- # 1.8.7 doesn't have the RUBY_ENGINE constant.
51
- engine = !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby'
52
-
53
- HTTP_HEADERS = {
54
- 'Accept' => 'application/json',
55
- 'Accept-Charset' => 'utf-8',
56
- 'User-Agent' => "twilio-ruby/#{Twilio::VERSION} (#{engine}/#{RUBY_PLATFORM} #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL})",
57
- }
54
+ attr_reader :account, :accounts
58
55
 
59
- DEFAULTS = {
60
- :host => 'api.twilio.com',
61
- :port => 443,
62
- :use_ssl => true,
63
- :ssl_verify_peer => true,
64
- :ssl_ca_file => File.dirname(__FILE__) + '/../../../conf/cacert.pem',
65
- :timeout => 30,
66
- :proxy_addr => nil,
67
- :proxy_port => nil,
68
- :proxy_user => nil,
69
- :proxy_pass => nil,
70
- :retry_limit => 1,
71
- }
72
-
73
- attr_reader :account_sid, :account, :accounts, :last_request,
74
- :last_response
56
+ host 'api.twilio.com'
75
57
 
76
58
  ##
77
59
  # Instantiate a new HTTP client to talk to Twilio. The parameters
78
- # +account_sid+ and +auth_token+ are required and used to generate the
60
+ # +account_sid+ and +auth_token+ are required, unless you have configured
61
+ # them already using the block configure syntax, and used to generate the
79
62
  # HTTP basic auth header in each request. The +options+ parameter is a
80
63
  # hash of connection configuration options. the following keys are
81
64
  # supported:
82
65
  #
83
- # === <tt>:host => 'api.twilio.com'</tt>
66
+ # === <tt>host: 'api.twilio.com'</tt>
84
67
  #
85
68
  # The domain to which you'd like the client to make HTTP requests. Useful
86
69
  # for testing. Defaults to 'api.twilio.com'.
87
70
  #
88
- # === <tt>:port => 443</tt>
71
+ # === <tt>port: 443</tt>
89
72
  #
90
73
  # The port on which to connect to the above domain. Defaults to 443 and
91
74
  # should be left that way except in testing environments.
92
75
  #
93
- # === <tt>:use_ssl => true</tt>
76
+ # === <tt>use_ssl: true</tt>
94
77
  #
95
78
  # Declare whether ssl should be used for connections to the above domain.
96
79
  # Defaults to true and should be left alone except when testing.
97
80
  #
98
- # === <tt>:ssl_verify_peer => true</tt>
81
+ # === <tt>ssl_verify_peer: true</tt>
99
82
  #
100
83
  # Declare whether to verify the host's ssl cert when setting up the
101
84
  # connection to the above domain. Defaults to true, but can be turned off
102
85
  # to avoid ssl certificate verification failures in environments without
103
86
  # the necessary ca certificates.
104
87
  #
105
- # === <tt>:ssl_ca_file => '/path/to/ca/file'</tt>
88
+ # === <tt>ssl_ca_file: '/path/to/ca/file'</tt>
106
89
  #
107
90
  # Specify the path to the certificate authority bundle you'd like to use
108
91
  # to verify Twilio's SSL certificate on each request. If not specified, a
109
92
  # certificate bundle extraced from Firefox is packaged with the gem and
110
93
  # used by default.
111
94
  #
112
- # === <tt>:timeout => 30</tt>
95
+ # === <tt>timeout: 30</tt>
113
96
  #
114
97
  # Set the time in seconds to wait before timing out the HTTP request.
115
98
  # Defaults to 30 seconds. If you aren't fetching giant pages of call or
@@ -117,32 +100,29 @@ module Twilio
117
100
  # lower. In paricular if you are sending SMS you can set this to 1 second
118
101
  # or less and swallow the exception if you don't care about the response.
119
102
  #
120
- # === <tt>:proxy_addr => 'proxy.host.domain'</tt>
103
+ # === <tt>proxy_addr: 'proxy.host.domain'</tt>
121
104
  #
122
105
  # The domain of a proxy through which you'd like the client to make HTTP
123
106
  # requests. Defaults to nil.
124
107
  #
125
- # === <tt>:proxy_port => 3128</tt>
108
+ # === <tt>proxy_port: 3128</tt>
126
109
  #
127
110
  # The port on which to connect to the above proxy. Defaults to nil.
128
111
  #
129
- # === <tt>:proxy_user => 'username'</tt>
112
+ # === <tt>proxy_user: 'username'</tt>
130
113
  #
131
114
  # The user name to use for authentication with the proxy. Defaults to nil.
132
115
  #
133
- # === <tt>:proxy_pass => 'password'</tt>
116
+ # === <tt>proxy_pass: 'password'</tt>
134
117
  #
135
118
  # The password to use for authentication with the proxy. Defaults to nil.
136
119
  #
137
- # === <tt>:retry_limit => 1</tt>
120
+ # === <tt>retry_limit: 1</tt>
138
121
  #
139
122
  # The number of times to retry a request that has failed before throwing
140
123
  # an exception. Defaults to one.
141
- def initialize(account_sid, auth_token, options={})
142
- @account_sid, @auth_token = account_sid.strip, auth_token.strip
143
- @config = DEFAULTS.merge! options
144
- set_up_connection
145
- set_up_subresources
124
+ def initialize(*args)
125
+ super(*args)
146
126
  end
147
127
 
148
128
  def inspect # :nodoc:
@@ -150,52 +130,27 @@ module Twilio
150
130
  end
151
131
 
152
132
  ##
153
- # Define #get, #put, #post and #delete helper methods for sending HTTP
154
- # requests to Twilio. You shouldn't need to use these methods directly,
155
- # but they can be useful for debugging. Each method returns a hash
156
- # obtained from parsing the JSON object in the response body.
157
- [:get, :put, :post, :delete].each do |method|
158
- method_class = Net::HTTP.const_get method.to_s.capitalize
159
- define_method method do |path, *args|
160
- params = twilify args[0]; params = {} if params.empty?
161
- unless args[1] # build the full path unless already given
162
- path = "#{path}.json"
163
- path << "?#{url_encode(params)}" if method == :get && !params.empty?
164
- end
165
- request = method_class.new path, HTTP_HEADERS
166
- request.basic_auth @account_sid, @auth_token
167
- request.form_data = params if [:post, :put].include? method
168
- connect_and_send request
133
+ # Delegate account methods from the client. This saves having to call
134
+ # <tt>client.account</tt> every time for resources on the default
135
+ # account.
136
+ def method_missing(method_name, *args, &block)
137
+ if account.respond_to?(method_name)
138
+ account.send(method_name, *args, &block)
139
+ else
140
+ super
169
141
  end
170
142
  end
171
143
 
172
- private
173
-
174
- ##
175
- # Set up and cache a Net::HTTP object to use when making requests. This is
176
- # a private method documented for completeness.
177
- def set_up_connection # :doc:
178
- connection_class = Net::HTTP::Proxy @config[:proxy_addr],
179
- @config[:proxy_port], @config[:proxy_user], @config[:proxy_pass]
180
- @connection = connection_class.new @config[:host], @config[:port]
181
- set_up_ssl
182
- @connection.open_timeout = @config[:timeout]
183
- @connection.read_timeout = @config[:timeout]
184
- end
185
-
186
- ##
187
- # Set up the ssl properties of the <tt>@connection</tt> Net::HTTP object.
188
- # This is a private method documented for completeness.
189
- def set_up_ssl # :doc:
190
- @connection.use_ssl = @config[:use_ssl]
191
- if @config[:ssl_verify_peer]
192
- @connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
193
- @connection.ca_file = @config[:ssl_ca_file]
144
+ def respond_to?(method_name, include_private=false)
145
+ if account.respond_to?(method_name, include_private)
146
+ true
194
147
  else
195
- @connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
148
+ super
196
149
  end
197
150
  end
198
151
 
152
+ protected
153
+
199
154
  ##
200
155
  # Set up +account+ and +accounts+ attributes.
201
156
  def set_up_subresources # :doc:
@@ -204,31 +159,11 @@ module Twilio
204
159
  end
205
160
 
206
161
  ##
207
- # Send an HTTP request using the cached <tt>@connection</tt> object and
208
- # return the JSON response body parsed into a hash. Also save the raw
209
- # Net::HTTP::Request and Net::HTTP::Response objects as
210
- # <tt>@last_request</tt> and <tt>@last_response</tt> to allow for
211
- # inspection later.
212
- def connect_and_send(request) # :doc:
213
- @last_request = request
214
- retries_left = @config[:retry_limit]
215
- begin
216
- response = @connection.request request
217
- @last_response = response
218
- if response.kind_of? Net::HTTPServerError
219
- raise Twilio::REST::ServerError
220
- end
221
- rescue Exception
222
- raise if request.class == Net::HTTP::Post
223
- if retries_left > 0 then retries_left -= 1; retry else raise end
224
- end
225
- if response.body and !response.body.empty?
226
- object = MultiJson.load response.body
227
- end
228
- if response.kind_of? Net::HTTPClientError
229
- raise Twilio::REST::RequestError.new object['message'], object['code']
230
- end
231
- object
162
+ # Builds up full request path
163
+ def build_full_path(path, params, method)
164
+ path = "#{path}.json"
165
+ path << "?#{url_encode(params)}" if method == :get && !params.empty?
166
+ path
232
167
  end
233
168
  end
234
169
  end
@@ -10,11 +10,11 @@ module Twilio
10
10
 
11
11
  class Participant < InstanceResource
12
12
  def mute
13
- update :muted => 'true'
13
+ update muted: 'true'
14
14
  end
15
15
 
16
16
  def unmute
17
- update :muted => 'false'
17
+ update muted: 'false'
18
18
  end
19
19
 
20
20
  alias :kick :delete
@@ -8,7 +8,7 @@ module Twilio
8
8
  end
9
9
 
10
10
  def buy(phone_number)
11
- create :phone_number => phone_number
11
+ create phone_number: phone_number
12
12
  end
13
13
  end
14
14
 
@@ -32,7 +32,7 @@ module Twilio
32
32
  # to handle the update. For example, to update the +VoiceUrl+ of a Twilio
33
33
  # Application you could write:
34
34
  #
35
- # @app.update :voice_url => 'http://my.other.app.com/handle_voice'
35
+ # @app.update voice_url: 'http://my.other.app.com/handle_voice'
36
36
  #
37
37
  # After returning, the object will contain the most recent state of the
38
38
  # instance resource, including the newly updated properties.
@@ -77,25 +77,11 @@ module Twilio
77
77
  hash.each do |p,v|
78
78
  property = detwilify p
79
79
  unless ['client', 'updated'].include? property
80
- eigenclass.send :define_method, property.to_sym, &lambda {v}
80
+ eigenclass.send :define_method, property.to_sym, &lambda { v }
81
81
  end
82
82
  end
83
83
  @updated = !hash.keys.empty?
84
84
  end
85
-
86
- def resource(*resources)
87
- custom_resource_names = {:sms => 'SMS', :sip => 'SIP'}
88
- resources.each do |r|
89
- resource = twilify r
90
- relative_path = custom_resource_names.fetch(r, resource)
91
- path = "#{@path}/#{relative_path}"
92
- enclosing_module = @submodule == nil ? (Twilio::REST) : (Twilio::REST.const_get(@submodule))
93
- resource_class = enclosing_module.const_get resource
94
- instance_variable_set("@#{r}", resource_class.new(path, @client))
95
- end
96
- self.class.instance_eval {attr_reader *resources}
97
- end
98
-
99
85
  end
100
86
  end
101
87
  end
@@ -3,9 +3,14 @@ module Twilio
3
3
  class ListResource
4
4
  include Utils
5
5
 
6
-
7
6
  def initialize(path, client)
8
- custom_names = {"Media" => "MediaInstance", "IpAddresses" => "IpAddress"}
7
+ custom_names = {
8
+ 'Activities' => 'Activity',
9
+ 'Media' => 'MediaInstance',
10
+ 'IpAddresses' => 'IpAddress',
11
+ 'Feedback' => 'FeedbackInstance',
12
+ 'Addresses' => 'Address'
13
+ }
9
14
  @path, @client = path, client
10
15
  resource_name = self.class.name.split('::')[-1]
11
16
  instance_name = custom_names.fetch(resource_name, resource_name.chop)
@@ -13,7 +18,11 @@ module Twilio
13
18
  # The next line grabs the enclosing module. Necessary for resources
14
19
  # contained in their own submodule like /SMS/Messages
15
20
  parent_module = self.class.to_s.split('::')[-2]
16
- full_module_path = parent_module == "REST" ? (Twilio::REST) : (Twilio::REST.const_get parent_module)
21
+ full_module_path = if parent_module == "REST"
22
+ Twilio::REST
23
+ else
24
+ Twilio::REST.const_get parent_module
25
+ end
17
26
 
18
27
  @instance_class = full_module_path.const_get instance_name
19
28
  @list_key, @instance_id_key = detwilify(resource_name), 'sid'
@@ -42,11 +51,17 @@ module Twilio
42
51
  @instance_class.new "#{path}/#{resource[@instance_id_key]}", @client,
43
52
  resource
44
53
  end
45
- # set the +total+ and +next_page+ properties on the array
54
+ # set the +previous_page+ and +next_page+ properties on the array
46
55
  client, list_class = @client, self.class
47
56
  resource_list.instance_eval do
48
57
  eigenclass = class << self; self; end
49
- eigenclass.send :define_method, :total, &lambda {response['total']}
58
+ eigenclass.send :define_method, :previous_page, &lambda {
59
+ if response['previous_page_uri']
60
+ list_class.new(response['previous_page_uri'], client).list({}, true)
61
+ else
62
+ []
63
+ end
64
+ }
50
65
  eigenclass.send :define_method, :next_page, &lambda {
51
66
  if response['next_page_uri']
52
67
  list_class.new(response['next_page_uri'], client).list({}, true)
@@ -58,18 +73,6 @@ module Twilio
58
73
  resource_list
59
74
  end
60
75
 
61
- ##
62
- # Ask Twilio for the total number of items in the list.
63
- # Calling this method makes an HTTP GET request to <tt>@path</tt> with a
64
- # page size parameter of 1 to minimize data over the wire while still
65
- # obtaining the total. Don't use this if you are planning to
66
- # call #list anyway, since the array returned from #list will have a
67
- # +total+ attribute as well.
68
- def total
69
- raise "Can't get a resource total without a REST Client" unless @client
70
- @client.get(@path, :page_size => 1)['total']
71
- end
72
-
73
76
  ##
74
77
  # Return an empty instance resource object with the proper path. Note that
75
78
  # this will never raise a Twilio::REST::RequestError on 404 since no HTTP
@@ -92,19 +95,6 @@ module Twilio
92
95
  @instance_class.new "#{@path}/#{response[@instance_id_key]}", @client,
93
96
  response
94
97
  end
95
-
96
- def resource(*resources)
97
- custom_resource_names = {:sms => 'SMS', :sip => 'SIP'}
98
- resources.each do |r|
99
- resource = twilify r
100
- relative_path = custom_resource_names.fetch(r, resource)
101
- path = "#{@path}/#{relative_path}"
102
- enclosing_module = @submodule == nil ? (Twilio::REST) : (Twilio::REST.const_get(@submodule))
103
- resource_class = enclosing_module.const_get resource
104
- instance_variable_set("@#{r}", resource_class.new(path, @client))
105
- end
106
- self.class.instance_eval {attr_reader *resources}
107
- end
108
98
  end
109
99
  end
110
100
  end
@@ -0,0 +1,17 @@
1
+ module Twilio
2
+ module REST
3
+ module Lookups
4
+ class PhoneNumbers < Twilio::REST::NextGenListResource;
5
+ include Twilio::Util
6
+ include Twilio::REST::Utils
7
+
8
+ def get(number, query={})
9
+ full_path = "#{@path}/#{number}"
10
+ full_path << "?#{url_encode(twilify(query))}" if !query.empty?
11
+ @instance_class.new full_path, @client
12
+ end
13
+ end
14
+ class PhoneNumber < InstanceResource; end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,99 @@
1
+ require 'twilio-ruby/rest/base_client'
2
+ module Twilio
3
+ module REST
4
+ class LookupsClient < BaseClient
5
+ API_VERSION = 'v1'
6
+
7
+ attr_reader :phone_numbers
8
+
9
+ host 'lookups.twilio.com'
10
+
11
+ ##
12
+ # Instantiate a new HTTP Lookups client to talk to Twilio. The parameters
13
+ # +account_sid+, +auth_token+ and +workspace_sid are required, unless you
14
+ # have configured them already using the block configure syntax, and used
15
+ # to generate the HTTP basic auth header in each request. The +options+
16
+ # parameter is a hash of connection configuration options. the following
17
+ # keys are supported:
18
+ #
19
+ # === <tt>host: 'lookups.twilio.com'</tt>
20
+ #
21
+ # The domain to which you'd like the client to make HTTP requests. Useful
22
+ # for testing. Defaults to 'lookups.twilio.com'.
23
+ #
24
+ # === <tt>port: 443</tt>
25
+ #
26
+ # The port on which to connect to the above domain. Defaults to 443 and
27
+ # should be left that way except in testing environments.
28
+ #
29
+ # === <tt>use_ssl: true</tt>
30
+ #
31
+ # Declare whether ssl should be used for connections to the above domain.
32
+ # Defaults to true and should be left alone except when testing.
33
+ #
34
+ # === <tt>ssl_verify_peer: true</tt>
35
+ #
36
+ # Declare whether to verify the host's ssl cert when setting up the
37
+ # connection to the above domain. Defaults to true, but can be turned off
38
+ # to avoid ssl certificate verification failures in environments without
39
+ # the necessary ca certificates.
40
+ #
41
+ # === <tt>ssl_ca_file: '/path/to/ca/file'</tt>
42
+ #
43
+ # Specify the path to the certificate authority bundle you'd like to use
44
+ # to verify Twilio's SSL certificate on each request. If not specified, a
45
+ # certificate bundle extraced from Firefox is packaged with the gem and
46
+ # used by default.
47
+ #
48
+ # === <tt>timeout: 30</tt>
49
+ #
50
+ # Set the time in seconds to wait before timing out the HTTP request.
51
+ # Defaults to 30 seconds. If you aren't fetching giant pages of call or
52
+ # SMS logs you can safely decrease this to something like 3 seconds or
53
+ # lower. In paricular if you are sending SMS you can set this to 1 second
54
+ # or less and swallow the exception if you don't care about the response.
55
+ #
56
+ # === <tt>proxy_addr: 'proxy.host.domain'</tt>
57
+ #
58
+ # The domain of a proxy through which you'd like the client to make HTTP
59
+ # requests. Defaults to nil.
60
+ #
61
+ # === <tt>proxy_port: 3128</tt>
62
+ #
63
+ # The port on which to connect to the above proxy. Defaults to nil.
64
+ #
65
+ # === <tt>proxy_user: 'username'</tt>
66
+ #
67
+ # The user name to use for authentication with the proxy. Defaults to nil.
68
+ #
69
+ # === <tt>proxy_pass: 'password'</tt>
70
+ #
71
+ # The password to use for authentication with the proxy. Defaults to nil.
72
+ #
73
+ # === <tt>retry_limit: 1</tt>
74
+ #
75
+ # The number of times to retry a request that has failed before throwing
76
+ # an exception. Defaults to one.
77
+ def inspect # :nodoc:
78
+ "<Twilio::REST::LookupsClient @account_sid=#{@account_sid}>"
79
+ end
80
+
81
+ protected
82
+
83
+ ##
84
+ # Set up +phone_numbers+ attribute.
85
+ def set_up_subresources # :doc:
86
+ @phone_numbers = Twilio::REST::Lookups::PhoneNumbers.new "/#{API_VERSION}/PhoneNumbers", self
87
+ end
88
+
89
+ ##
90
+ # Builds up full request path
91
+ def build_full_path(path, params, method)
92
+ path = path.dup
93
+ path << "?#{url_encode(params)}" if method == :get && !params.empty?
94
+ path
95
+ end
96
+
97
+ end
98
+ end
99
+ end
@@ -12,6 +12,11 @@ module Twilio
12
12
  super
13
13
  resource :media
14
14
  end
15
+
16
+ def redact()
17
+ update({body: ''})
18
+ end
19
+
15
20
  end
16
21
  end
17
22
  end
@@ -0,0 +1,36 @@
1
+ module Twilio
2
+ module REST
3
+ class NextGenListResource < Twilio::REST::ListResource
4
+ def list(params={}, full_path=false)
5
+ raise "Can't get a resource list without a REST Client" unless @client
6
+ response = @client.get @path, params, full_path
7
+ list_key = response['meta']['key']
8
+ raise "Couldn't find a list key in response meta" unless list_key
9
+ resources = response[list_key]
10
+ resource_list = resources.map do |resource|
11
+ @instance_class.new "#{@path}/#{resource[@instance_id_key]}", @client,
12
+ resource
13
+ end
14
+ client, list_class = @client, self.class
15
+ resource_list.instance_eval do
16
+ eigenclass = class << self; self; end
17
+ eigenclass.send :define_method, :next_page, &lambda {
18
+ if response['meta']['next_page_url']
19
+ list_class.new(response['meta']['next_page_url'], client).list({})
20
+ else
21
+ []
22
+ end
23
+ }
24
+ eigenclass.send :define_method, :previous_page, &lambda {
25
+ if response['meta']['previous_page_url']
26
+ list_class.new(response['meta']['previous_page_url'], client).list({})
27
+ else
28
+ []
29
+ end
30
+ }
31
+ end
32
+ resource_list
33
+ end
34
+ end
35
+ end
36
+ end
@@ -2,7 +2,7 @@ module Twilio
2
2
  module REST
3
3
  class OutgoingCallerIds < ListResource
4
4
  def add(phone_number)
5
- create :phone_number => phone_number
5
+ create phone_number: phone_number
6
6
  end
7
7
  alias :verify :add
8
8
 
@@ -22,7 +22,7 @@ module Twilio
22
22
 
23
23
  class Member < InstanceResource
24
24
  def dequeue(url, method='POST')
25
- update :url => url, :method => method
25
+ update url: url, method: method
26
26
  end
27
27
  end
28
28
  end
@@ -3,9 +3,7 @@ module Twilio
3
3
  class Sip < InstanceResource
4
4
  def initialize(path, client, params={})
5
5
  super
6
- resource :domains,
7
- :ip_access_control_lists,
8
- :credential_lists
6
+ resource :domains, :ip_access_control_lists, :credential_lists
9
7
  end
10
8
  end
11
9
  end
@@ -1,7 +1,25 @@
1
1
  module Twilio
2
2
  module REST
3
3
  module SMS
4
+
5
+ module Deprecation
6
+ def deprecate(method_name)
7
+ old_method = "_deprecated_#{method_name}"
8
+ alias_method old_method, method_name
9
+ define_method method_name do |*args, &block|
10
+ warn "[DEPRECATED] SMS Resource is deprecated. Please use Messages (https://www.twilio.com/docs/api/rest/message)"
11
+ send old_method, *args, &block
12
+ end
13
+ end
14
+ end
15
+
4
16
  class Messages < ListResource
17
+ extend Deprecation
18
+
19
+ deprecate :list
20
+ deprecate :get
21
+ deprecate :create
22
+
5
23
  def initialize(path, client)
6
24
  super
7
25
  @list_key = 'sms_messages'
@@ -9,6 +27,11 @@ module Twilio
9
27
  end
10
28
 
11
29
  class Message < InstanceResource
30
+ extend Deprecation
31
+
32
+ deprecate :update
33
+ deprecate :refresh
34
+ deprecate :delete
12
35
  end
13
36
  end
14
37
  end
@@ -0,0 +1,8 @@
1
+ module Twilio
2
+ module REST
3
+ module TaskRouter
4
+ class Activities < Twilio::REST::NextGenListResource; end
5
+ class Activity < InstanceResource; end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Twilio
2
+ module REST
3
+ module TaskRouter
4
+ class Events < ListResource; end
5
+ class Event < InstanceResource; end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Twilio
2
+ module REST
3
+ module TaskRouter
4
+ class Reservations < Twilio::REST::NextGenListResource; end
5
+ class Reservation < InstanceResource; end
6
+ end
7
+ end
8
+ end