twilio-ruby 3.1.0 → 3.1.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.
data/README.md CHANGED
@@ -1,19 +1,19 @@
1
- ## Get Started
2
-
3
- To install:
1
+ ## Install
4
2
 
5
3
  Via rubygems.org:
6
4
 
7
5
  ```
8
- $ sudo gem install twilio-ruby
6
+ $ gem install twilio-ruby
9
7
  ```
10
8
 
11
- To build and install yourself from the latest source:
9
+ To build and install the development branch yourself from the latest source:
12
10
 
13
11
  ```
14
- $ git clone git@github.com:andrewmbenton/twilio-ruby.git
15
- $ cd twilio-ruby; rake gem
16
- $ sudo gem install pkg/twilio-ruby-{version}
12
+ $ git clone git@github.com:twilio/twilio-ruby.git
13
+ $ cd twilio-ruby
14
+ $ git checkout develop
15
+ $ rake gem
16
+ $ gem install pkg/twilio-ruby-{version}
17
17
  ```
18
18
 
19
19
  ## Some Code To Get You Started
@@ -21,7 +21,7 @@ $ sudo gem install pkg/twilio-ruby-{version}
21
21
  ### Setup Work
22
22
 
23
23
  ``` ruby
24
- require 'rubygems'
24
+ require 'rubygems' # not necessary with ruby 1.9.2 but included for completeness
25
25
  require 'twilio-ruby'
26
26
 
27
27
  # put your own credentials here
@@ -5,11 +5,17 @@ module Twilio
5
5
  include Twilio::Util
6
6
  include Twilio::REST::Utils
7
7
 
8
+ HTTP_HEADERS = {
9
+ 'Accept' => 'application/json',
10
+ 'User-Agent' => 'twilio-ruby/3.1.1',
11
+ }
12
+
8
13
  attr_reader :account_sid, :account, :accounts
9
14
 
10
15
  def initialize(account_sid, auth_token, domain = 'api.twilio.com',
11
16
  proxy_host = nil, proxy_port = nil)
12
- @account_sid, @auth_token = account_sid, auth_token
17
+ @account_sid = account_sid
18
+ @auth_token = auth_token
13
19
  set_up_connection_to domain, proxy_host, proxy_port
14
20
  set_up_subresources
15
21
  end
@@ -18,24 +24,13 @@ module Twilio
18
24
  [:get, :put, :post, :delete].each do |method|
19
25
  method_class = Net::HTTP.const_get method.to_s.capitalize
20
26
  define_method method do |uri, *args|
21
- uri += '.json'
22
- params = twilify(args[0]); params = {} if params.empty?
23
- uri += "?#{url_encode(params)}" if !params.empty? && method == :get
24
- headers = {
25
- 'Accept' => 'application/json',
26
- 'User-Agent' => 'twilio-ruby/3.1.0'
27
- }
28
- request = method_class.new uri, headers
27
+ params = twilify args[0]; params = {} if params.empty?
28
+ uri += '.json' # create a local copy of the uri to manipulate
29
+ uri << "?#{url_encode(params)}" if method == :get && !params.empty?
30
+ request = method_class.new uri, HTTP_HEADERS
29
31
  request.basic_auth @account_sid, @auth_token
30
32
  request.form_data = params if [:post, :put].include? method
31
- http_response = @connection.request request
32
- object = JSON.parse http_response.body if http_response.body
33
- if http_response.kind_of? Net::HTTPClientError
34
- raise Twilio::REST::RequestError, object['message']
35
- elsif http_response.kind_of? Net::HTTPServerError
36
- raise Twilio::REST::ServerError, object['message']
37
- end
38
- object
33
+ connect_and_send request
39
34
  end
40
35
  end
41
36
 
@@ -47,7 +42,7 @@ module Twilio
47
42
 
48
43
  case method
49
44
  when 'GET'
50
- uri += "?#{url_encode(params)}" if params
45
+ uri << "?#{url_encode(params)}" if params
51
46
  req = Net::HTTP::Get.new uri
52
47
  when 'DELETE'
53
48
  req = Net::HTTP::Delete.new uri
@@ -86,6 +81,17 @@ module Twilio
86
81
  @accounts = Twilio::REST::Accounts.new accounts_uri, self
87
82
  end
88
83
 
84
+ def connect_and_send(request)
85
+ response = @connection.request request
86
+ object = JSON.parse response.body if response.body
87
+ if response.kind_of? Net::HTTPClientError
88
+ raise Twilio::REST::RequestError, object['message']
89
+ elsif response.kind_of? Net::HTTPServerError
90
+ raise Twilio::REST::ServerError, object['message']
91
+ end
92
+ object
93
+ end
94
+
89
95
  end
90
96
  end
91
97
  end
@@ -15,6 +15,13 @@ module Twilio
15
15
  self
16
16
  end
17
17
 
18
+ def refresh
19
+ raise "Can't refresh a resource without a REST Client" unless @client
20
+ @updated = false
21
+ response = @client.get @uri
22
+ set_up_properties_from response
23
+ end
24
+
18
25
  def delete
19
26
  raise "Can't delete a resource without a REST Client" unless @client
20
27
  @client.delete @uri
data/twilio-ruby.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "twilio-ruby"
3
- s.version = "3.1.0"
3
+ s.version = "3.1.1"
4
4
  s.author = "Andrew Benton"
5
5
  s.email = "andrew@twilio.com"
6
6
  s.description = "A simple library for communicating with the Twilio REST API"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twilio-ruby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 1
9
- - 0
10
- version: 3.1.0
9
+ - 1
10
+ version: 3.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Benton
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-17 00:00:00 -07:00
18
+ date: 2011-07-22 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency