twilio-ruby 4.0.0 → 4.0.1

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTVlYzExOGM0MDgwMzg3NmE4MTM0M2M1MjAyNTY1MmU5Yjk3NjY1Mw==
4
+ NzJmYWRjOTQwZDI1MDliYmNhNjYyOWZkMGQyZGMxN2FhNWZkZDE1Yg==
5
5
  data.tar.gz: !binary |-
6
- MTBlYzkxM2NjYjViMzY2OGU5NzUyMjBhMjNjOGQ5ZWVmN2I5YTdjYw==
6
+ MTVhNzZiNWRiZTdjYTY5MTFkZDRlN2QxOWYzMzFiYjQyMzQ4ZjAzYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Mjk0ZDNjYjIwYTc2NjZiYjAzNmM4NGQ4NWQ4NWJlNGM0NzA2NTI5NmI1OTI4
10
- Y2E5ZDEzYzQ0MjNiNTEzM2Y0MWQ5MzBiMTFiM2MwNThmODNjMjY4NmE2MTdi
11
- MDM4NWY3OWU0ZGY1NWI4YjU2MTM4NzRiZTRjNmQ4MzNjZDEyOWU=
9
+ YjVlYjExNGFiNDg3YzVlMDE3MWE4YTkxYzNkNzRlZGFiYTdlY2QyZDFiYjcx
10
+ MGIwYzQ2ZDgxYWVhN2FjZDMzYzgxMjIxZjRjNjdlZjFkMzgzMGNhYThkMjEz
11
+ N2ExYzBmNzBlNGEwNDcxYWY3NTAwNWRmMDhlNjBlNDFkNmQ2YjY=
12
12
  data.tar.gz: !binary |-
13
- ODBhZjRmYWQ4ZTU3MTA3ZjE5MjEyNjYyODI2ZDk0Njk3Mjg3YjRjYTgyYTA4
14
- NGEyMjExNzUzYjhjMGE3ZWM1YmI2MzM4YThmOGEwNGRkZTZmNzc5ZmMwMjli
15
- OTNkMmE3YjY2NmIxZjRkZGRmMTc3OWE3NmM2ZjE5MGJmOTViN2E=
13
+ MDJkNzJmZWIzNWIyZDcyMjRhOGEwYjIzMjJiZDAwNTU4MTEyMmE0NmRlMTgx
14
+ OGI3M2NlYWUzM2EyMjBjNzBlOTYxNmZkYWJmMjY2NDMyNmI2NTg2Y2JjNzMx
15
+ ODMxODUyMWE3ZjVlNTNmZjE5M2U5YTI4NjNhMjM1ZDE3OWUzYzY=
data/CHANGES.md CHANGED
@@ -1,6 +1,13 @@
1
1
  twilio-ruby changelog
2
2
  =====================
3
3
 
4
+ Version 4.0.1
5
+ -------------
6
+
7
+ Released May 6, 2015
8
+
9
+ - Add support for the new Pricing API
10
+
4
11
  Version 4.0.0
5
12
  -------------
6
13
 
data/README.md CHANGED
@@ -11,7 +11,7 @@ A module for using the Twilio REST API and generating valid [TwiML](http://www.t
11
11
  To install using [Bundler][bundler] grab the latest stable version:
12
12
 
13
13
  ```ruby
14
- gem 'twilio-ruby', '~> 4.0.0'
14
+ gem 'twilio-ruby', '~> 4.0.1'
15
15
  ```
16
16
 
17
17
  To manually install `twilio-ruby` via [Rubygems][rubygems] simply gem install:
@@ -192,6 +192,12 @@ implementations:
192
192
  - [JRuby][jruby]
193
193
  - [Rubinius][rubinius]
194
194
 
195
+ ## Getting help
196
+
197
+ If you need help installing or using the library, please contact Twilio Support at help@twilio.com first. Twilio's Support staff are well-versed in all of the Twilio Helper Libraries, and usually reply within 24 hours.
198
+
199
+ If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!
200
+
195
201
  ## More Information
196
202
 
197
203
  There are more detailed examples in the included [examples][examples]
data/docs/index.rst CHANGED
@@ -54,6 +54,7 @@ Query the Twilio REST API to create phone calls, send SMS/MMS messages and more!
54
54
  usage/caller-ids
55
55
  usage/queues
56
56
  usage/sip
57
+ usage/pricing
57
58
 
58
59
 
59
60
  TaskRouter
@@ -0,0 +1,169 @@
1
+ .. module:: twilio.rest.pricing
2
+
3
+ ======================================
4
+ Accessing Twilio Pricing API Resources
5
+ ======================================
6
+
7
+ To access Twilio Pricing resources, you'll first need to instantiate a
8
+ :class:`Twilio::REST::PricingClient`.
9
+
10
+
11
+ Authentication
12
+ --------------
13
+
14
+ The :class:`Twilio::REST::PricingClient` needs your Twilio credentials. To get
15
+ your credentials, visit `your Twilio account portal
16
+ <https://www.twilio.com/user/account>`_. If you don't have a Twilio account
17
+ yet, go `here <https://www.twilio.com/try-twilio>`_ to get started.
18
+
19
+ Once you have your credentials, you can create create a new :class:`PricingClient` and get started.
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::PricingClient.new account_sid, auth_token
30
+
31
+ You can also configure the client using the top level configure method, like so:
32
+
33
+ .. code-block:: ruby
34
+
35
+ require 'twilio-ruby'
36
+
37
+ Twilio.configure do |config|
38
+ config.account_sid = "ACXXXXXXXXXXXXXXXXX"
39
+ config.auth_token = "YYYYYYYYYYYYYYYYYY"
40
+ end
41
+
42
+ @client = Twilio::REST::PricingClient.new
43
+
44
+
45
+ =============
46
+ Voice Pricing
47
+ =============
48
+
49
+ Twilio Voice pricing information is available by country and by phone number.
50
+
51
+ Voice calls are priced per minute and reflect the current Twilio list price
52
+ and any discounts available to the requesting account at the time of the
53
+ request.
54
+
55
+ Voice Countries
56
+ ---------------
57
+
58
+ To retrieve a list of countries where Twilio Voice services are available:
59
+
60
+ .. code-block:: ruby
61
+
62
+ require 'twilio-ruby'
63
+
64
+ # To find these visit https://www.twilio.com/user/account
65
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
66
+ auth_token = "YYYYYYYYYYYYYYYYYY"
67
+
68
+ @client = Twilio::REST::PricingClient.new account_sid, auth_token
69
+ @countries = @client.voice.countries.list
70
+ @countries.each do |c|
71
+ puts c.country
72
+ end
73
+
74
+ Note that the country objects in the returned list will not have pricing
75
+ information populated; you will need to retrieve the specific information
76
+ for each country you are interested in individually:
77
+
78
+ .. code-block:: ruby
79
+
80
+ require 'twilio-ruby'
81
+
82
+ # To find these visit https://www.twilio.com/user/account
83
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
84
+ auth_token = "YYYYYYYYYYYYYYYYYY"
85
+
86
+ @client = Twilio::REST::PricingClient.new account_sid, auth_token
87
+ @country = @client.voice.countries.get('US')
88
+ puts @country.iso_country
89
+ puts @country.price_unit
90
+
91
+ # A list of price rates for inbound calls to each type of Twilio Number
92
+ # available in this country
93
+ @country.inbound_call_prices.each do |p|
94
+ puts p.number_type
95
+ puts p.base_price # List price per minute
96
+ puts p.current_price # Discounted price per minute
97
+ end
98
+
99
+ # A list of price rates for outbound calls to number, organized
100
+ # by prefix.
101
+ @country.outbound_prefix_prices.each do |p|
102
+ puts p.prefixes # List of one or more prefixes this price applies to
103
+ puts p.base_price # Base price per minute
104
+ puts p.current_price # Discounted price per minute
105
+
106
+ Voice Numbers
107
+ -------------
108
+
109
+ To retrieve pricing information for Twilio Voice calls to and from a specific
110
+ number:
111
+
112
+ .. code-block:: ruby
113
+
114
+ require 'twilio-ruby'
115
+
116
+ # To find these visit https://www.twilio.com/user/account
117
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
118
+ auth_token = "YYYYYYYYYYYYYYYYYY"
119
+
120
+ @client = Twilio::REST::PricingClient.new account_sid, auth_token
121
+ @number = @client.voice.phone_numbers.get('+15105551234')
122
+ puts @number.iso_country
123
+ puts @number.price_unit
124
+ puts @number.outbound_call_price.base_price
125
+ puts @number.inbound_call_price.number_type # inbound_call_price will be nil if the number is not Twilio-hosted
126
+
127
+
128
+ Phone Number Pricing
129
+ ====================
130
+
131
+ To retrieve a list of countries where Twilio phone numbers are available:
132
+
133
+ .. code-block:: ruby
134
+
135
+ require 'twilio-ruby'
136
+
137
+ # To find these visit https://www.twilio.com/user/account
138
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
139
+ auth_token = "YYYYYYYYYYYYYYYYYY"
140
+
141
+ @client = Twilio::REST::PricingClient.new account_sid, auth_token
142
+ @countries = @client.phone_numbers.countries.list
143
+ @countries.each do |c|
144
+ puts c.country
145
+ end
146
+
147
+
148
+ Note that the country objects in the returned list will not have pricing
149
+ information populated; you will need to retrieve the specific information for
150
+ each country you are interested in individually:
151
+
152
+ .. code-block:: ruby
153
+
154
+ require 'twilio-ruby'
155
+
156
+ # To find these visit https://www.twilio.com/user/account
157
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
158
+ auth_token = "YYYYYYYYYYYYYYYYYY"
159
+
160
+ @client = Twilio::REST::PricingClient.new account_sid, auth_token
161
+ @country = @client.phone_numbers.countries.get('US')
162
+ puts @country.iso_country
163
+ puts @country.price_unit
164
+
165
+ @country.phone_number_prices.each do |p|
166
+ puts p.number_type # 'local', 'mobile', 'national', or 'toll_free'
167
+ puts p.base_price # Price per month before any discounts have been applied
168
+ puts p.current_price # Price per month after any available discounts from the requesting account have applied
169
+
data/lib/twilio-ruby.rb CHANGED
@@ -83,6 +83,7 @@ require 'twilio-ruby/rest/addresses/dependent_phone_numbers'
83
83
  require 'twilio-ruby/rest/client'
84
84
  require 'twilio-ruby/rest/task_router_client'
85
85
  require 'twilio-ruby/rest/lookups_client'
86
+ require 'twilio-ruby/rest/pricing_client'
86
87
  require 'rack/twilio_webhook_authentication'
87
88
 
88
89
  module Twilio
@@ -110,13 +110,16 @@ module Twilio
110
110
  if response.kind_of? Net::HTTPServerError
111
111
  raise Twilio::REST::ServerError
112
112
  end
113
- rescue Exception
113
+ rescue
114
114
  raise if request.class == Net::HTTP::Post
115
115
  if retries_left > 0 then retries_left -= 1; retry else raise end
116
116
  end
117
117
  if response.body and !response.body.empty?
118
118
  object = MultiJson.load response.body
119
+ elsif response.kind_of? Net::HTTPBadRequest
120
+ object = { message: 'Bad request', code: 400 }
119
121
  end
122
+
120
123
  if response.kind_of? Net::HTTPClientError
121
124
  raise Twilio::REST::RequestError.new object['message'], object['code']
122
125
  end
@@ -1,4 +1,5 @@
1
1
  require 'twilio-ruby/rest/base_client'
2
+
2
3
  module Twilio
3
4
  module REST
4
5
  ##
@@ -50,7 +51,6 @@ module Twilio
50
51
  # ListResource#get to grab a particular account once you know its sid.
51
52
  class Client < BaseClient
52
53
  API_VERSION = '2010-04-01'
53
-
54
54
  attr_reader :account, :accounts
55
55
 
56
56
  host 'api.twilio.com'
@@ -6,10 +6,11 @@ module Twilio
6
6
  def initialize(path, client)
7
7
  custom_names = {
8
8
  'Activities' => 'Activity',
9
- 'Media' => 'MediaInstance',
10
- 'IpAddresses' => 'IpAddress',
9
+ 'Addresses' => 'Address',
10
+ 'Countries' => 'Country',
11
11
  'Feedback' => 'FeedbackInstance',
12
- 'Addresses' => 'Address'
12
+ 'IpAddresses' => 'IpAddress',
13
+ 'Media' => 'MediaInstance',
13
14
  }
14
15
  @path, @client = path, client
15
16
  resource_name = self.class.name.split('::')[-1]
@@ -0,0 +1,6 @@
1
+ module Twilio
2
+ module REST
3
+ module Pricing
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,21 @@
1
+ module Twilio
2
+ module REST
3
+ module Pricing
4
+ class Countries < NextGenListResource
5
+ def initialize(path, client)
6
+ super
7
+ @list_key = 'countries'
8
+ @instance_id_key = 'iso_country'
9
+ @submodule = :Pricing
10
+ end
11
+ end
12
+
13
+ class Country < InstanceResource
14
+ def initialize(path, client, params={})
15
+ super
16
+ @submodule = :Pricing
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ module Twilio
2
+ module REST
3
+ module Pricing
4
+ class PhoneNumbers < InstanceResource
5
+
6
+ def initialize(path, client, params={})
7
+ super
8
+ @submodule = :Pricing
9
+ resource :countries
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ require 'twilio-ruby/rest/pricing/countries'
2
+ require 'twilio-ruby/rest/pricing/voice/numbers'
3
+
4
+ module Twilio
5
+ module REST
6
+ module Pricing
7
+ class Voice < InstanceResource
8
+
9
+ def initialize(path, client, params={})
10
+ super
11
+ @submodule = :Pricing
12
+ resource :countries, :numbers
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ module Twilio
2
+ module REST
3
+ module Pricing
4
+ class Numbers < NextGenListResource
5
+ def initialize(path, client)
6
+ super
7
+ @submodule = :Pricing
8
+ end
9
+ end
10
+
11
+ class Number < InstanceResource
12
+ def initialize(path, client)
13
+ super
14
+ @submodule = :Pricing
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,110 @@
1
+ require 'twilio-ruby/rest/base_client'
2
+ require 'twilio-ruby/rest/pricing'
3
+ require 'twilio-ruby/rest/pricing/voice'
4
+ require 'twilio-ruby/rest/pricing/phone_numbers'
5
+
6
+ module Twilio
7
+ module REST
8
+ class PricingClient < BaseClient
9
+ include Twilio::Util
10
+ include Twilio::REST::Utils
11
+
12
+ API_VERSION = 'v1'
13
+
14
+ attr_reader :voice, :phone_numbers
15
+
16
+ host 'pricing.twilio.com'
17
+
18
+ ##
19
+ # Instantiate a new HTTP client to talk to Twilio's Pricing API. The
20
+ # parameters +account_sid+ and +auth_token+ are required, unless you have
21
+ # configured them already using the block configure syntax, and used to
22
+ # generate the HTTP basic auth header in each request. The +options+
23
+ # parameter is a hash of connection configuration options. the following
24
+ # keys are supported:
25
+ #
26
+ # === <tt>host: 'pricing.twilio.com'</tt>
27
+ #
28
+ # The domain to which you'd like the client to make HTTP requests. Useful
29
+ # for testing. Defaults to 'pricing.twilio.com'.
30
+ #
31
+ # === <tt>port: 443</tt>
32
+ #
33
+ # The port on which to connect to the above domain. Defaults to 443 and
34
+ # should be left that way except in testing environments.
35
+ #
36
+ # === <tt>use_ssl: true</tt>
37
+ #
38
+ # Declare whether ssl should be used for connections to the above domain.
39
+ # Defaults to true and should be left alone except when testing.
40
+ #
41
+ # === <tt>ssl_verify_peer: true</tt>
42
+ #
43
+ # Declare whether to verify the host's ssl cert when setting up the
44
+ # connection to the above domain. Defaults to true, but can be turned off
45
+ # to avoid ssl certificate verification failures in environments without
46
+ # the necessary ca certificates.
47
+ #
48
+ # === <tt>ssl_ca_file: '/path/to/ca/file'</tt>
49
+ #
50
+ # Specify the path to the certificate authority bundle you'd like to use
51
+ # to verify Twilio's SSL certificate on each request. If not specified, a
52
+ # certificate bundle extraced from Firefox is packaged with the gem and
53
+ # used by default.
54
+ #
55
+ # === <tt>timeout: 30</tt>
56
+ #
57
+ # Set the time in seconds to wait before timing out the HTTP request.
58
+ # Defaults to 30 seconds. If you aren't fetching giant pages of call or
59
+ # SMS logs you can safely decrease this to something like 3 seconds or
60
+ # lower. In paricular if you are sending SMS you can set this to 1 second
61
+ # or less and swallow the exception if you don't care about the response.
62
+ #
63
+ # === <tt>proxy_addr: 'proxy.host.domain'</tt>
64
+ #
65
+ # The domain of a proxy through which you'd like the client to make HTTP
66
+ # requests. Defaults to nil.
67
+ #
68
+ # === <tt>proxy_port: 3128</tt>
69
+ #
70
+ # The port on which to connect to the above proxy. Defaults to nil.
71
+ #
72
+ # === <tt>proxy_user: 'username'</tt>
73
+ #
74
+ # The user name to use for authentication with the proxy. Defaults to nil.
75
+ #
76
+ # === <tt>proxy_pass: 'password'</tt>
77
+ #
78
+ # The password to use for authentication with the proxy. Defaults to nil.
79
+ #
80
+ # === <tt>retry_limit: 1</tt>
81
+ #
82
+ # The number of times to retry a request that has failed before throwing
83
+ # an exception. Defaults to one.
84
+ def initialize(*args)
85
+ super(*args)
86
+ end
87
+
88
+ def inspect # :nodoc:
89
+ "<Twilio::REST::PricingClient @account_sid=#{@account_sid}>"
90
+ end
91
+
92
+ protected
93
+
94
+ ##
95
+ # Set up +voice+ and +phone_numbers+ attributes.
96
+ def set_up_subresources # :doc:
97
+ @voice = Twilio::REST::Pricing::Voice.new "/#{API_VERSION}/Voice", self
98
+ @phone_numbers = Twilio::REST::Pricing::PhoneNumbers.new "/#{API_VERSION}/PhoneNumbers", self
99
+ end
100
+
101
+ ##
102
+ # Builds up full request path
103
+ def build_full_path(path, params, method)
104
+ path = path.dup
105
+ path << "?#{url_encode(params)}" if method == :get && !params.empty?
106
+ path
107
+ end
108
+ end
109
+ end
110
+ end
@@ -1,3 +1,3 @@
1
1
  module Twilio
2
- VERSION = '4.0.0'
2
+ VERSION = '4.0.1'
3
3
  end
@@ -255,4 +255,23 @@ describe Twilio::REST::Client do
255
255
  expect(client.send(method)).to eq(client.workspace.send(method))
256
256
  end
257
257
  end
258
+
259
+ end
260
+
261
+ describe Twilio::REST::PricingClient do
262
+ it 'should have its host set to pricing.twilio.com' do
263
+ client = Twilio::REST::PricingClient.new('sid', 'token')
264
+ connection = client.instance_variable_get('@connection')
265
+ expect(connection.address).to eq('pricing.twilio.com')
266
+ end
267
+
268
+ it 'should set up a voice resource object' do
269
+ client = Twilio::REST::PricingClient.new('sid', 'token')
270
+ expect(client).to respond_to(:voice)
271
+ end
272
+
273
+ it 'should set up a phone numbers resource object' do
274
+ client = Twilio::REST::PricingClient.new('sid', 'token')
275
+ expect(client).to respond_to(:phone_numbers)
276
+ end
258
277
  end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Twilio::REST::PricingClient do
4
+ before do
5
+ @client = Twilio::REST::PricingClient.new('AC123', 'foobar')
6
+ end
7
+
8
+ it 'should set up a voice resources object' do
9
+ expect(@client).to respond_to(:voice)
10
+ expect(@client.voice.instance_variable_get('@path')).to eq(
11
+ '/v1/Voice'
12
+ )
13
+ end
14
+
15
+ it 'should set up the country list resource on voice' do
16
+ voice = @client.voice
17
+ expect(voice).to respond_to(:countries)
18
+ expect(voice.countries.instance_variable_get('@path')).to eq(
19
+ '/v1/Voice/Countries'
20
+ )
21
+ end
22
+
23
+ it 'should set up the numbers resource on voice' do
24
+ voice = @client.voice
25
+ expect(voice).to respond_to(:numbers)
26
+ expect(voice.numbers.instance_variable_get('@path')).to eq(
27
+ '/v1/Voice/Numbers'
28
+ )
29
+ end
30
+
31
+ it 'should set up a phone numbers resource object' do
32
+ expect(@client).to respond_to(:phone_numbers)
33
+ expect(@client.phone_numbers.instance_variable_get('@path')).to eq(
34
+ '/v1/PhoneNumbers'
35
+ )
36
+ end
37
+
38
+ it 'should set up a countries list on phone numbers' do
39
+ numbers = @client.phone_numbers
40
+ expect(numbers).to respond_to(:countries)
41
+ expect(numbers.countries.instance_variable_get('@path')).to eq(
42
+ '/v1/PhoneNumbers/Countries'
43
+ )
44
+ end
45
+ end
@@ -29,65 +29,85 @@ describe Twilio::Util::RequestValidator do
29
29
  end
30
30
  end
31
31
 
32
- it 'should properly validate a Twilio Voice request' do
33
- token = '2bd9e9638872de601313dc77410d3b23'
34
- validator = Twilio::Util::RequestValidator.new token
35
- url = 'http://twiliotests.heroku.com/validate/voice'
36
- params = {
37
- 'ToState' => 'California',
38
- 'CalledState' => 'California',
39
- 'Direction' => 'inbound',
40
- 'FromState' => 'CA',
41
- 'AccountSid' => 'ACba8bc05eacf94afdae398e642c9cc32d',
42
- 'Caller' => '+14153595711',
43
- 'CallerZip' => '94108',
44
- 'CallerCountry' => 'US',
45
- 'From' => '+14153595711',
46
- 'FromCity' => 'SAN FRANCISCO',
47
- 'CallerCity' => 'SAN FRANCISCO',
48
- 'To' => '+14157669926',
49
- 'FromZip' => '94108',
50
- 'FromCountry' => 'US',
51
- 'ToCity' => '',
52
- 'CallStatus' => 'ringing',
53
- 'CalledCity' => '',
54
- 'CallerState' => 'CA',
55
- 'CalledZip' => '',
56
- 'ToZip' => '',
57
- 'ToCountry' => 'US',
58
- 'CallSid' => 'CA136d09cd59a3c0ec8dbff44da5c03f31',
59
- 'CalledCountry' => 'US',
60
- 'Called' => '+14157669926',
61
- 'ApiVersion' => '2010-04-01',
62
- 'ApplicationSid' => 'AP44efecad51364e80b133bb7c07eb8204'
63
- }
64
- signature = 'oVb2kXoVy8GEfwBDjR8bk/ZZ6eA='
65
- expect(validator.validate(url, params, signature)).to eq(true)
66
- end
32
+ describe 'validations' do
33
+ let(:token) { '2bd9e9638872de601313dc77410d3b23' }
34
+
35
+ let(:validator) { Twilio::Util::RequestValidator.new token }
36
+
37
+ let(:voice_url) { 'http://twiliotests.heroku.com/validate/voice' }
38
+
39
+ let(:sms_url) { 'http://twiliotests.heroku.com/validate/sms' }
40
+
41
+ let(:voice_params) do
42
+ {
43
+ 'ToState' => 'California',
44
+ 'CalledState' => 'California',
45
+ 'Direction' => 'inbound',
46
+ 'FromState' => 'CA',
47
+ 'AccountSid' => 'ACba8bc05eacf94afdae398e642c9cc32d',
48
+ 'Caller' => '+14153595711',
49
+ 'CallerZip' => '94108',
50
+ 'CallerCountry' => 'US',
51
+ 'From' => '+14153595711',
52
+ 'FromCity' => 'SAN FRANCISCO',
53
+ 'CallerCity' => 'SAN FRANCISCO',
54
+ 'To' => '+14157669926',
55
+ 'FromZip' => '94108',
56
+ 'FromCountry' => 'US',
57
+ 'ToCity' => '',
58
+ 'CallStatus' => 'ringing',
59
+ 'CalledCity' => '',
60
+ 'CallerState' => 'CA',
61
+ 'CalledZip' => '',
62
+ 'ToZip' => '',
63
+ 'ToCountry' => 'US',
64
+ 'CallSid' => 'CA136d09cd59a3c0ec8dbff44da5c03f31',
65
+ 'CalledCountry' => 'US',
66
+ 'Called' => '+14157669926',
67
+ 'ApiVersion' => '2010-04-01',
68
+ 'ApplicationSid' => 'AP44efecad51364e80b133bb7c07eb8204'
69
+ }
70
+ end
71
+
72
+ let(:sms_params) do
73
+ {
74
+ 'ToState' => 'CA',
75
+ 'FromState' => 'CA',
76
+ 'AccountSid' => 'ACba8bc05eacf94afdae398e642c9cc32d',
77
+ 'SmsMessageSid' => 'SM2003cbd5e6a3701999aa3e5f20ff2787',
78
+ 'Body' => 'Orly',
79
+ 'From' => '+14159354345',
80
+ 'FromCity' => 'SAN FRANCISCO',
81
+ 'SmsStatus' => 'received',
82
+ 'FromZip' => '94107',
83
+ 'FromCountry' => 'US',
84
+ 'To' => '+14158141819',
85
+ 'ToCity' => 'SAN FRANCISCO',
86
+ 'ToZip' => '94105',
87
+ 'ToCountry' => 'US',
88
+ 'ApiVersion' => '2010-04-01',
89
+ 'SmsSid' => 'SM2003cbd5e6a3701999aa3e5f20ff2787'
90
+ }
91
+ end
67
92
 
68
- it 'should properly validate a Twilio SMS request' do
69
- token = '2bd9e9638872de601313dc77410d3b23'
70
- validator = Twilio::Util::RequestValidator.new token
71
- url = 'http://twiliotests.heroku.com/validate/sms'
72
- params = {
73
- 'ToState' => 'CA',
74
- 'FromState' => 'CA',
75
- 'AccountSid' => 'ACba8bc05eacf94afdae398e642c9cc32d',
76
- 'SmsMessageSid' => 'SM2003cbd5e6a3701999aa3e5f20ff2787',
77
- 'Body' => 'Orly',
78
- 'From' => '+14159354345',
79
- 'FromCity' => 'SAN FRANCISCO',
80
- 'SmsStatus' => 'received',
81
- 'FromZip' => '94107',
82
- 'FromCountry' => 'US',
83
- 'To' => '+14158141819',
84
- 'ToCity' => 'SAN FRANCISCO',
85
- 'ToZip' => '94105',
86
- 'ToCountry' => 'US',
87
- 'ApiVersion' => '2010-04-01',
88
- 'SmsSid' => 'SM2003cbd5e6a3701999aa3e5f20ff2787'
89
- }
90
- signature = 'mxeiv65lEe0b8L6LdVw2jgJi8yw='
91
- expect(validator.validate(url, params, signature)).to eq(true)
93
+ it 'should validate an authentic Twilio Voice request' do
94
+ signature = 'oVb2kXoVy8GEfwBDjR8bk/ZZ6eA='
95
+ expect(validator.validate(voice_url, voice_params, signature)).to eq(true)
96
+ end
97
+
98
+ it 'should validate an authentic Twilio SMS request' do
99
+ signature = 'mxeiv65lEe0b8L6LdVw2jgJi8yw='
100
+ expect(validator.validate(sms_url, sms_params, signature)).to eq(true)
101
+ end
102
+
103
+ it 'should not validate a Twilio Voice request with wrong signature' do
104
+ signature = 'foo'
105
+ expect(validator.validate(voice_url, voice_params, signature)).to eq(false)
106
+ end
107
+
108
+ it 'should not validate a Twilio SMS request with wrong signature' do
109
+ signature = 'bar'
110
+ expect(validator.validate(sms_url, sms_params, signature)).to eq(false)
111
+ end
92
112
  end
93
113
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twilio-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Benton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-16 00:00:00.000000000 Z
11
+ date: 2015-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -116,6 +116,7 @@ files:
116
116
  - docs/usage/notifications.rst
117
117
  - docs/usage/phone-calls.rst
118
118
  - docs/usage/phone-numbers.rst
119
+ - docs/usage/pricing.rst
119
120
  - docs/usage/queues.rst
120
121
  - docs/usage/recordings.rst
121
122
  - docs/usage/sip.rst
@@ -161,6 +162,12 @@ files:
161
162
  - lib/twilio-ruby/rest/next_gen_list_resource.rb
162
163
  - lib/twilio-ruby/rest/notifications.rb
163
164
  - lib/twilio-ruby/rest/outgoing_caller_ids.rb
165
+ - lib/twilio-ruby/rest/pricing.rb
166
+ - lib/twilio-ruby/rest/pricing/countries.rb
167
+ - lib/twilio-ruby/rest/pricing/phone_numbers.rb
168
+ - lib/twilio-ruby/rest/pricing/voice.rb
169
+ - lib/twilio-ruby/rest/pricing/voice/numbers.rb
170
+ - lib/twilio-ruby/rest/pricing_client.rb
164
171
  - lib/twilio-ruby/rest/queues.rb
165
172
  - lib/twilio-ruby/rest/queues/members.rb
166
173
  - lib/twilio-ruby/rest/recordings.rb
@@ -217,6 +224,7 @@ files:
217
224
  - spec/rest/lookups/phone_number_spec.rb
218
225
  - spec/rest/message_spec.rb
219
226
  - spec/rest/numbers_spec.rb
227
+ - spec/rest/pricing_client_spec.rb
220
228
  - spec/rest/queue_spec.rb
221
229
  - spec/rest/recording_spec.rb
222
230
  - spec/rest/sms/message_spec.rb
@@ -279,6 +287,7 @@ test_files:
279
287
  - spec/rest/lookups/phone_number_spec.rb
280
288
  - spec/rest/message_spec.rb
281
289
  - spec/rest/numbers_spec.rb
290
+ - spec/rest/pricing_client_spec.rb
282
291
  - spec/rest/queue_spec.rb
283
292
  - spec/rest/recording_spec.rb
284
293
  - spec/rest/sms/message_spec.rb