bandwidth 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -1
- data/Gemfile.lock +4 -9
- data/README.md +5 -0
- data/VERSION +1 -1
- data/bandwidth.gemspec +11 -4
- data/lib/bandwidth.rb +1 -1
- data/lib/bandwidth/bandwidth.rb +36 -9
- data/lib/bandwidth/string_patch.rb +9 -0
- data/spec/bandwidth_spec.rb +66 -2
- data/spec/spec_helper.rb +1 -0
- metadata +44 -15
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
builder (3.0.0)
|
5
4
|
crack (0.1.8)
|
6
5
|
diff-lcs (1.1.2)
|
7
6
|
git (1.2.5)
|
8
|
-
gyoku (0.3.1)
|
9
|
-
builder (>= 2.1.2)
|
10
7
|
hashie (1.0.0)
|
11
8
|
httpi (0.9.0)
|
12
9
|
ntlm-http (>= 0.1.1)
|
@@ -15,6 +12,7 @@ GEM
|
|
15
12
|
bundler (~> 1.0.0)
|
16
13
|
git (>= 1.2.5)
|
17
14
|
rake
|
15
|
+
nokogiri (1.4.4)
|
18
16
|
ntlm-http (0.1.1)
|
19
17
|
rack (1.2.1)
|
20
18
|
rake (0.8.7)
|
@@ -27,11 +25,6 @@ GEM
|
|
27
25
|
rspec-expectations (2.3.0)
|
28
26
|
diff-lcs (~> 1.1.2)
|
29
27
|
rspec-mocks (2.3.0)
|
30
|
-
savon (0.8.6)
|
31
|
-
builder (>= 2.1.2)
|
32
|
-
crack (~> 0.1.8)
|
33
|
-
gyoku (>= 0.3.0)
|
34
|
-
httpi (>= 0.7.8)
|
35
28
|
yard (0.6.4)
|
36
29
|
|
37
30
|
PLATFORMS
|
@@ -39,9 +32,11 @@ PLATFORMS
|
|
39
32
|
|
40
33
|
DEPENDENCIES
|
41
34
|
bundler (~> 1.0.0)
|
35
|
+
crack
|
42
36
|
hashie
|
37
|
+
httpi
|
43
38
|
jeweler (~> 1.5.2)
|
39
|
+
nokogiri
|
44
40
|
rcov
|
45
41
|
rspec (~> 2.3.0)
|
46
|
-
savon
|
47
42
|
yard (~> 0.6.0)
|
data/README.md
CHANGED
@@ -89,6 +89,11 @@ Full details of available methods [here](https://my.bandwidth.com/portal/apidoc/
|
|
89
89
|
[2.x] Restricted Operations, Numbers - getRateCenterBlockOrder
|
90
90
|
[2.x] Restricted Operations, Numbers - getRateCenterBlockOrders
|
91
91
|
|
92
|
+
Notes
|
93
|
+
-----
|
94
|
+
|
95
|
+
When calling the 'basic_number_order' method, be sure to use ':number_IDs' & ':ext_ref_ID' as the correct options, given that the Bandwidth API is not following camelCase standards in this case.
|
96
|
+
|
92
97
|
Copyright
|
93
98
|
---------
|
94
99
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/bandwidth.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bandwidth}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jason Goecke"]
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"examples/example.rb",
|
30
30
|
"lib/bandwidth.rb",
|
31
31
|
"lib/bandwidth/bandwidth.rb",
|
32
|
+
"lib/bandwidth/string_patch.rb",
|
32
33
|
"spec/bandwidth_spec.rb",
|
33
34
|
"spec/spec_helper.rb"
|
34
35
|
]
|
@@ -47,16 +48,20 @@ Gem::Specification.new do |s|
|
|
47
48
|
s.specification_version = 3
|
48
49
|
|
49
50
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
-
s.add_runtime_dependency(%q<
|
51
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
52
|
+
s.add_runtime_dependency(%q<crack>, [">= 0"])
|
51
53
|
s.add_runtime_dependency(%q<hashie>, [">= 0"])
|
54
|
+
s.add_runtime_dependency(%q<httpi>, [">= 0"])
|
52
55
|
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
53
56
|
s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
|
54
57
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
55
58
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
56
59
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
57
60
|
else
|
58
|
-
s.add_dependency(%q<
|
61
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
62
|
+
s.add_dependency(%q<crack>, [">= 0"])
|
59
63
|
s.add_dependency(%q<hashie>, [">= 0"])
|
64
|
+
s.add_dependency(%q<httpi>, [">= 0"])
|
60
65
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
61
66
|
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
62
67
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
@@ -64,8 +69,10 @@ Gem::Specification.new do |s|
|
|
64
69
|
s.add_dependency(%q<rcov>, [">= 0"])
|
65
70
|
end
|
66
71
|
else
|
67
|
-
s.add_dependency(%q<
|
72
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
73
|
+
s.add_dependency(%q<crack>, [">= 0"])
|
68
74
|
s.add_dependency(%q<hashie>, [">= 0"])
|
75
|
+
s.add_dependency(%q<httpi>, [">= 0"])
|
69
76
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
70
77
|
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
71
78
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
data/lib/bandwidth.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
$: << File.expand_path(File.dirname(__FILE__))
|
2
|
-
%w(
|
2
|
+
%w(nokogiri crack httpi hashie bandwidth/bandwidth bandwidth/string_patch).each { |lib| require lib }
|
data/lib/bandwidth/bandwidth.rb
CHANGED
@@ -61,17 +61,14 @@ class Bandwidth
|
|
61
61
|
raise NoMethodError, "The method #{method_name.to_s} does not exist." if API_METHODS.include?(method_name) == false
|
62
62
|
|
63
63
|
if method_name == :get_cdr_archive
|
64
|
-
@cdrs_request.body =
|
65
|
-
:attributes! => xml_namespaces(method_name) })
|
64
|
+
@cdrs_request.body = build_xml(method_name, params)
|
66
65
|
|
67
66
|
response = HTTPI.post @cdrs_request
|
68
67
|
Hashie::Mash.new({ :code => response.code,
|
69
68
|
:body => response.raw_body,
|
70
69
|
:headers => response.headers })
|
71
70
|
else
|
72
|
-
@numbers_request.body =
|
73
|
-
:attributes! => xml_namespaces(method_name) })
|
74
|
-
|
71
|
+
@numbers_request.body = build_xml(method_name, params)
|
75
72
|
response = HTTPI.post @numbers_request
|
76
73
|
Hashie::Mash.new({ :code => response.code,
|
77
74
|
:body => Crack::XML.parse(response.raw_body),
|
@@ -79,6 +76,36 @@ class Bandwidth
|
|
79
76
|
end
|
80
77
|
end
|
81
78
|
|
79
|
+
##
|
80
|
+
# Builds the XML document for the method call
|
81
|
+
#
|
82
|
+
# @param [required, Symbol] the method name to invoke on the REST API
|
83
|
+
# @param [optional, Hash] the parameters to pass to the method, should be symbols and may be all lowercase with underscores or camelCase
|
84
|
+
# @return [String] the resulting XML document
|
85
|
+
def build_xml(method_name, params)
|
86
|
+
builder_params = params.merge({ :developer_key => @developer_key })
|
87
|
+
|
88
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
89
|
+
xml.send(method_name.to_s.camelize.uncapitalize.to_sym, xml_namespaces) do
|
90
|
+
builder_params.each do |parent_k, parent_v|
|
91
|
+
if parent_v.instance_of?(Array)
|
92
|
+
xml.send(parent_k.to_s.camelize.uncapitalize.to_sym) do
|
93
|
+
parent_v.each do |item|
|
94
|
+
item.each do |item_k, item_v|
|
95
|
+
symbol = (item_k.to_s + '_').to_sym
|
96
|
+
xml.send(symbol, item_v)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
else
|
101
|
+
xml.send(parent_k.to_s.camelize.uncapitalize.to_sym, parent_v)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
builder.to_xml
|
107
|
+
end
|
108
|
+
|
82
109
|
private
|
83
110
|
|
84
111
|
##
|
@@ -121,9 +148,9 @@ class Bandwidth
|
|
121
148
|
#
|
122
149
|
# @param [required, Symbol] method_name to add the XML namespace details to
|
123
150
|
# @return [Hash] the resulting XML namespace attributes
|
124
|
-
def xml_namespaces
|
125
|
-
{
|
126
|
-
|
127
|
-
|
151
|
+
def xml_namespaces
|
152
|
+
{ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
|
153
|
+
'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
|
154
|
+
'xmlns' => 'http://www.bandwidth.com/api/' }
|
128
155
|
end
|
129
156
|
end
|
data/spec/bandwidth_spec.rb
CHANGED
@@ -8,6 +8,24 @@ describe "Bandwidth" do
|
|
8
8
|
:log_level => :debug })
|
9
9
|
end
|
10
10
|
|
11
|
+
describe "string patch" do
|
12
|
+
it 'should camelize a string' do
|
13
|
+
"foo_bar".camelize.should == 'FooBar'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should uncapitalize a string' do
|
17
|
+
"FooBar".uncapitalize.should == 'fooBar'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should camelize and uncapitlize a string' do
|
21
|
+
"foo_bar".camelize.uncapitalize.should == 'fooBar'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should leave the ID alone' do
|
25
|
+
"foobar_IDs".camelize.uncapitalize.should == 'foobarIDs'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
11
29
|
describe "numbers" do
|
12
30
|
it "should instantiate a Bandwidth::Numbers class" do
|
13
31
|
@bandwidth.instance_of?(Bandwidth).should == true
|
@@ -55,9 +73,55 @@ describe "Bandwidth" do
|
|
55
73
|
|
56
74
|
describe "cdrs" do
|
57
75
|
it "should get a resopnse when retrieving cdrs" do
|
58
|
-
#pending('It appears Bandwidth has not provided access to this just yet.')
|
59
76
|
result = @bandwidth.get_cdr_archive(:get_type => 'Daily', :get_value => '20110221')
|
60
|
-
result['Content-Type'].should ==
|
77
|
+
result['headers']['Content-Type'].should == 'application/zip'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "xml builder" do
|
82
|
+
it "should build a valid area code search XML document" do
|
83
|
+
params = { :npa_nxx => '303', :max_quantity => '3' }
|
84
|
+
result = @bandwidth.build_xml(:area_code_number_search, params)
|
85
|
+
Crack::XML.parse(result).should == {
|
86
|
+
"areaCodeNumberSearch" => {
|
87
|
+
"developerKey" => ENV['BANDWIDTH_DEVELOPER_KEY'],
|
88
|
+
"xmlns:xsd" => "http://www.w3.org/2001/XMLSchema",
|
89
|
+
"maxQuantity" => "3",
|
90
|
+
"npaNxx" => "303",
|
91
|
+
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
|
92
|
+
"xmlns" => "http://www.bandwidth.com/api/"
|
93
|
+
}
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should build a valid basic number order document" do
|
98
|
+
params = { :order_name => 'Foobar 0',
|
99
|
+
:ext_ref_ID => 'Foobar 1',
|
100
|
+
:number_IDs => [ { :id => '1' }, { :id => '2' }],
|
101
|
+
:subscriber => 'Tropo',
|
102
|
+
:end_points => { :host => 'sip.tropo.com' } }
|
103
|
+
result = @bandwidth.build_xml(:basic_number_order, params)
|
104
|
+
|
105
|
+
Crack::XML.parse(result).should == {
|
106
|
+
"basicNumberOrder" => {
|
107
|
+
"developerKey" => ENV['BANDWIDTH_DEVELOPER_KEY'],
|
108
|
+
"subscriber" => "Tropo",
|
109
|
+
"xmlns:xsd" => "http://www.w3.org/2001/XMLSchema",
|
110
|
+
"extRefID" => "Foobar 1",
|
111
|
+
"orderName" => "Foobar 0",
|
112
|
+
"numberIDs" => {
|
113
|
+
"id" => [
|
114
|
+
"1",
|
115
|
+
"2"
|
116
|
+
]
|
117
|
+
},
|
118
|
+
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
|
119
|
+
"xmlns" => "http://www.bandwidth.com/api/",
|
120
|
+
"endPoints" => {
|
121
|
+
"host" => "sip.tropo.com"
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
61
125
|
end
|
62
126
|
end
|
63
127
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
3
|
require 'rspec'
|
4
4
|
require 'bandwidth'
|
5
|
+
require 'awesome_print'
|
5
6
|
|
6
7
|
# Requires supporting files with custom matchers and macros, etc,
|
7
8
|
# in ./support/ and its subdirectories.
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bandwidth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jason Goecke
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
segments:
|
30
30
|
- 0
|
31
31
|
version: "0"
|
32
|
-
name:
|
32
|
+
name: nokogiri
|
33
33
|
version_requirements: *id001
|
34
34
|
prerelease: false
|
35
35
|
- !ruby/object:Gem::Dependency
|
@@ -43,12 +43,40 @@ dependencies:
|
|
43
43
|
segments:
|
44
44
|
- 0
|
45
45
|
version: "0"
|
46
|
-
name:
|
46
|
+
name: crack
|
47
47
|
version_requirements: *id002
|
48
48
|
prerelease: false
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
|
-
type: :
|
50
|
+
type: :runtime
|
51
51
|
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
name: hashie
|
61
|
+
version_requirements: *id003
|
62
|
+
prerelease: false
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
type: :runtime
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
name: httpi
|
75
|
+
version_requirements: *id004
|
76
|
+
prerelease: false
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
type: :development
|
79
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
52
80
|
none: false
|
53
81
|
requirements:
|
54
82
|
- - ~>
|
@@ -60,11 +88,11 @@ dependencies:
|
|
60
88
|
- 0
|
61
89
|
version: 2.3.0
|
62
90
|
name: rspec
|
63
|
-
version_requirements: *
|
91
|
+
version_requirements: *id005
|
64
92
|
prerelease: false
|
65
93
|
- !ruby/object:Gem::Dependency
|
66
94
|
type: :development
|
67
|
-
requirement: &
|
95
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
68
96
|
none: false
|
69
97
|
requirements:
|
70
98
|
- - ~>
|
@@ -76,11 +104,11 @@ dependencies:
|
|
76
104
|
- 0
|
77
105
|
version: 0.6.0
|
78
106
|
name: yard
|
79
|
-
version_requirements: *
|
107
|
+
version_requirements: *id006
|
80
108
|
prerelease: false
|
81
109
|
- !ruby/object:Gem::Dependency
|
82
110
|
type: :development
|
83
|
-
requirement: &
|
111
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
84
112
|
none: false
|
85
113
|
requirements:
|
86
114
|
- - ~>
|
@@ -92,11 +120,11 @@ dependencies:
|
|
92
120
|
- 0
|
93
121
|
version: 1.0.0
|
94
122
|
name: bundler
|
95
|
-
version_requirements: *
|
123
|
+
version_requirements: *id007
|
96
124
|
prerelease: false
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
126
|
type: :development
|
99
|
-
requirement: &
|
127
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
100
128
|
none: false
|
101
129
|
requirements:
|
102
130
|
- - ~>
|
@@ -108,11 +136,11 @@ dependencies:
|
|
108
136
|
- 2
|
109
137
|
version: 1.5.2
|
110
138
|
name: jeweler
|
111
|
-
version_requirements: *
|
139
|
+
version_requirements: *id008
|
112
140
|
prerelease: false
|
113
141
|
- !ruby/object:Gem::Dependency
|
114
142
|
type: :development
|
115
|
-
requirement: &
|
143
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
116
144
|
none: false
|
117
145
|
requirements:
|
118
146
|
- - ">="
|
@@ -122,7 +150,7 @@ dependencies:
|
|
122
150
|
- 0
|
123
151
|
version: "0"
|
124
152
|
name: rcov
|
125
|
-
version_requirements: *
|
153
|
+
version_requirements: *id009
|
126
154
|
prerelease: false
|
127
155
|
description: "More detail here: https://my.bandwidth.com/portal/apidoc/welcome.htm"
|
128
156
|
email: jason@goecke.net
|
@@ -146,6 +174,7 @@ files:
|
|
146
174
|
- examples/example.rb
|
147
175
|
- lib/bandwidth.rb
|
148
176
|
- lib/bandwidth/bandwidth.rb
|
177
|
+
- lib/bandwidth/string_patch.rb
|
149
178
|
- spec/bandwidth_spec.rb
|
150
179
|
- spec/spec_helper.rb
|
151
180
|
has_rdoc: true
|