sipwizard 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +9 -3
  3. data/Guardfile +6 -5
  4. data/lib/sipwizard.rb +3 -0
  5. data/lib/sipwizard/account.rb +101 -0
  6. data/lib/sipwizard/binding.rb +40 -0
  7. data/lib/sipwizard/cdr.rb +59 -0
  8. data/lib/sipwizard/connection.rb +31 -7
  9. data/lib/sipwizard/customer.rb +81 -0
  10. data/lib/sipwizard/dial_plan.rb +91 -0
  11. data/lib/sipwizard/provider.rb +99 -0
  12. data/lib/sipwizard/provider_binding.rb +53 -0
  13. data/lib/sipwizard/rate.rb +81 -0
  14. data/lib/sipwizard/relation.rb +27 -0
  15. data/lib/sipwizard/version.rb +1 -1
  16. data/sipwizard.gemspec +6 -4
  17. data/spec/lib/sipwizard/account_spec.rb +80 -0
  18. data/spec/lib/sipwizard/binding_spec.rb +22 -0
  19. data/spec/lib/sipwizard/cdr_spec.rb +21 -0
  20. data/spec/lib/sipwizard/configuration_spec.rb +1 -1
  21. data/spec/lib/sipwizard/connection_spec.rb +19 -25
  22. data/spec/lib/sipwizard/customer_spec.rb +80 -0
  23. data/spec/lib/sipwizard/dial_plan_spec.rb +95 -0
  24. data/spec/lib/sipwizard/provider_binding_spec.rb +22 -0
  25. data/spec/lib/sipwizard/provider_spec.rb +107 -0
  26. data/spec/lib/sipwizard/rate_spec.rb +83 -0
  27. data/spec/lib/sipwizard_spec.rb +1 -1
  28. data/spec/spec.yml.sample +7 -0
  29. data/spec/spec_helper.rb +32 -9
  30. data/spec/vcr/sipsorcery/cdr/count.yml +70 -0
  31. data/spec/vcr/sipsorcery/cdr/get.yml +38 -0
  32. data/spec/vcr/sipsorcery/customeraccount/add.yml +73 -0
  33. data/spec/vcr/sipsorcery/customeraccount/count.yml +36 -0
  34. data/spec/vcr/sipsorcery/customeraccount/delete.yml +36 -0
  35. data/spec/vcr/sipsorcery/customeraccount/get.yml +36 -0
  36. data/spec/vcr/sipsorcery/customeraccount/update.yml +38 -0
  37. data/spec/vcr/sipsorcery/dialplan/add.yml +75 -0
  38. data/spec/vcr/sipsorcery/dialplan/copy.yml +36 -0
  39. data/spec/vcr/sipsorcery/dialplan/count.yml +36 -0
  40. data/spec/vcr/sipsorcery/dialplan/delete.yml +36 -0
  41. data/spec/vcr/sipsorcery/dialplan/get.yml +37 -0
  42. data/spec/vcr/sipsorcery/dialplan/update.yml +39 -0
  43. data/spec/vcr/sipsorcery/rate/add.yml +73 -0
  44. data/spec/vcr/sipsorcery/rate/count.yml +36 -0
  45. data/spec/vcr/sipsorcery/rate/delete.yml +36 -0
  46. data/spec/vcr/sipsorcery/rate/get.yml +36 -0
  47. data/spec/vcr/sipsorcery/rate/update.yml +38 -0
  48. data/spec/vcr/sipsorcery/sipaccount/add.yml +74 -0
  49. data/spec/vcr/sipsorcery/sipaccount/count.yml +36 -0
  50. data/spec/vcr/sipsorcery/sipaccount/delete.yml +69 -0
  51. data/spec/vcr/sipsorcery/sipaccount/get.yml +36 -0
  52. data/spec/vcr/sipsorcery/sipaccount/update.yml +37 -0
  53. data/spec/vcr/sipsorcery/sipaccountbinding/count.yml +36 -0
  54. data/spec/vcr/sipsorcery/sipaccountbinding/get.yml +36 -0
  55. data/spec/vcr/sipsorcery/sipprovider/add.yml +74 -0
  56. data/spec/vcr/sipsorcery/sipprovider/count.yml +36 -0
  57. data/spec/vcr/sipsorcery/sipprovider/delete.yml +36 -0
  58. data/spec/vcr/sipsorcery/sipprovider/get.yml +36 -0
  59. data/spec/vcr/sipsorcery/sipprovider/update.yml +38 -0
  60. data/spec/vcr/sipsorcery/sipproviderbinding/count.yml +36 -0
  61. data/spec/vcr/sipsorcery/sipproviderbinding/get.yml +69 -0
  62. metadata +129 -6
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sipwizard::Customer do
4
+ describe '.count(params={})' do
5
+ subject{ described_class.count }
6
+ it 'returns a result' do
7
+ expect(subject).to be_instance_of Fixnum
8
+ end
9
+ end
10
+
11
+ describe '.create(params)' do
12
+ let(:params) do
13
+ {
14
+ account_name: "foo",
15
+ credit: 4.0
16
+ }
17
+ end
18
+
19
+ subject{ described_class.create(params) }
20
+
21
+ it 'creates a new account' do
22
+ response = subject
23
+ expect(response).not_to be_nil
24
+ expect(response).to be_instance_of String
25
+ expect(response).to match(/(?:\w|-)+/)
26
+ end
27
+
28
+ context 'if the account_name already exists' do
29
+ it 'raise an argument error' do
30
+ expect do
31
+ described_class.create(params)
32
+ described_class.create({account_name: 'foo', credit: 3.0})
33
+ end.to raise_exception(ArgumentError)
34
+ end
35
+ end
36
+ end
37
+
38
+ describe '.find(id)' do
39
+ let(:id){ settings['sensitive_data']['CUSTOMER_ID'] }
40
+
41
+ subject{ described_class.find(id) }
42
+
43
+ it 'returns an account' do
44
+ subject.should be_instance_of Sipwizard::Customer
45
+ subject.id.should eq id
46
+ end
47
+ end
48
+
49
+ describe '.save' do
50
+ let(:id){ settings['sensitive_data']['CUSTOMER_ID'] }
51
+ let(:customer){ described_class.find(id) }
52
+
53
+ before{ customer.should be_instance_of Sipwizard::Customer }
54
+
55
+ subject{ customer.save }
56
+
57
+ it 'updates the account' do
58
+ customer.pin = "1234"
59
+ response = subject
60
+ expect(response).not_to be_nil
61
+ expect(response).to be_instance_of String
62
+ expect(response).to match(/(?:\w|-)+/)
63
+ end
64
+ end
65
+
66
+ describe 'delete' do
67
+ let(:id){ settings['sensitive_data']['CUSTOMER_ID'] }
68
+
69
+ let(:customer){ described_class.find(id) }
70
+
71
+ before{ customer.should be_instance_of Sipwizard::Customer }
72
+
73
+ subject{ customer.delete }
74
+
75
+ it 'delete the customer' do
76
+ response = subject
77
+ expect(response).to be_true
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sipwizard::DialPlan do
4
+ describe '.count(params={})' do
5
+ subject{ described_class.count }
6
+ it 'returns a result' do
7
+ expect(subject).to be_instance_of Fixnum
8
+ end
9
+ end
10
+
11
+ describe '.find(id)' do
12
+ let(:id){ settings['sensitive_data']['DIALPLAN_ID'] }
13
+
14
+ subject{ described_class.find(id) }
15
+
16
+ it 'returns an account' do
17
+ subject.should be_instance_of Sipwizard::DialPlan
18
+ subject.id.should eq id
19
+ end
20
+ end
21
+
22
+ describe '.create(params)' do
23
+ let(:params) do
24
+ {
25
+ dial_plan_name: "foo",
26
+ dial_plan_script: "sys.Dial(\"music@iptel.org\"); sys.Respond(404, \"No one home\")"
27
+ }
28
+ end
29
+
30
+ subject{ described_class.create(params) }
31
+
32
+ it 'creates a new dial_plan' do
33
+ response = subject
34
+ expect(response).not_to be_nil
35
+ expect(response).to be_instance_of String
36
+ expect(response).to match(/(?:\w|-)+/)
37
+ end
38
+
39
+ context 'if the username already exists' do
40
+ it 'raise an argument error' do
41
+ expect do
42
+ described_class.create(params)
43
+ described_class.create({dial_plan_name: 'foo', dial_plan_script: 'bra'})
44
+ end.to raise_exception(ArgumentError)
45
+ end
46
+ end
47
+ end
48
+
49
+ describe 'delete' do
50
+ let(:id){ settings['sensitive_data']['DIALPLAN_ID'] }
51
+
52
+ let(:dial_plan){ described_class.find(id) }
53
+
54
+ before{ dial_plan.should be_instance_of Sipwizard::DialPlan }
55
+
56
+ subject{ dial_plan.delete }
57
+
58
+ it 'delete the account' do
59
+ response = subject
60
+ expect(response).to be_true
61
+ end
62
+ end
63
+
64
+ describe 'copy' do
65
+ let(:id){ settings['sensitive_data']['DIALPLAN_ID'] }
66
+
67
+ let(:dial_plan){ described_class.find(id) }
68
+
69
+ before{ dial_plan.should be_instance_of Sipwizard::DialPlan }
70
+
71
+ subject{ dial_plan.copy }
72
+
73
+ it 'delete the account' do
74
+ response = subject
75
+ expect(response).to be_true
76
+ end
77
+ end
78
+
79
+ describe '.save' do
80
+ let(:id){ settings['sensitive_data']['DIALPLAN_ID'] }
81
+ let(:dial_plan){ described_class.find(id) }
82
+
83
+ before{ dial_plan.should be_instance_of Sipwizard::DialPlan }
84
+
85
+ subject{ dial_plan.save }
86
+
87
+ it 'updates the account' do
88
+ dial_plan.trace_email_address = "foo@bar.com"
89
+ response = subject
90
+ expect(response).not_to be_nil
91
+ expect(response).to be_instance_of String
92
+ expect(response).to match(/(?:\w|-)+/)
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sipwizard::ProviderBinding do
4
+ describe '.count' do
5
+ subject{ described_class.count }
6
+
7
+ it 'returns a result' do
8
+ expect(subject).to be_instance_of Fixnum
9
+ end
10
+ end
11
+
12
+ describe '.find(id)' do
13
+ let(:id){ settings['sensitive_data']['PROVIDER_BINDING_ID'] }
14
+
15
+ subject{ described_class.find(id) }
16
+
17
+ it 'returns an provider binding' do
18
+ subject.should be_instance_of Sipwizard::ProviderBinding
19
+ subject.id.should eq id
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sipwizard::Provider do
4
+ describe '.count' do
5
+ subject{ described_class.count }
6
+
7
+ it 'returns a result' do
8
+ expect(subject).to be_instance_of Fixnum
9
+ end
10
+ end
11
+
12
+ describe '.find(id)' do
13
+ let(:id){ settings['sensitive_data']['PROVIDER_ID'] }
14
+
15
+ subject{ described_class.find(id) }
16
+
17
+ it 'returns an provider' do
18
+ subject.should be_instance_of Sipwizard::Provider
19
+ subject.id.should eq id
20
+ end
21
+ end
22
+
23
+ describe '.create(params)' do
24
+ let(:params) do
25
+ {
26
+ provider_name: "foo",
27
+ provider_username: "bar",
28
+ provider_password: 'provider_password',
29
+ provider_server: 'provider_server',
30
+ provider_type: 'provider_type',
31
+ register_contact: 'register_contact'
32
+ }
33
+ end
34
+
35
+ subject{ described_class.create(params) }
36
+
37
+ it 'creates a new provider and return an id' do
38
+ response = subject
39
+ expect(response).not_to be_nil
40
+ expect(response).to be_instance_of String
41
+ expect(response).to match(/(?:\w|-)+/)
42
+ end
43
+
44
+ context 'if the username already exists' do
45
+ it 'raise an argument error' do
46
+ expect do
47
+ described_class.create(params)
48
+ described_class.create(params.merge({provider_username: 'bar', provider_password: 'bra'}))
49
+ end.to raise_exception(ArgumentError)
50
+ end
51
+ end
52
+ end
53
+
54
+ describe '.save' do
55
+ let(:id){ settings['sensitive_data']['PROVIDER_ID'] }
56
+ let(:provider){ described_class.find(id) }
57
+
58
+ before{ provider.should be_instance_of Sipwizard::Provider }
59
+
60
+ subject{ provider.save }
61
+
62
+ it 'updates the provider' do
63
+ provider.provider_name = "barbar"
64
+ response = subject
65
+ expect(response).not_to be_nil
66
+ expect(response).to be_instance_of String
67
+ expect(response).to match(/(?:\w|-)+/)
68
+ end
69
+ end
70
+
71
+ describe 'delete' do
72
+ let(:id){ settings['sensitive_data']['PROVIDER_ID'] }
73
+
74
+ let(:provider){ described_class.find(id) }
75
+
76
+ before{ provider.should be_instance_of Sipwizard::Provider }
77
+
78
+ subject{ provider.delete }
79
+
80
+ it 'delete the provider' do
81
+ response = subject
82
+ expect(response).to be_true
83
+ end
84
+ end
85
+
86
+ describe 'binding(cache=true)' do
87
+ let(:id){ settings['sensitive_data']['PROVIDER_ID'] }
88
+
89
+ let(:provider){ described_class.find(id) }
90
+
91
+ before{ provider.should be_instance_of Sipwizard::Provider }
92
+
93
+ subject{ provider.binding }
94
+
95
+ it 'return the binding of a provider' do
96
+ Sipwizard::ProviderBinding.should_receive(:find_by_provider_id).once.and_call_original
97
+ expect(subject).to be_instance_of Sipwizard::ProviderBinding
98
+ subject.provider_id.should eq provider.id
99
+ end
100
+
101
+ it 'can skip the cache response' do
102
+ Sipwizard::ProviderBinding.should_receive(:find_by_provider_id).twice.and_call_original
103
+ expect(subject).to be_instance_of Sipwizard::ProviderBinding
104
+ provider.binding(false).provider_id.should eq provider.id
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sipwizard::Rate do
4
+ describe '.count(params={})' do
5
+ subject{ described_class.count }
6
+ it 'returns a result' do
7
+ expect(subject).to be_instance_of Fixnum
8
+ end
9
+ end
10
+
11
+ describe '.create(params)' do
12
+ let(:params) do
13
+ {
14
+ description: "foo",
15
+ prefix: "777",
16
+ rate: 2.0,
17
+ setup_cost: 0,
18
+ increment_seconds: 1
19
+ }
20
+ end
21
+
22
+ subject{ described_class.create(params) }
23
+
24
+ it 'creates a new rate' do
25
+ response = subject
26
+ expect(response).not_to be_nil
27
+ expect(response).to be_instance_of String
28
+ expect(response).to match(/(?:\w|-)+/)
29
+ end
30
+
31
+ context 'if the prefix already exists' do
32
+ it 'raise an argument error' do
33
+ expect do
34
+ described_class.create(params)
35
+ described_class.create({description: 'bar', prefix: "777", rate: 1.0, setup_cost: 0, increment_seconds: 1})
36
+ end.to raise_exception(ArgumentError)
37
+ end
38
+ end
39
+ end
40
+
41
+ describe '.find(id)' do
42
+ let(:id){ settings['sensitive_data']['RATE_ID'] }
43
+
44
+ subject{ described_class.find(id) }
45
+
46
+ it 'returns an account' do
47
+ subject.should be_instance_of Sipwizard::Rate
48
+ subject.id.should eq id
49
+ end
50
+ end
51
+
52
+ describe '.save' do
53
+ let(:id){ settings['sensitive_data']['RATE_ID'] }
54
+ let(:rate){ described_class.find(id) }
55
+
56
+ before{ rate.should be_instance_of Sipwizard::Rate }
57
+
58
+ subject{ rate.save }
59
+
60
+ it 'updates the rate' do
61
+ rate.prefix = "1234"
62
+ response = subject
63
+ expect(response).not_to be_nil
64
+ expect(response).to be_instance_of String
65
+ expect(response).to match(/(?:\w|-)+/)
66
+ end
67
+ end
68
+
69
+ describe 'delete' do
70
+ let(:id){ settings['sensitive_data']['RATE_ID'] }
71
+
72
+ let(:rate){ described_class.find(id) }
73
+
74
+ before{ rate.should be_instance_of Sipwizard::Rate }
75
+
76
+ subject{ rate.delete }
77
+
78
+ it 'delete the customer' do
79
+ response = subject
80
+ expect(response).to be_true
81
+ end
82
+ end
83
+ end
@@ -13,7 +13,7 @@ describe Sipwizard do
13
13
  end
14
14
 
15
15
  it 'has set the api_key' do
16
- subject.config.api_key.must_equal api_key
16
+ subject.config.api_key.should eq api_key
17
17
  end
18
18
  end
19
19
  end
@@ -0,0 +1,7 @@
1
+ sensitive_data:
2
+ SIPSORCERY_API_KEY: "<YOUR API KEY>"
3
+ ID: "<A VALID ID>"
4
+ ACCOUNT_BINDING_ID: "<A VALID ACCOUNT_BINDING_ID>"
5
+ CDR_ID: "<A VALID CDR_ID>"
6
+ PROVIDER_ID: "<A VALID PROVIDER_ID>"
7
+ DIALPLAN_ID: "<A VALID DIALPLAN_ID>"
@@ -3,17 +3,40 @@ require 'bundler/setup'
3
3
  Bundler.require(:test)
4
4
 
5
5
  require_relative '../lib/sipwizard'
6
+ $LOAD_PATH << File.dirname(__FILE__)
6
7
 
7
- require 'minitest/autorun'
8
- require 'minitest/pride'
8
+ Spork.prefork do
9
+ RSpec.configure do |config|
10
+ config.before :suite do
11
+ Sipwizard.configure do |sip_config|
12
+ sip_config.api_key = settings['sensitive_data']['SIPSORCERY_API_KEY']
13
+ end
14
+ end
9
15
 
10
- Turn.config do |c|
11
- c.format = :outline
12
- c.natural = true
13
- end
16
+ def settings
17
+ @settings ||= YAML::load_file(File.join(File.dirname(File.expand_path(__FILE__)), 'spec.yml'))
18
+ end
19
+ end
20
+
21
+ VCR.configure do |config|
22
+ config.cassette_library_dir = "spec/vcr"
23
+ config.hook_into :faraday
24
+ config.default_cassette_options = { serialize_with: :psych , record: :new_episodes} #record: :new_episodes
25
+
26
+ settings['sensitive_data'].each do |k, v|
27
+ config.filter_sensitive_data("<#{k}>"){ |interactive| v }
28
+ end
29
+
30
+ config.around_http_request do |request|
31
+ case request.uri
32
+ when Regexp.new(Sipwizard::Connection::BASE_REST_API)
33
+ #endpoint_test = /rest/v0.1/provisioning.svc/cdr/count" => cdr/count
34
+ #endpoint_test = /rest/v0.1/accounting.svc/cdr/count" => cdr/count
35
+ endpoint_test = URI(request.uri).path[/\/rest\/v0.1\/(?:provisioning|accounting).svc\/([A-z|\/]*)/, 1]
36
+ vcr_options = { match_requests_on: [:method, :path, :body, :headers, :query], allow_playback_repeats: true }
14
37
 
15
- MiniTest::Spec.before :each do
16
- Sipwizard.configure do |config|
17
- config.api_key = 'default_api'
38
+ VCR.use_cassette("sipsorcery/#{endpoint_test}", vcr_options, &request)
39
+ end
40
+ end
18
41
  end
19
42
  end