twilio_resource 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,7 +8,7 @@ as if they're local ActiveRecord models:
8
8
  phone = TwilioResource::LocalIncomingPhoneNumber.new(:url => 'http://www.example.com',
9
9
  :area_code => '206',
10
10
  :method => 'GET',
11
- :friendly_name =g> "My First Phone Number",
11
+ :friendly_name => "My First Phone Number",
12
12
  :account_id => Twilio::Base.user)
13
13
  phone.save
14
14
 
@@ -17,6 +17,7 @@ The wrapper doesn't support the entire Twilio API, but it should be
17
17
  simple enough to add new functionality as needed by following the
18
18
  models that are already built.
19
19
 
20
+
20
21
  Supported Functionality
21
22
  =======================
22
23
  - Requesting, listing, and deleting new local and toll-free numbers
@@ -75,4 +76,4 @@ Placing a call:
75
76
  :account_id => Twilio::Base.user,
76
77
  :caller => '2065551111',
77
78
  :called => '2065551212',
78
- :url => 'http://example.com/call.xml'})
79
+ :url => 'http://example.com/call.xml'})
@@ -10,12 +10,9 @@ class TwilioResource::Exception < StandardError
10
10
  # exception if it is mapped, or the xml response otherwise.
11
11
  def self.find_exception(e)
12
12
  new_exception = if e.respond_to?(:response)
13
- exception_data = Hash.from_xml(e.response.body)
13
+ exception_data = ActiveResource::Formats::TwilioFormat.decode(e.response.body)
14
14
 
15
-
16
- code = exception_data['twilio_response'] &&
17
- exception_data['twilio_response']['rest_exception'] &&
18
- exception_data['twilio_response']['rest_exception']['code']
15
+ code = exception_data['code']
19
16
  exception_klass = twilio_exceptions[code.to_i] if code
20
17
  exception_klass.nil? ? e : exception_klass.new
21
18
  else
@@ -31,6 +31,12 @@ module ActiveResource
31
31
  # Manipulate from_xml Hash, because twilio doesn't format their
32
32
  # xml in the way active_resource expects it.
33
33
  def from_xml_data(data)
34
+
35
+ # HACK to underscore hash keys like Rails did in 2.3.2 (e.g. "CallSegmentSid" => "call_segment_sid")
36
+ # Hash#from_xml stopped doing this in Rails 2.3.4, and it's unclear if it should or not.
37
+ # See: https://rails.lighthouseapp.com/projects/8994/tickets/3377-hashfrom_xml-converted-camelcase-to-underscore-in-232-doesnt-in-234
38
+ data = deep_underscore_hash_keys(data)
39
+
34
40
  if data.is_a?(Hash) && data['twilio_response']
35
41
  from_xml_data(data['twilio_response'])
36
42
  else
@@ -40,7 +46,7 @@ module ActiveResource
40
46
  # it's the empty set, initialize it to an array so
41
47
  # active_resource doesn't throw a fit.
42
48
  if v["page"]
43
- array_data = v[k.singularize]
49
+ array_data = v[k.singularize]
44
50
  data[k] = [array_data].flatten.compact
45
51
  elsif v.blank?
46
52
  data[k] = []
@@ -51,6 +57,24 @@ module ActiveResource
51
57
  data.values.first
52
58
  end
53
59
  end
60
+
61
+
62
+ def deep_underscore_hash_keys(hash)
63
+ hash.keys.each do |key|
64
+ hash[key.underscore] = hash.delete(key)
65
+ end
66
+
67
+ hash.values.each do |value|
68
+ if value.is_a?(Hash)
69
+ deep_underscore_hash_keys(value)
70
+ elsif value.is_a?(Array)
71
+ value.each {|v| deep_underscore_hash_keys(v)}
72
+ end
73
+ end
74
+
75
+ hash
76
+ end
77
+
54
78
  end
55
79
  end
56
80
  end
data/test/call_test.rb CHANGED
@@ -11,6 +11,12 @@ class TwilioResource::CallTest < Test::Unit::TestCase
11
11
  def test_find_all
12
12
  calls = TwilioResource::Call.find(:all, :params => {:account_id => 1})
13
13
  assert_equal 2, calls.length
14
+
15
+ # check attributes were assigned correctly
16
+ call = calls.first
17
+ assert_equal('4159633717', call.called)
18
+ assert_equal('4156767925', call.caller)
19
+ assert(call.call_segment_sid.blank?)
14
20
  end
15
21
 
16
22
  # what the hell, twilio? who uses capitalization to distinguish
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twilio_resource
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 25
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 1
8
- - 0
9
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Justin Weiss
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-06-16 00:00:00 -07:00
18
+ date: 2010-10-07 00:00:00 -07:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: activeresource
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 7
27
30
  segments:
28
31
  - 2
29
32
  - 3
@@ -67,23 +70,27 @@ rdoc_options: []
67
70
  require_paths:
68
71
  - lib
69
72
  required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
70
74
  requirements:
71
75
  - - ">="
72
76
  - !ruby/object:Gem::Version
77
+ hash: 3
73
78
  segments:
74
79
  - 0
75
80
  version: "0"
76
81
  required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
77
83
  requirements:
78
84
  - - ">="
79
85
  - !ruby/object:Gem::Version
86
+ hash: 3
80
87
  segments:
81
88
  - 0
82
89
  version: "0"
83
90
  requirements: []
84
91
 
85
92
  rubyforge_project:
86
- rubygems_version: 1.3.6
93
+ rubygems_version: 1.3.7
87
94
  signing_key:
88
95
  specification_version: 3
89
96
  summary: An ActiveResource API wrapper for Twilio