routengn-client 0.1.4

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.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +34 -0
  7. data/Rakefile +1 -0
  8. data/lib/routengn_client/connection.rb +77 -0
  9. data/lib/routengn_client/exceptions.rb +8 -0
  10. data/lib/routengn_client/logging.rb +23 -0
  11. data/lib/routengn_client/middleware/routengn_response_middleware.rb +23 -0
  12. data/lib/routengn_client/model.rb +177 -0
  13. data/lib/routengn_client/models/account.rb +23 -0
  14. data/lib/routengn_client/models/allow_list.rb +38 -0
  15. data/lib/routengn_client/models/carrier.rb +14 -0
  16. data/lib/routengn_client/models/code.rb +32 -0
  17. data/lib/routengn_client/models/code_sheet.rb +11 -0
  18. data/lib/routengn_client/models/contact.rb +124 -0
  19. data/lib/routengn_client/models/end_point.rb +18 -0
  20. data/lib/routengn_client/models/inbound_end_point_group.rb +70 -0
  21. data/lib/routengn_client/models/inbound_rate.rb +13 -0
  22. data/lib/routengn_client/models/outbound_end_point_group.rb +51 -0
  23. data/lib/routengn_client/models/outbound_rate.rb +13 -0
  24. data/lib/routengn_client/models/rate_sheet.rb +13 -0
  25. data/lib/routengn_client/models/record.rb +231 -0
  26. data/lib/routengn_client/models/route.rb +42 -0
  27. data/lib/routengn_client/models/route_block.rb +7 -0
  28. data/lib/routengn_client/models/route_container.rb +18 -0
  29. data/lib/routengn_client/models/route_ordering_override.rb +7 -0
  30. data/lib/routengn_client/models/route_table.rb +30 -0
  31. data/lib/routengn_client/models/system_admin_account.rb +5 -0
  32. data/lib/routengn_client/models/uri_matcher.rb +72 -0
  33. data/lib/routengn_client/models/user.rb +20 -0
  34. data/lib/routengn_client/remote_model.rb +69 -0
  35. data/lib/routengn_client/request.rb +34 -0
  36. data/lib/routengn_client/response.rb +108 -0
  37. data/lib/routengn_client/utils.rb +20 -0
  38. data/lib/routengn_client/version.rb +3 -0
  39. data/lib/routengn_client.rb +72 -0
  40. data/routengn-client.gemspec +37 -0
  41. data/spec/lib/routengn_client/connection_spec.rb +44 -0
  42. data/spec/lib/routengn_client/logging_spec.rb +9 -0
  43. data/spec/lib/routengn_client/model_spec.rb +82 -0
  44. data/spec/lib/routengn_client/models/account_spec.rb +28 -0
  45. data/spec/lib/routengn_client/models/carrier_spec.rb +20 -0
  46. data/spec/lib/routengn_client/models/code_spec.rb +32 -0
  47. data/spec/lib/routengn_client/models/contact_spec.rb +57 -0
  48. data/spec/lib/routengn_client/models/inbound_end_point_group_spec.rb +33 -0
  49. data/spec/lib/routengn_client/models/inbound_rate_spec.rb +10 -0
  50. data/spec/lib/routengn_client/models/outbound_end_point_group_spec.rb +52 -0
  51. data/spec/lib/routengn_client/models/outbound_rate_spec.rb +10 -0
  52. data/spec/lib/routengn_client/models/rate_sheet_spec.rb +0 -0
  53. data/spec/lib/routengn_client/models/record_spec.rb +59 -0
  54. data/spec/lib/routengn_client/models/route_container_spec.rb +10 -0
  55. data/spec/lib/routengn_client/models/route_spec.rb +228 -0
  56. data/spec/lib/routengn_client/models/route_table_spec.rb +87 -0
  57. data/spec/lib/routengn_client/remote_model_spec.rb +60 -0
  58. data/spec/lib/routengn_client/request_spec.rb +14 -0
  59. data/spec/lib/routengn_client/response_spec.rb +29 -0
  60. data/spec/lib/routengn_client_spec.rb +5 -0
  61. data/spec/spec_helper.rb +34 -0
  62. data/spec/support/blueprints.rb +157 -0
  63. metadata +351 -0
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe RouteNGNClient::OutboundRate do
4
+
5
+ it "can be instanstiated" do
6
+ r = OutboundRate.new
7
+ r.should be_an_instance_of(OutboundRate)
8
+ end
9
+
10
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe RouteNGNClient::Record do
4
+
5
+ let(:iepg1) {
6
+ InboundEndPointGroup.new({ "name"=>"IEPG 1",
7
+ "contact_template"=>"<sip:${ruri.dialcode}${ruri.user_params}${oepg.uri_user_params}@${oep.host}${oep.port}${ruri.params}${oepg.uri_params}>",
8
+ "multi_line_contacts"=>true,
9
+ "color_code"=>"#a4f379",
10
+ "route_on_type"=>"DN",
11
+ "min_percent_price_margin"=>nil,
12
+ "min_absolute_price_margin"=>nil,
13
+ "min_route_weight"=>nil,
14
+ "dialcode_expression"=>"([0-9]*)$",
15
+ "dialcode_prefix_expression"=>"^(.*D+)",
16
+ "ani_expression"=>"([0-9]*)$",
17
+ "ani_prefix_expression"=>"^(.*D+)",
18
+ "destination_billing_type"=>"DN",
19
+ "external_lrn_lookup_enabled"=>false,
20
+ "created_at"=>"2013-03-05T00:11:29Z",
21
+ "updated_at"=>"2013-03-05T00:35:24Z",
22
+ "id"=>"513538316f1cc9a140000010",
23
+ "carrier_id"=>"513538316f1cc9a140000011",
24
+ "primary_route_table_id"=>"513538666f1cc9a14000001b",
25
+ "secondary_route_table_id"=>"",
26
+ "allow_list" => {"id"=>"513538316f1cc9a14000000e",
27
+ "uri_matchers" => [{"header"=>"request",
28
+ "prefix"=>"",
29
+ "user_params"=>"tgrp=foo",
30
+ "uri_params"=>"",
31
+ "created_at"=>"2013-03-05T00:11:29Z",
32
+ "updated_at"=>"2013-03-05T00:11:29Z",
33
+ "id"=>"513538316f1cc9a14000000f"}]},
34
+ "end_points"=> [{"end_point"=> {"host"=>"127.0.0.1",
35
+ "port"=>5060,
36
+ "priority"=>nil,
37
+ "created_at"=>nil,
38
+ "updated_at"=>nil,
39
+ "id"=>"51353dcc6f1cc9f910000006"}}]
40
+ })
41
+ }
42
+
43
+ it "can be instanstiated" do
44
+ r = Record.new
45
+ r.should be_an_instance_of(Record)
46
+ end
47
+
48
+ it "can be json serialized" do
49
+ r = Record.new
50
+ r.set_inbound_end_point_group iepg1
51
+ r.inbound_end_point_group.should be_an_instance_of(InboundEndPointGroup)
52
+ j = r.to_json
53
+ j.should be_an_instance_of(String)
54
+ r2 = Record.from_json j
55
+ r2.should be_an_instance_of(Record)
56
+ r2.inbound_end_point_group.should be_an_instance_of(InboundEndPointGroup)
57
+ end
58
+
59
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe RouteNGNClient::RouteContainer do
4
+
5
+ it "can be instanstiated" do
6
+ rc = RouteContainer.new
7
+ rc.should be_an_instance_of(RouteContainer)
8
+ end
9
+
10
+ end
@@ -0,0 +1,228 @@
1
+ require 'spec_helper'
2
+
3
+ describe RouteNGNClient::Route do
4
+
5
+ before do
6
+ RouteNGNClient.connect(:uri => 'http://127.0.0.1')
7
+ end
8
+
9
+ let(:iepg1) {
10
+ InboundEndPointGroup.new({ "name"=>"IEPG 1",
11
+ "contact_template"=>"<sip:${ruri.dialcode}${ruri.user_params}${oepg.uri_user_params}@${oep.host}${oep.port}${ruri.params}${oepg.uri_params}>",
12
+ "multi_line_contacts"=>true,
13
+ "color_code"=>"#a4f379",
14
+ "route_on_type"=>"DN",
15
+ "min_percent_price_margin"=>nil,
16
+ "min_absolute_price_margin"=>nil,
17
+ "min_route_weight"=>nil,
18
+ "dialcode_expression"=>"([0-9]*)$",
19
+ "dialcode_prefix_expression"=>"^(.*D+)",
20
+ "ani_expression"=>"([0-9]*)$",
21
+ "ani_prefix_expression"=>"^(.*D+)",
22
+ "destination_billing_type"=>"DN",
23
+ "external_lrn_lookup_enabled"=>false,
24
+ "created_at"=>"2013-03-05T00:11:29Z",
25
+ "updated_at"=>"2013-03-05T00:35:24Z",
26
+ "id"=>"513538316f1cc9a140000010",
27
+ "carrier_id"=>"513538316f1cc9a140000011",
28
+ "primary_route_table_id"=>"513538666f1cc9a14000001b",
29
+ "secondary_route_table_id"=>"",
30
+ "allow_list" => {"id"=>"513538316f1cc9a14000000e",
31
+ "uri_matchers" => [{"header"=>"request",
32
+ "prefix"=>"",
33
+ "user_params"=>"tgrp=foo",
34
+ "uri_params"=>"",
35
+ "created_at"=>"2013-03-05T00:11:29Z",
36
+ "updated_at"=>"2013-03-05T00:11:29Z",
37
+ "id"=>"513538316f1cc9a14000000f"}]},
38
+ "end_points"=> [{"end_point"=> {"host"=>"127.0.0.1",
39
+ "port"=>5060,
40
+ "priority"=>nil,
41
+ "created_at"=>nil,
42
+ "updated_at"=>nil,
43
+ "id"=>"51353dcc6f1cc9f910000006"}}]
44
+ })
45
+ }
46
+
47
+ let(:oepg1) {
48
+ OutboundEndPointGroup.new({
49
+ "id"=>"513538546f1cc9a140000016",
50
+ "carrier_id"=>"513538546f1cc9a140000017",
51
+ "color_code"=>"#f379de",
52
+ "created_at"=>"2013-03-05 00:12:04 UTC",
53
+ "default_route_weight"=>nil,
54
+ "destination_billing_type"=>"DN",
55
+ "dialcode_expression"=>"([0-9]*)$",
56
+ "dialcode_template"=>"${dialcode_match}",
57
+ "end_points"=>
58
+ [{"_id"=>"513538546f1cc9a140000018",
59
+ "port"=>5060,
60
+ "host"=>"1.1.1.1",
61
+ "priority"=>nil}],
62
+ "max_contact_end_points"=>nil,
63
+ "name"=>"OEPG 1",
64
+ "rate_link_types"=>["dialcode"],
65
+ "route_table_ids"=>["513538666f1cc9a14000001b"],
66
+ "updated_at"=>"2013-03-05 00:12:04 UTC",
67
+ "uri_params"=>"",
68
+ "uri_params_blacklist"=>[],
69
+ "uri_user_params"=>"abc=123",
70
+ "uri_user_params_blacklist"=>[]
71
+ })
72
+ }
73
+
74
+ let(:outbound_rate1) {
75
+ OutboundRate.new({
76
+ "id"=>"51353a256f1cc98978000007",
77
+ "price"=>0.572,
78
+ "type"=>"inter",
79
+ "effective_at"=>"2013-03-05 00:12:37 UTC",
80
+ "created_at"=>"2013-03-05 00:19:49 UTC",
81
+ "updated_at"=>"2013-03-05 00:19:49 UTC",
82
+ "line_number"=>1,
83
+ "dialcode"=>"3217689",
84
+ "account_id"=>"5135354e6f1cc9a140000004",
85
+ "rate_sheet_id"=>"5135388c6f1cc9a14000001f",
86
+ "outbound_end_point_group_id"=>"513538546f1cc9a140000016"
87
+ })
88
+ }
89
+
90
+ let(:oepg2) {
91
+ OutboundEndPointGroup.new({
92
+ "id"=>"513538546f1cc9a140000028",
93
+ "carrier_id"=>"513538546f1cc9a140000017",
94
+ "color_code"=>"#f379de",
95
+ "created_at"=>"2013-03-05 00:12:04 UTC",
96
+ "default_route_weight"=>nil,
97
+ "destination_billing_type"=>"DN",
98
+ "dialcode_expression"=>"([0-9]*)$",
99
+ "dialcode_template"=>"${dialcode_match}",
100
+ "end_points"=>
101
+ [{"_id"=>"513538546f1cc9a140000019",
102
+ "port"=>5060,
103
+ "host"=>"2.2.2.2",
104
+ "priority"=>nil}],
105
+ "max_contact_end_points"=>nil,
106
+ "name"=>"OEPG 1",
107
+ "rate_link_types"=>["dialcode"],
108
+ "route_table_ids"=>["513538666f1cc9a14000001b"],
109
+ "updated_at"=>"2013-03-05 00:12:04 UTC",
110
+ "uri_params"=>"",
111
+ "uri_params_blacklist"=>[],
112
+ "uri_user_params"=>"",
113
+ "uri_user_params_blacklist"=>[]
114
+ })
115
+ }
116
+
117
+ let(:outbound_rate2) {
118
+ OutboundRate.new({
119
+ "id"=>"51353a256f1cc98973234320000f",
120
+ "price"=>0.9,
121
+ "type"=>"inter",
122
+ "effective_at"=>"2013-03-05 00:12:37 UTC",
123
+ "created_at"=>"2013-03-05 00:19:49 UTC",
124
+ "updated_at"=>"2013-03-05 00:19:49 UTC",
125
+ "line_number"=>1,
126
+ "dialcode"=>"3217689",
127
+ "account_id"=>"5135354e6f1cc9a140000004",
128
+ "rate_sheet_id"=>"5135388c6f1cc9a14000001f",
129
+ "outbound_end_point_group_id"=>"513538546f1cc9a140000028"
130
+ })
131
+ }
132
+
133
+ it "can be instantiated" do
134
+ Route.new.should be_an_instance_of(Route)
135
+ end
136
+
137
+ it "can return contacts" do
138
+ route = Route.new(:outbound_rate => outbound_rate1, :outbound_end_point_group => oepg1)
139
+ sip_request = RSIP::Message.parse(INVITE)
140
+ a = route.contacts
141
+ a.should be_an_instance_of(Array)
142
+ a.length.should == 1
143
+ c = a.first
144
+ c.should be_an_instance_of(Contact)
145
+ aor = c.build_aor(sip_request, iepg1)
146
+ aor.should == '<sip:50246380762;abc=123@1.1.1.1:5060;otg=3;npdi=yes;rn=2123334545>'
147
+ end
148
+
149
+ it "can build contacts with inbound host and inbound port" do
150
+ iepg2 = iepg1.dup
151
+ iepg2.attributes.contact_template = "<sip:${ruri.dialcode}${ruri.user_params}${oepg.uri_user_params}@${iep.host}${iep.port}${ruri.params}${oepg.uri_params}>"
152
+ route = Route.new(:outbound_rate => outbound_rate1, :outbound_end_point_group => oepg1)
153
+ sip_request = RSIP::Message.parse(INVITE)
154
+ a = route.contacts
155
+ a.should be_an_instance_of(Array)
156
+ a.length.should == 1
157
+ c = a.first
158
+ c.should be_an_instance_of(Contact)
159
+ aor = c.build_aor(sip_request, iepg1, :inbound_end_point_host => '2.2.2.2', :inbound_end_point_port => 5060)
160
+ aor.should == '<sip:50246380762;abc=123@2.2.2.2:5060;otg=3;npdi=yes;rn=2123334545>'
161
+ end
162
+
163
+ it "can build contacts with outbound rate" do
164
+ iepg2 = iepg1.dup
165
+ iepg2.attributes.contact_template = "<sip:${ruri.dialcode}${ruri.user_params}${oepg.uri_user_params}@${iep.host}${iep.port}${ruri.params}${oepg.uri_params};or_price=${or.price}>"
166
+ route = Route.new(:outbound_rate => outbound_rate1, :outbound_end_point_group => oepg1)
167
+ sip_request = RSIP::Message.parse(INVITE)
168
+ a = route.contacts
169
+ a.should be_an_instance_of(Array)
170
+ a.length.should == 1
171
+ c = a.first
172
+ c.should be_an_instance_of(Contact)
173
+ aor = c.build_aor(sip_request, iepg1, :inbound_end_point_host => '2.2.2.2', :inbound_end_point_port => 5060)
174
+ aor.should == '<sip:50246380762;abc=123@2.2.2.2:5060;otg=3;npdi=yes;rn=2123334545;or_price=0.572>'
175
+ end
176
+
177
+ it "can build contacts with inbound rate" do
178
+ iepg2 = iepg1.dup
179
+ iepg2.attributes.contact_template = "<sip:${ruri.dialcode}${ruri.user_params}${oepg.uri_user_params}@${iep.host}${iep.port}${ruri.params}${oepg.uri_params};ir_price=${ir.price}>"
180
+ route = Route.new(:inbound_rate => outbound_rate1, :outbound_end_point_group => oepg1)
181
+ sip_request = RSIP::Message.parse(INVITE)
182
+ a = route.contacts
183
+ a.should be_an_instance_of(Array)
184
+ a.length.should == 1
185
+ c = a.first
186
+ c.should be_an_instance_of(Contact)
187
+ aor = c.build_aor(sip_request, iepg1, :inbound_end_point_host => '2.2.2.2', :inbound_end_point_port => 5060)
188
+ aor.should == '<sip:50246380762;abc=123@2.2.2.2:5060;otg=3;npdi=yes;rn=2123334545;ir_price=0.572>'
189
+ end
190
+
191
+ context "reactor not running" do
192
+ it "can build aors" do
193
+ route = Route.new(:outbound_rate => outbound_rate1, :outbound_end_point_group => oepg1)
194
+ sip_request = RSIP::Message.parse(INVITE)
195
+ r = route.build_aors(sip_request, IEPG1)
196
+ r.should be_an_instance_of(Array)
197
+ route.contacts.first.aor.should be_an_instance_of(String)
198
+ expect { aors2 = route.build_aors(sip_request, nil) }.to raise_error
199
+ end
200
+
201
+ it "can build multiple aors" do
202
+ route1 = Route.new(:outbound_rate => outbound_rate1, :outbound_end_point_group => oepg1)
203
+ route2 = Route.new(:outbound_rate => outbound_rate2, :outbound_end_point_group => oepg2)
204
+ sip_request = RSIP::Message.parse(INVITE)
205
+ aors1 = route1.build_aors(sip_request, IEPG1)
206
+ aors2 = route2.build_aors(sip_request, IEPG1)
207
+ aors1.should == ["<sip:50246380762;abc=123@1.1.1.1:5060;otg=3;npdi=yes;rn=2123334545>"]
208
+ aors2.should == ["<sip:50246380762@2.2.2.2:5060;otg=3;npdi=yes;rn=2123334545>"]
209
+ end
210
+ end
211
+
212
+ context "reactor running" do
213
+ it "can build aors" do
214
+ route = Route.new(:outbound_rate => outbound_rate1, :outbound_end_point_group => oepg1)
215
+ sip_request = RSIP::Message.parse(INVITE)
216
+ aors = nil
217
+ aors2 = nil
218
+
219
+ aors = route.build_aors(sip_request, IEPG1)
220
+ expect { aors2 = route.build_aors(sip_request, nil) }.to raise_error
221
+
222
+ aors.should be_an_instance_of(Array)
223
+ route.contacts.first.aor.should be_an_instance_of(String)
224
+ end
225
+
226
+ end
227
+
228
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ describe RouteNGNClient::RouteTable do
4
+
5
+ before do
6
+ RouteNGNClient.connect(:uri => 'http://127.0.0.1')
7
+ # RouteTables
8
+ body = '{"total_count":1,"current_page":1,"per_page":25,"offset":0,"total_pages":1,"route_tables":[{"route_table":{"name":"Test","rate_types":["undefined","inter","intra","local"],"ordering_method":"lowest_price","max_route_depth":null,"created_at":"2013-03-05T00:12:22Z","updated_at":"2013-03-05T00:12:22Z","id":"513538666f1cc9a14000001b","account_id":"5135354e6f1cc9a140000004","outbound_end_point_group_ids":["513538546f1cc9a140000016"]}}]}'
9
+ stub_request(:get, /^http:\/\/127\.0\.0\.1\/metallic\/route_tables\.json.*/).to_return(:body => body,
10
+ :status => 200,
11
+ :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
12
+ # RouteContainers
13
+ body = '{"route_containers":[{"route_container":{"route_table_id":"513538666f1cc9a14000001b","rate_type":"undefined","destination_code_id":"5135425c165c882a3efc0849","inbound_rate":{"dialcode":"6","lata":null,"ocn":null,"price":0.5,"type":"undefined","weight":null,"effective_at":"2013-03-21T22:43:18Z","ineffective_at":null,"line_number":null,"minimum_duration":null,"billing_increment":null,"min_percent_price_margin":null,"min_absolute_price_margin":null,"min_route_weight":null,"id":"514b8d076f1cc973bd0000c7","inbound_end_point_group_id":"513538316f1cc9a140000010","outbound_end_point_group_id":null,"rate_sheet_id":null},"routes":[{"route":{"outbound_end_point_group_id":"513538546f1cc9a140000016","outbound_rate":{"dialcode":"6076623","lata":null,"ocn":null,"price":0.958,"type":"undefined","weight":null,"effective_at":"2013-03-05T00:12:37Z","ineffective_at":null,"line_number":27319,"minimum_duration":null,"billing_increment":null,"min_percent_price_margin":null,"min_absolute_price_margin":null,"min_route_weight":null,"id":"51353a2e6f1cc98978006b45","inbound_end_point_group_id":null,"outbound_end_point_group_id":"513538546f1cc9a140000016","rate_sheet_id":"5135388c6f1cc9a14000001f"}}}]}}]}'
14
+ stub_request(:get, /^http:\/\/127\.0\.0\.1\/metallic\/route_tables\/513538666f1cc9a14000001b\/route_containers\.json.*/).to_return(:body => body,
15
+ :status => 200,
16
+ :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
17
+
18
+ # OEPG
19
+ body = '{"outbound_end_point_group":{"id":"513538546f1cc9a140000016","carrier_id":"513538546f1cc9a140000017","color_code":"#f379de","created_at":"2013-03-05 00:12:04 UTC","default_route_weight":null,"destination_billing_type":"DN","dialcode_expression":"([0-9]*)$","dialcode_template":"${dialcode_match}","end_points":[{"_id":"513538546f1cc9a140000018","port":5060,"host":"1.1.1.1","priority":null}],"max_contact_end_points":null,"name":"OEPG 1","rate_link_types":["dialcode"],"route_table_ids":["513538666f1cc9a14000001b"],"updated_at":"2013-03-05 00:12:04 UTC","uri_params":"","uri_params_blacklist":[],"uri_user_params":"","uri_user_params_blacklist":[]}}'
20
+ stub_request(:get, /^http:\/\/127\.0\.0\.1\/metallic\/outbound_end_point_groups\/513538546f1cc9a140000016\.json.*/).to_return(:body => body,
21
+ :status => 200,
22
+ :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
23
+ end
24
+
25
+ it "can be instanstiated" do
26
+ rt = RouteTable.new
27
+ rt.should be_an_instance_of(RouteTable)
28
+ end
29
+
30
+ it "can get all via callback" do
31
+ route_tables = nil
32
+
33
+ RouteNGNClient::RouteTable.all({}, :account_id => 'foofoo') do |models|
34
+ route_tables = models
35
+ end
36
+
37
+ route_tables.length.should == 1
38
+ route_tables.first.should be_an_instance_of RouteNGNClient::RouteTable
39
+ end
40
+
41
+ it "can get all via fibers" do
42
+ route_tables = nil
43
+
44
+ route_tables = RouteNGNClient::RouteTable.all({}, :account_id => 'foofoo')
45
+
46
+ route_tables.length.should == 1
47
+ route_tables.first.should be_an_instance_of RouteNGNClient::RouteTable
48
+ end
49
+
50
+ it "can get route_containers" do
51
+ route_containers = nil
52
+ rc = nil
53
+ e_routes = nil
54
+
55
+ route_tables = RouteNGNClient::RouteTable.all({}, :account_id => 'foofoo')
56
+
57
+ route_table = route_tables.first
58
+ route_table.should be_an_instance_of RouteNGNClient::RouteTable
59
+
60
+ params = {}
61
+ params[:env] = { :account_id => 'foofoo' }
62
+ params[:destination_code_id] = '5135425c165c882a3efc0849'
63
+ params[:origination_code_id] = '5135425c165c882a3efc0849'
64
+ params[:destination_dialcode] = '6076623'
65
+ params[:origination_dialcode] = '6076623'
66
+ params[:inbound_end_point_group_id] = '513538316f1cc9a140000010'
67
+ params[:rate_type] = 'undefined'
68
+
69
+ route_table.route_containers(params) do |models|
70
+ route_containers = models
71
+ end
72
+
73
+ rc = route_containers.first
74
+ e_routes = rc.enhanced_routes
75
+
76
+ route_containers.length.should == 1
77
+ rc.should be_an_instance_of RouteNGNClient::RouteContainer
78
+ rc.routes.length.should == 1
79
+ rc.inbound_rate.should be_an_instance_of RouteNGNClient::InboundRate
80
+ e_routes.length.should == 1
81
+ route = e_routes.first
82
+ route.should be_an_instance_of RouteNGNClient::Route
83
+ route.inbound_rate.should be_an_instance_of RouteNGNClient::InboundRate
84
+ route.outbound_end_point_group.should be_an_instance_of RouteNGNClient::OutboundEndPointGroup
85
+ end
86
+
87
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe RouteNGNClient::RemoteModel do
4
+
5
+ before do
6
+ RouteNGNClient.connect(:uri => 'http://127.0.0.1')
7
+
8
+ bodya = '{"total_count":1,"current_page":1,"per_page":200,"offset":0,"total_pages":1,"testas":[{"testa":{}}]}'
9
+ stub_request(:get, /^http:\/\/127\.0\.0\.1\/testas\.json.*/).to_return(:body => bodya,
10
+ :status => 200,
11
+ :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
12
+
13
+ stub_request(:get, /^http:\/\/127\.0\.0\.1\/testa_with_acct\.json\?env%5Baccount_id%5D=abcd.*/).to_return(:body => bodya,
14
+ :status => 200,
15
+ :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
16
+
17
+ bodyb = '{"testb":{}}'
18
+ stub_request(:get, /^http:\/\/127\.0\.0\.1\/testb\/1\.json.*/).to_return(:body => bodyb,
19
+ :status => 200,
20
+ :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
21
+ end
22
+
23
+ it "should create a new instance given valid attributes" do
24
+ m = RemoteModel.new
25
+ m.should be_an_instance_of(RemoteModel)
26
+ end
27
+
28
+ describe '#set_resource_attributes' do
29
+ it "should set resource_attributes" do
30
+ rm = Class.new(RemoteModel)
31
+ rm.set_resource_attributes({:path_ext => '.foo'})
32
+ rm.path_ext.should == '.foo'
33
+ end
34
+ end
35
+
36
+ describe '#all' do
37
+ it "should return an Array instance" do
38
+ rm = Class.new(RemoteModel)
39
+ rm.set_resource_attributes(:path_base => 'testas', :collection_name => 'testas')
40
+ rm.all.should be_an_instance_of(Array)
41
+ end
42
+
43
+ it "should use :account_id in options" do
44
+ rm = Class.new(RemoteModel)
45
+ rm.set_resource_attributes(:path_base => 'testa_with_acct', :collection_name => 'testas')
46
+ models = rm.all({}, :account_id => 'abcd')
47
+ models.should be_an_instance_of(Array)
48
+ models.first.request_account_id.should == 'abcd'
49
+ end
50
+ end
51
+
52
+ describe '#find' do
53
+ it "should return an RemoteModel instance" do
54
+ rm = Class.new(RemoteModel)
55
+ rm.set_resource_attributes(:path_base => 'testb', :collection_name => 'testb')
56
+ rm.find(1).should be_an_instance_of(rm)
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe RouteNGNClient::Request do
4
+
5
+ before do
6
+
7
+ end
8
+
9
+ it "should create a new instance given valid attributes" do
10
+ c = Request.new({}, :test, {}, {})
11
+ c.should be_an_instance_of(Request)
12
+ end
13
+
14
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe RouteNGNClient::Response do
4
+
5
+ before do
6
+ @env1 = { :status => 200,
7
+ :body => {
8
+ :total_count => 1,
9
+ :current_page => 1,
10
+ :per_page => 10,
11
+ :offset => 0,
12
+ :total_pages => 1
13
+ }
14
+ }
15
+ end
16
+
17
+ it "should create a new instance given valid attributes" do
18
+ c = Response.new(nil, nil)
19
+ c.should be_an_instance_of(Response)
20
+ end
21
+
22
+ it "should have paging information" do
23
+ fr = OpenStruct.new(:env => @env1)
24
+ r = Response.new(nil, fr)
25
+ r.total_pages.should == 1
26
+ r.pages_left?.should == false
27
+ end
28
+
29
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe RouteNGNClient do
4
+
5
+ end
@@ -0,0 +1,34 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'bundler/setup'
3
+ require 'webmock/rspec'
4
+ require 'simplecov'
5
+ require 'rspec'
6
+ require 'ffaker'
7
+ require 'rsip'
8
+ require 'routengn_client'
9
+
10
+ include RouteNGNClient
11
+
12
+ SimpleCov.start do
13
+ add_filter 'spec'
14
+ end
15
+
16
+ RSpec.configure do |config|
17
+ config.treat_symbols_as_metadata_keys_with_true_values = true
18
+ config.run_all_when_everything_filtered = true
19
+ #config.filter_run :focus
20
+
21
+ # Use color in STDOUT
22
+ config.color_enabled = true
23
+
24
+ # Use color not only in STDOUT but also in pagers and files
25
+ config.tty = true
26
+
27
+ config.before(:suite) do
28
+ end
29
+
30
+ config.after(:suite) do
31
+ end
32
+ end
33
+
34
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each{|f| require f}