twilio_resource 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,17 @@
1
1
  require 'logger'
2
- require 'activeresource'
2
+ require 'reactive_resource'
3
3
 
4
4
  require 'twilio_resource/twilio_format'
5
5
  require 'twilio_resource/exceptions'
6
6
 
7
7
  module TwilioResource
8
+
9
+ autoload :Base, 'twilio_resource/base'
10
+ autoload :Account, 'twilio_resource/account'
11
+ autoload :Call, 'twilio_resource/call'
12
+ autoload :IncomingPhoneNumber, 'twilio_resource/incoming_phone_number'
13
+ autoload :LocalIncomingPhoneNumber, 'twilio_resource/local_incoming_phone_number'
14
+ autoload :TollFreeIncomingPhoneNumber, 'twilio_resource/toll_free_incoming_phone_number'
8
15
 
9
16
  class << self
10
17
  attr_accessor :logger
@@ -18,10 +25,3 @@ module TwilioResource
18
25
  TwilioResource::Base.token = token
19
26
  end
20
27
  end
21
-
22
- require 'twilio_resource/base'
23
- require 'twilio_resource/account'
24
- require 'twilio_resource/call'
25
- require 'twilio_resource/incoming_phone_number'
26
- require 'twilio_resource/local_incoming_phone_number'
27
- require 'twilio_resource/toll_free_incoming_phone_number'
@@ -1,3 +1,5 @@
1
+ require 'reactive_resource'
2
+
1
3
  # Encapsulates the changes that need to be made to active_resource's
2
4
  # defaults in order to communicate with Twilio. There are a few main
3
5
  # issues with ActiveResource's defaults:
@@ -15,7 +17,7 @@
15
17
  # ActiveResource::Formats::TwilioFormat.
16
18
  #
17
19
  # All of the Twilio ActiveResource classes inherit from this class.
18
- class TwilioResource::Base < ActiveResource::Base
20
+ class TwilioResource::Base < ReactiveResource::Base
19
21
 
20
22
  class << self
21
23
  attr_accessor :sid
@@ -27,29 +29,23 @@ class TwilioResource::Base < ActiveResource::Base
27
29
  alias_method :password=, :token=
28
30
  end
29
31
 
30
- # Have to override this to make empty extensions work (without the dot)
32
+ # Add logging to these requests
31
33
  def self.element_path(id, prefix_options = {}, query_options = nil)
32
- prefix_options, query_options = split_options(prefix_options) if query_options.nil?
33
- extension = format.extension.blank? ? "" : ".#{format.extension}"
34
- path = "#{prefix(prefix_options)}#{collection_name}/#{id}#{extension}#{query_string(query_options)}"
34
+ path = super(id, prefix_options, query_options)
35
35
  TwilioResource.logger.info("Request: #{path}")
36
36
  path
37
37
  end
38
38
 
39
- # Have to override this to make empty extensions work (without the dot)
39
+ # Add logging to these requests
40
40
  def self.collection_path(prefix_options = {}, query_options = nil)
41
- prefix_options, query_options = split_options(prefix_options) if query_options.nil?
42
- extension = format.extension.blank? ? "" : ".#{format.extension}"
43
- path = "#{prefix(prefix_options)}#{collection_name}#{extension}#{query_string(query_options)}"
41
+ path = super(prefix_options, query_options)
44
42
  TwilioResource.logger.info("Request: #{path}")
45
43
  path
46
44
  end
47
45
 
48
- # Have to override this to make empty extensions work (without the dot)
46
+ # Add logging to these requests
49
47
  def self.custom_method_collection_url(method_name, options = {})
50
- prefix_options, query_options = split_options(options)
51
- extension = format.extension.blank? ? "" : ".#{format.extension}"
52
- path = "#{prefix(prefix_options)}#{collection_name}/#{method_name}#{extension}#{query_string(query_options)}"
48
+ path = super(method_name, options)
53
49
  TwilioResource.logger.info("Request: #{path}")
54
50
  path
55
51
  end
@@ -73,7 +69,6 @@ class TwilioResource::Base < ActiveResource::Base
73
69
  rescue => e
74
70
  raise TwilioResource::Exception.find_exception(e)
75
71
  end
76
-
77
72
  end
78
73
 
79
74
 
@@ -3,7 +3,7 @@
3
3
  # - http://www.twilio.com/docs/api/2008-08-01/rest/call
4
4
  # - http://www.twilio.com/docs/api/2008-08-01/rest/making_calls
5
5
  class TwilioResource::Call < TwilioResource::Base
6
- self.prefix = superclass.prefix_source + 'Accounts/:account_id/'
6
+ belongs_to :account
7
7
 
8
8
  NOT_DIALED = 0
9
9
  IN_PROGRESS = 1
@@ -2,5 +2,5 @@
2
2
  # incoming phone calls. Documentation is at
3
3
  # http://www.twilio.com/docs/api/2008-08-01/rest/incoming-phone-numbers
4
4
  class TwilioResource::IncomingPhoneNumber < TwilioResource::Base
5
- self.prefix = superclass.prefix_source + 'Accounts/:account_id/'
5
+ belongs_to :account
6
6
  end
@@ -5,10 +5,12 @@
5
5
  # http://www.twilio.com/docs/api/2008-08-01/rest/incoming-phone-numbers
6
6
  class TwilioResource::LocalIncomingPhoneNumber < TwilioResource::IncomingPhoneNumber
7
7
 
8
- self.prefix = superclass.prefix_source + 'IncomingPhoneNumbers/'
9
-
10
8
  def self.collection_name
11
9
  'Local'
12
10
  end
13
11
 
12
+ def self.association_prefix(options)
13
+ super(options) + superclass.collection_name + "/"
14
+ end
15
+
14
16
  end
@@ -5,10 +5,12 @@
5
5
  # http://www.twilio.com/docs/api/2008-08-01/rest/incoming-phone-numbers
6
6
  class TwilioResource::TollFreeIncomingPhoneNumber < TwilioResource::IncomingPhoneNumber
7
7
 
8
- self.prefix = superclass.prefix_source + 'IncomingPhoneNumbers/'
9
-
10
8
  def self.collection_name
11
9
  'TollFree'
12
10
  end
13
11
 
12
+ def self.association_prefix(options)
13
+ super(options) + superclass.collection_name + "/"
14
+ end
15
+
14
16
  end
data/test/test_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'test/unit'
2
2
  require 'rubygems'
3
- require 'activeresource'
3
+ require 'reactive_resource'
4
4
  require 'twilio_resource'
5
5
 
6
6
  TwilioResource.setup('1', '1')
data/test/twilio_mock.rb CHANGED
@@ -22,10 +22,18 @@ class TwilioMock
22
22
 
23
23
  end
24
24
 
25
+ def self.build_header(method)
26
+ if ActiveResource::VERSION::MAJOR == 3
27
+ TwilioResource::Account.connection.send(:build_request_headers, {}, method, '')
28
+ else
29
+ TwilioResource::Account.connection.send(:build_request_headers, {})
30
+ end
31
+ end
32
+
25
33
  def self.auth_delete(account_id)
26
34
  old_account_id = TwilioResource::Base.user
27
35
  TwilioResource::Base.user = account_id
28
- auth = TwilioResource::Account.connection.send(:build_request_headers, {}, :delete)
36
+ auth = build_header(:delete)
29
37
  TwilioResource::Base.user = old_account_id
30
38
  auth
31
39
  end
@@ -33,7 +41,7 @@ class TwilioMock
33
41
  def self.auth_post(account_id)
34
42
  old_account_id = TwilioResource::Base.user
35
43
  TwilioResource::Base.user = account_id
36
- auth = TwilioResource::Account.connection.send(:build_request_headers, {}, :post)
44
+ auth = build_header(:post)
37
45
  TwilioResource::Base.user = old_account_id
38
46
  auth
39
47
  end
@@ -41,7 +49,7 @@ class TwilioMock
41
49
  def self.auth_get(account_id)
42
50
  old_account_id = TwilioResource::Base.user
43
51
  TwilioResource::Base.user = account_id
44
- auth = TwilioResource::Account.connection.send(:build_request_headers, {}, :get)
52
+ auth = build_header(:get)
45
53
  TwilioResource::Base.user = old_account_id
46
54
  auth
47
55
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twilio_resource
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Justin Weiss
@@ -15,23 +14,22 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-10-07 00:00:00 -07:00
17
+ date: 2011-02-16 00:00:00 -08:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
- name: activeresource
21
+ name: reactive_resource
23
22
  prerelease: false
24
23
  requirement: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
25
  requirements:
27
- - - ">="
26
+ - - ~>
28
27
  - !ruby/object:Gem::Version
29
- hash: 7
30
28
  segments:
31
- - 2
32
- - 3
33
- - 2
34
- version: 2.3.2
29
+ - 0
30
+ - 5
31
+ - 1
32
+ version: 0.5.1
35
33
  type: :runtime
36
34
  version_requirements: *id001
37
35
  description:
@@ -74,7 +72,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
72
  requirements:
75
73
  - - ">="
76
74
  - !ruby/object:Gem::Version
77
- hash: 3
78
75
  segments:
79
76
  - 0
80
77
  version: "0"
@@ -83,7 +80,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
80
  requirements:
84
81
  - - ">="
85
82
  - !ruby/object:Gem::Version
86
- hash: 3
87
83
  segments:
88
84
  - 0
89
85
  version: "0"