onsip 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d756dbee6749a9399eefa71653ff605ce1181167
4
- data.tar.gz: 777b636d24fcf319c711edf35a79f2b0cf7650f2
3
+ metadata.gz: d3799330e51714e247923ae9e1523ef2a6a349bc
4
+ data.tar.gz: 5485de0a71597a66071fba8ba4d8d14e07aee7c9
5
5
  SHA512:
6
- metadata.gz: e5358759f94c71ac2e61f02738d613e5c6d7d2988f81a6b54f778085425202beec664018d9b1cc301519c905af2fa40c1e5781aa71b2548c322e598ec14725ec
7
- data.tar.gz: c2be2aead48b8afc2ad3378543f0f8ec74bd7016a11784bc4d3354d90b4e5cddd5c8ea927fff17ea93ee1c3a75f48c9138660372b85eaf7ef25dad8ce8b41702
6
+ metadata.gz: 6010ab6d5f48a46599584ec91fe9553d4b13bef40d6887e02133e82baf38880770218234f831ccb14dde30e80c6cc40b7e31aac7b9f12d403ef55a909f9122f8
7
+ data.tar.gz: 95d5e1a40bd7c5fe7c90705ae117761451e3e22f0250a8a32e8ce9279ef0c12448f0754c7fbb677365a83d620327409b0225ee67e1f3856cea3fdb274e1f43fc
@@ -6,6 +6,18 @@ module OnSIP
6
6
  def initialize(object)
7
7
  @object = object
8
8
  end
9
+
10
+ def message
11
+ if @object && @object.kind_of?(Hash)
12
+ @object[:message]
13
+ else
14
+ @object.to_s
15
+ end
16
+ end
17
+
18
+ def to_s
19
+ self.message
20
+ end
9
21
  end
10
22
 
11
23
  class OnSIPRequestError < OnSIPError
data/lib/onsip/model.rb CHANGED
@@ -9,6 +9,19 @@ module OnSIP
9
9
 
10
10
  module ClassMethods
11
11
 
12
+ DEFAULT_OPTIONS = {}
13
+
14
+ def merge_params(default_options = {}, options = {})
15
+ merged_params = {}
16
+
17
+ default_options.each do |opt,h|
18
+ v = options[opt] || h[:v]
19
+ merged_params[h[:k]] = v
20
+ end
21
+
22
+ merged_params
23
+ end
24
+
12
25
  end
13
26
 
14
27
  extend ClassMethods
@@ -55,8 +55,24 @@ module OnSIP
55
55
  end
56
56
 
57
57
  module ClassMethods
58
- def browse(account_id)
59
- params = {'Action' => 'UserBrowse', 'AccountId' => account_id, 'SessionId' => OnSIP.session.id, 'Output' => 'json'}
58
+ include Model::ClassMethods
59
+
60
+ DEFAULT_OPTIONS = {
61
+ :browse => {
62
+ :order_by => {:k => 'OrderBy', :v => 'UserId'},
63
+ :limit => {:k => 'Limit', :v => 100},
64
+ :offset => {:k => 'Offset', :v => 0},
65
+ :calc_found => {:k => 'CalcFound', :v => true}
66
+ }
67
+ }
68
+
69
+ def browse(account_id, options = {})
70
+ params = merge_params(DEFAULT_OPTIONS[:browse], options)
71
+ params = params.merge({'Action' => 'UserBrowse',
72
+ 'AccountId' => account_id,
73
+ 'SessionId' => OnSIP.session.id,
74
+ 'Output' => 'json'})
75
+
60
76
  response = OnSIP.connection.get('/api', params, {})
61
77
  yield response if block_given?
62
78
  process_browse_user_response response
data/lib/onsip/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OnSIP
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/lib/onsip.rb CHANGED
@@ -2,6 +2,7 @@ require 'logger'
2
2
  require 'trollop'
3
3
  require 'multi_json'
4
4
  require 'awesome_print'
5
+ require 'active_support'
5
6
  require 'active_support/core_ext'
6
7
  require 'hashie'
7
8
  require 'faraday'
data/onsip.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency 'rb-fsevent', '~> 0.9.3'
29
29
  spec.add_development_dependency 'simplecov', '~> 0.8.2'
30
30
  spec.add_development_dependency 'rspec', '>= 3.1.0'
31
- spec.add_runtime_dependency 'activesupport', ['>= 3.0.0', '<= 4.0.0']
31
+ spec.add_runtime_dependency 'activesupport', '>= 4.0.0'
32
32
  spec.add_runtime_dependency 'trollop', '~> 2.0'
33
33
  spec.add_runtime_dependency 'multi_json', '~> 1.10.1'
34
34
  spec.add_runtime_dependency 'nokogiri', '~> 1.6.1'
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe OnSIP::Model do
4
+ before :each do
5
+
6
+ end
7
+
8
+ describe "ClassMethods" do
9
+ it "can merge params" do
10
+ params = OnSIP::Model.merge_params({:test => {:k => 'Test', :v => 123}}, {:test => 456})
11
+ expect(params).to eq({'Test' => 456})
12
+ end
13
+ end
14
+
15
+ end
@@ -2,39 +2,39 @@ require 'spec_helper'
2
2
 
3
3
  describe OnSIP::Account do
4
4
  before :each do
5
-
6
- success_body = {"Response"=>{"Context"=>{"Action"=>{"IsCompleted"=>"true"}, "Request"=>{"IsValid"=>"true", "DateTime"=>"2014-12-04T20:34:18+00:00", "Duration"=>"50", "Parameters"=>{"Parameter"=>[{"Name"=>"AccountId", "Value"=>"27370"}, {"Name"=>"Action", "Value"=>"AccountRead"}, {"Name"=>"Output", "Value"=>"json"}, {"Name"=>"SessionId", "Value"=>"1vflpm8sa25vt88o6nsl60lgi5"}]}}, "Session"=>{"IsEstablished"=>"true", "SessionId"=>"1vflpm8sa25vt88o6nsl60lgi5", "UserId"=>"212762", "Roles"=>{"Role"=>{"Name"=>"Account Admin"}}}}, "Result"=>{"AccountRead"=>{"Account"=>{"AccountId"=>"27370", "Receivable"=>"0.00", "Promocode"=>{}, "Productcode"=>"platform", "PerUserPricing"=>"false", "ResellerBilling"=>"false", "BalanceSeconds"=>"0", "EscrowSecondsUpdate"=>"0", "EscrowSecondsCredit"=>"0", "Balance"=>"00.00", "CreditLimit"=>"0.00", "Recharge"=>"false", "RechargeLevel"=>"0.00", "RechargeThreshold"=>"0.00", "Modified"=>"2014-12-03T19:04:34+00:00", "Created"=>"2014-03-24T14:15:44+00:00", "Contact"=>{"Name"=>"Bar Foo", "Organization"=>"IceHook Systems", "Address"=>"123 Main St", "City"=>"New York", "State"=>"NY", "Zipcode"=>"100000", "Country"=>"United States of America", "CountryId"=>"207", "Phone"=>"1-212-555-1212", "Email"=>"test@icehook.com", "Modified"=>"2014-03-24T14:15:44+00:00"}, "CreditCard"=>{"CreditCardId"=>"12345", "AccountId"=>"54321", "CreditCardType"=>"3", "Name"=>"Foo Bar", "LastFour"=>"****", "Expiration"=>"01/2017", "Modified"=>"2014-10-15T18:07:36+00:00", "FirstName"=>"Foo", "LastName"=>"Bar", "Address"=>"123 Main St", "City"=>"New York", "State"=>"NY", "Zipcode"=>"10000", "CountryId"=>"207", "Phone"=>"1-212-555-1212", "IPAddress"=>"127.0.0.1"}}}}}}.to_json
7
- stub_request(:get, Regexp.new('http://success.onsip.com/api?.*AccountRead.*'))
8
- .to_return({
9
- :body => success_body,
10
- :status => 200,
11
- :headers => { 'Content-Type' => 'application/json; charset=utf-8' }
12
- })
13
-
14
- failed_body = {"Response"=>{"Context"=>{"Action"=>{"IsCompleted"=>"false", "Errors"=>{"Error"=>{"Code"=>"AccountAuthorization.Required", "Message"=>"Permission to perform the requested action has not been granted."}}}, "Request"=>{"IsValid"=>"true", "DateTime"=>"2014-12-04T21:36:21+00:00", "Duration"=>"41", "Parameters"=>{"Parameter"=>[{"Name"=>"AccountId", "Value"=>"12345"}, {"Name"=>"Action", "Value"=>"AccountRead"}, {"Name"=>"Output", "Value"=>"json"}, {"Name"=>"SessionId", "Value"=>"j3kmb4boemqnl6u1vsip210rp7"}]}}, "Session"=>{"IsEstablished"=>"true", "SessionId"=>"j3kmb4boemqnl6u1vsip210rp7", "UserId"=>"212762", "Roles"=>{"Role"=>{"Name"=>"Account Admin"}}}}}}.to_json
15
- stub_request(:get, Regexp.new('http://fail.onsip.com/api?.*AccountRead.*'))
16
- .to_return({
17
- :body => failed_body,
18
- :status => 200,
19
- :headers => { 'Content-Type' => 'application/json; charset=utf-8' }
20
- })
21
-
22
5
  OnSIP.session = OnSIP::Session.new("IsEstablished" => "true")
23
6
  end
24
7
 
25
- describe "Onsip::Account.read" do
26
- it "has a valid id" do
8
+ describe "read" do
9
+
10
+ success_body = {"Response"=>{"Context"=>{"Action"=>{"IsCompleted"=>"true"}, "Request"=>{"IsValid"=>"true", "DateTime"=>"2014-12-04T20:34:18+00:00", "Duration"=>"50", "Parameters"=>{"Parameter"=>[{"Name"=>"AccountId", "Value"=>"27370"}, {"Name"=>"Action", "Value"=>"AccountRead"}, {"Name"=>"Output", "Value"=>"json"}, {"Name"=>"SessionId", "Value"=>"1vflpm8sa25vt88o6nsl60lgi5"}]}}, "Session"=>{"IsEstablished"=>"true", "SessionId"=>"1vflpm8sa25vt88o6nsl60lgi5", "UserId"=>"212762", "Roles"=>{"Role"=>{"Name"=>"Account Admin"}}}}, "Result"=>{"AccountRead"=>{"Account"=>{"AccountId"=>"27370", "Receivable"=>"0.00", "Promocode"=>{}, "Productcode"=>"platform", "PerUserPricing"=>"false", "ResellerBilling"=>"false", "BalanceSeconds"=>"0", "EscrowSecondsUpdate"=>"0", "EscrowSecondsCredit"=>"0", "Balance"=>"00.00", "CreditLimit"=>"0.00", "Recharge"=>"false", "RechargeLevel"=>"0.00", "RechargeThreshold"=>"0.00", "Modified"=>"2014-12-03T19:04:34+00:00", "Created"=>"2014-03-24T14:15:44+00:00", "Contact"=>{"Name"=>"Bar Foo", "Organization"=>"IceHook Systems", "Address"=>"123 Main St", "City"=>"New York", "State"=>"NY", "Zipcode"=>"100000", "Country"=>"United States of America", "CountryId"=>"207", "Phone"=>"1-212-555-1212", "Email"=>"test@icehook.com", "Modified"=>"2014-03-24T14:15:44+00:00"}, "CreditCard"=>{"CreditCardId"=>"12345", "AccountId"=>"54321", "CreditCardType"=>"3", "Name"=>"Foo Bar", "LastFour"=>"****", "Expiration"=>"01/2017", "Modified"=>"2014-10-15T18:07:36+00:00", "FirstName"=>"Foo", "LastName"=>"Bar", "Address"=>"123 Main St", "City"=>"New York", "State"=>"NY", "Zipcode"=>"10000", "CountryId"=>"207", "Phone"=>"1-212-555-1212", "IPAddress"=>"127.0.0.1"}}}}}}.to_json
11
+ before { custom_stub(success_body, 'success', 'AccountRead') }
12
+
13
+ it "with a valid id" do
27
14
  OnSIP.connect('http://success.onsip.com')
28
15
  account = OnSIP::Account.read('27370')
29
16
  expect(account.class).to eq OnSIP::Account
30
17
  end
31
18
 
32
- it "has an invalid id" do
19
+ failed_body = {"Response"=>{"Context"=>{"Action"=>{"IsCompleted"=>"false", "Errors"=>{"Error"=>{"Code"=>"AccountAuthorization.Required", "Message"=>"Permission to perform the requested action has not been granted."}}}, "Request"=>{"IsValid"=>"true", "DateTime"=>"2014-12-04T21:36:21+00:00", "Duration"=>"41", "Parameters"=>{"Parameter"=>[{"Name"=>"AccountId", "Value"=>"12345"}, {"Name"=>"Action", "Value"=>"AccountRead"}, {"Name"=>"Output", "Value"=>"json"}, {"Name"=>"SessionId", "Value"=>"j3kmb4boemqnl6u1vsip210rp7"}]}}, "Session"=>{"IsEstablished"=>"true", "SessionId"=>"j3kmb4boemqnl6u1vsip210rp7", "UserId"=>"212762", "Roles"=>{"Role"=>{"Name"=>"Account Admin"}}}}}}.to_json
20
+ before { custom_stub(failed_body, 'fail', 'AccountRead') }
21
+
22
+ it "with an invalid id" do
33
23
  OnSIP.connect('http://fail.onsip.com')
34
24
  account = nil
35
25
  expect { account = OnSIP::Account.read('12345') }.to raise_error(OnSIP::Exceptions::OnSIPRequestError)
36
26
  expect(account).to be(nil)
37
27
  end
28
+
29
+ end
30
+
31
+ describe "add" do
32
+ end
33
+
34
+ describe "browse" do
35
+ end
36
+
37
+ describe "UserEditContact" do
38
38
  end
39
39
 
40
40
  end
@@ -2,15 +2,17 @@ require 'spec_helper'
2
2
 
3
3
  describe OnSIP::ExternalAddress do
4
4
  before :each do
5
-
6
- body = {"Response"=>{"Context"=>{"Action"=>{"IsCompleted"=>"true"}, "Request"=>{"IsValid"=>"true", "DateTime"=>"2014-12-04T17:39:53+00:00", "Duration"=>"30", "Parameters"=>{"Parameter"=>[{"Name"=>"Action", "Value"=>"SessionCreate"}, {"Name"=>"Output", "Value"=>"json"}, {"Name"=>"Password", "Value"=>"******"}, {"Name"=>"Username", "Value"=>"icehook"}]}}, "Session"=>{"IsEstablished"=>"true", "SessionId"=>"j2vtu1bk7rsdpklofplu07ocq1", "UserId"=>"212762", "Roles"=>{"Role"=>{"Name"=>"Account Admin"}}}}, "Result"=>{"SessionCreate"=>{}}}}.to_json
7
- stub_request(:get, Regexp.new('http://api.onsip.com/api?.*ExternalAddressAdd.*'))
8
- .to_return({
9
- :body => body,
10
- :status => 200,
11
- :headers => { 'Content-Type' => 'application/json; charset=utf-8' }
12
- })
13
5
  OnSIP.connect('http://api.onsip.com')
6
+ OnSIP.session = OnSIP::Session.new("IsEstablished" => "true")
14
7
  end
15
8
 
9
+ describe "browse" do
10
+ body = {"Response"=>{"Context"=>{"Action"=>{"IsCompleted"=>"true"}, "Request"=>{"IsValid"=>"true", "DateTime"=>"2014-12-05T20:13:59+00:00", "Duration"=>"17", "Parameters"=>{"Parameter"=>[{"Name"=>"Action", "Value"=>"ExternalAddressBrowse"}, {"Name"=>"Output", "Value"=>"json"}, {"Name"=>"SessionId", "Value"=>"lu2qftbuv883gu5iu5qofrva90"}, {"Name"=>"UserId", "Value"=>"266848"}, {"Name"=>"Limit", "Value"=>"20"}, {"Name"=>"Offset", "Value"=>"0"}, {"Name"=>"CalcFound", "Value"=>"true"}]}}, "Session"=>{"IsEstablished"=>"true", "SessionId"=>"lu2qftbuv883gu5iu5qofrva90", "UserId"=>"212762", "Roles"=>{"Role"=>{"Name"=>"Account Admin"}}}}, "Result"=>{"ExternalAddressBrowse"=>{"ExternalAddresses"=>{"@attributes"=>{"Limit"=>"20", "Offset"=>"0"}}}}}}.to_json
11
+ before { custom_stub(body, 'api', 'ExternalAddressBrowse') }
12
+
13
+ it "with valid id" do
14
+ ea = OnSIP::ExternalAddress.browse({'UserId' => '266848'})
15
+ expect(ea).to be_empty
16
+ end
17
+ end
16
18
  end
@@ -2,15 +2,17 @@ require 'spec_helper'
2
2
 
3
3
  describe OnSIP::Organization do
4
4
  before :each do
5
-
6
- body = {"Response"=>{"Context"=>{"Action"=>{"IsCompleted"=>"true"}, "Request"=>{"IsValid"=>"true", "DateTime"=>"2014-12-04T17:39:53+00:00", "Duration"=>"30", "Parameters"=>{"Parameter"=>[{"Name"=>"Action", "Value"=>"SessionCreate"}, {"Name"=>"Output", "Value"=>"json"}, {"Name"=>"Password", "Value"=>"******"}, {"Name"=>"Username", "Value"=>"icehook"}]}}, "Session"=>{"IsEstablished"=>"true", "SessionId"=>"j2vtu1bk7rsdpklofplu07ocq1", "UserId"=>"212762", "Roles"=>{"Role"=>{"Name"=>"Account Admin"}}}}, "Result"=>{"SessionCreate"=>{}}}}.to_json
7
- stub_request(:get, Regexp.new('http://api.onsip.com/api?.*OrganizationAdd.*'))
8
- .to_return({
9
- :body => body,
10
- :status => 200,
11
- :headers => { 'Content-Type' => 'application/json; charset=utf-8' }
12
- })
13
5
  OnSIP.connect('http://api.onsip.com')
6
+ OnSIP.session = OnSIP::Session.new("IsEstablished" => "true")
14
7
  end
15
8
 
9
+ describe "read" do
10
+ body = {"Response"=>{"Context"=>{"Action"=>{"IsCompleted"=>"true"}, "Request"=>{"IsValid"=>"true", "DateTime"=>"2014-12-05T19:13:17+00:00", "Duration"=>"24", "Parameters"=>{"Parameter"=>[{"Name"=>"Action", "Value"=>"OrganizationRead"}, {"Name"=>"OrganizationId", "Value"=>"30096"}, {"Name"=>"Output", "Value"=>"json"}, {"Name"=>"SessionId", "Value"=>"7kq545de3001r1h2vfmrh15ag3"}]}}, "Session"=>{"IsEstablished"=>"true", "SessionId"=>"7kq545de3001r1h2vfmrh15ag3", "UserId"=>"212762", "Roles"=>{"Role"=>{"Name"=>"Account Admin"}}}}, "Result"=>{"OrganizationRead"=>{"Organization"=>{"OrganizationId"=>"30096", "AccountId"=>"27370", "Service"=>"platform", "Domain"=>"sip.firertc.com", "CallerId"=>{}, "CallerIdName"=>{}, "CallerIdNumber"=>{}, "Status"=>"enabled", "ExtendedDialing"=>"false", "E911Provisioning"=>"false", "BusyLampField"=>"true", "Authenticated"=>"true", "RegistrationLimit"=>"5000", "Modified"=>"2014-11-24T19:24:03+00:00", "Created"=>"2014-03-24T14:15:44+00:00", "Contact"=>{"Name"=>"Foo Bar", "Organization"=>"IceHook Systems", "Address"=>"123 Main st", "City"=>"New York", "State"=>"NY", "Zipcode"=>"10000", "Country"=>"United States of America", "CountryId"=>"207", "Phone"=>"1-212-222-6263", "Email"=>"foo@example.com", "Modified"=>"2014-03-24T14:15:44+00:00"}}}}}}.to_json
11
+ before { custom_stub(body, 'api', 'OrganizationRead') }
12
+
13
+ it "with valid id" do
14
+ org = OnSIP::Organization.read('30096')
15
+ expect(org.class).to eq OnSIP::Organization
16
+ end
17
+ end
16
18
  end
@@ -2,15 +2,17 @@ require 'spec_helper'
2
2
 
3
3
  describe OnSIP::UserAddress do
4
4
  before :each do
5
-
6
- body = {"Response"=>{"Context"=>{"Action"=>{"IsCompleted"=>"true"}, "Request"=>{"IsValid"=>"true", "DateTime"=>"2014-12-04T17:39:53+00:00", "Duration"=>"30", "Parameters"=>{"Parameter"=>[{"Name"=>"Action", "Value"=>"SessionCreate"}, {"Name"=>"Output", "Value"=>"json"}, {"Name"=>"Password", "Value"=>"******"}, {"Name"=>"Username", "Value"=>"icehook"}]}}, "Session"=>{"IsEstablished"=>"true", "SessionId"=>"j2vtu1bk7rsdpklofplu07ocq1", "UserId"=>"212762", "Roles"=>{"Role"=>{"Name"=>"Account Admin"}}}}, "Result"=>{"SessionCreate"=>{}}}}.to_json
7
- stub_request(:get, Regexp.new('http://api.onsip.com/api?.*UserAddressAdd.*'))
8
- .to_return({
9
- :body => body,
10
- :status => 200,
11
- :headers => { 'Content-Type' => 'application/json; charset=utf-8' }
12
- })
13
5
  OnSIP.connect('http://api.onsip.com')
6
+ OnSIP.session = OnSIP::Session.new("IsEstablished" => "true")
14
7
  end
15
8
 
9
+ describe "browse" do
10
+ body = {"Response"=>{"Context"=>{"Action"=>{"IsCompleted"=>"true"}, "Request"=>{"IsValid"=>"true", "DateTime"=>"2014-12-05T20:02:37+00:00", "Duration"=>"20", "Parameters"=>{"Parameter"=>[{"Name"=>"Action", "Value"=>"UserAddressBrowse"}, {"Name"=>"Output", "Value"=>"json"}, {"Name"=>"SessionId", "Value"=>"lu2qftbuv883gu5iu5qofrva90"}, {"Name"=>"UserId", "Value"=>"252683"}, {"Name"=>"Limit", "Value"=>"20"}, {"Name"=>"Offset", "Value"=>"0"}, {"Name"=>"CalcFound", "Value"=>"true"}]}}, "Session"=>{"IsEstablished"=>"true", "SessionId"=>"lu2qftbuv883gu5iu5qofrva90", "UserId"=>"212762", "Roles"=>{"Role"=>{"Name"=>"Account Admin"}}}}, "Result"=>{"UserAddressBrowse"=>{"UserAddresses"=>{"@attributes"=>{"Limit"=>"20", "Offset"=>"0", "Found"=>"1"}, "UserAddress"=>{"UserId"=>"252683", "AuthUsername"=>"bharris_firertc", "AuthPassword"=>"eUDkEdMnuqiWr2jA", "Timeout"=>"20", "E911LocationId"=>{}, "DoNotDisturb"=>"false", "Address"=>{"AddressId"=>"787282", "Username"=>"bharris", "Domain"=>"sip.firertc.com", "Type"=>"user", "Name"=>"Brendon Harris", "Modified"=>"2014-09-30T18:32:13+00:00", "Created"=>"2014-09-30T18:32:13+00:00", "CplText"=>"<cpl xmlns=\"urn:ietf:params:xml:ns:cpl\"/>"}}}}}}}.to_json
11
+ before { custom_stub(body, 'api', 'UserAddressBrowse') }
12
+
13
+ it "with valid id" do
14
+ ua = OnSIP::UserAddress.browse({'UserId' => '266848'})
15
+ expect(ua).to include OnSIP::UserAddress
16
+ end
17
+ end
16
18
  end
@@ -1,25 +1,52 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OnSIP::User do
4
- before :each do
5
4
 
6
- body = {"Response"=>{"Context"=>{"Action"=>{"IsCompleted"=>"true"}, "Request"=>{"IsValid"=>"true", "DateTime"=>"2014-12-04T20:17:17+00:00", "Duration"=>"46", "Parameters"=>{"Parameter"=>[{"Name"=>"Action", "Value"=>"UserRead"}, {"Name"=>"Output", "Value"=>"json"}, {"Name"=>"SessionId", "Value"=>"bvb4thhuk1d7tb2bddf09teqr4"}, {"Name"=>"UserId", "Value"=>"260161"}]}}, "Session"=>{"IsEstablished"=>"true", "SessionId"=>"bvb4thhuk1d7tb2bddf09teqr4", "UserId"=>"212762", "Roles"=>{"Role"=>{"Name"=>"Account Admin"}}}}, "Result"=>{"UserRead"=>{"User"=>{"UserId"=>"260161", "OrganizationId"=>"30096", "AccountId"=>"27370", "Flags"=>"32", "Status"=>"disabled", "Domain"=>"sip.firertc.com", "Username"=>"test3_firertc", "Password"=>"**********", "AuthUsername"=>"test3_firertc", "Modified"=>"2014-11-24T19:24:03+00:00", "Created"=>"2014-11-03T19:30:08+00:00", "Ack911"=>"1970-01-01T00:00:00+00:00", "SurveyCompleted"=>"1970-01-01T00:00:00+00:00", "AckTrunkingTerms"=>"1970-01-01T00:00:00+00:00", "AckTrunkingE911"=>"1970-01-01T00:00:00+00:00", "AckHostedTerms"=>"1970-01-01T00:00:00+00:00", "AckHostedE911"=>"1970-01-01T00:00:00+00:00", "ExtendedDialing"=>"false", "PSTNForwarding"=>"false", "E911Provisioning"=>"false", "PSTNTrunking"=>"false", "FreePSTNTrunking"=>"false", "BusyLampField"=>"true", "Contact"=>{"Name"=>"test", "Organization"=>"IceHook Systems", "Address"=>"123 Main St", "City"=>"New York", "State"=>"NY", "Zipcode"=>"10000", "Country"=>"United States of America", "CountryId"=>"207", "Phone"=>"1-212-555-1212", "Email"=>"test@icehook.com", "Modified"=>"2014-11-03T19:30:08+00:00"}, "Roles"=>{"Role"=>{"Name"=>"User"}}}}}}}.to_json
7
- stub_request(:get, Regexp.new('http://api.onsip.com/api?.*UserRead.*'))
8
- .to_return({
9
- :body => body,
10
- :status => 200,
11
- :headers => { 'Content-Type' => 'application/json; charset=utf-8' }
12
- })
13
- OnSIP.connect('http://api.onsip.com')
5
+ before :each do
14
6
  OnSIP.session = OnSIP::Session.new("IsEstablished" => "true")
15
7
  end
16
8
 
17
- describe "with valid id" do
18
- it "can be read" do
9
+ describe "read" do
10
+ read_body = {"Response"=>{"Context"=>{"Action"=>{"IsCompleted"=>"true"}, "Request"=>{"IsValid"=>"true", "DateTime"=>"2014-12-04T20:17:17+00:00", "Duration"=>"46", "Parameters"=>{"Parameter"=>[{"Name"=>"Action", "Value"=>"UserRead"}, {"Name"=>"Output", "Value"=>"json"}, {"Name"=>"SessionId", "Value"=>"bvb4thhuk1d7tb2bddf09teqr4"}, {"Name"=>"UserId", "Value"=>"260161"}]}}, "Session"=>{"IsEstablished"=>"true", "SessionId"=>"bvb4thhuk1d7tb2bddf09teqr4", "UserId"=>"212762", "Roles"=>{"Role"=>{"Name"=>"Account Admin"}}}}, "Result"=>{"UserRead"=>{"User"=>{"UserId"=>"260161", "OrganizationId"=>"30096", "AccountId"=>"27370", "Flags"=>"32", "Status"=>"disabled", "Domain"=>"sip.firertc.com", "Username"=>"test3_firertc", "Password"=>"**********", "AuthUsername"=>"test3_firertc", "Modified"=>"2014-11-24T19:24:03+00:00", "Created"=>"2014-11-03T19:30:08+00:00", "Ack911"=>"1970-01-01T00:00:00+00:00", "SurveyCompleted"=>"1970-01-01T00:00:00+00:00", "AckTrunkingTerms"=>"1970-01-01T00:00:00+00:00", "AckTrunkingE911"=>"1970-01-01T00:00:00+00:00", "AckHostedTerms"=>"1970-01-01T00:00:00+00:00", "AckHostedE911"=>"1970-01-01T00:00:00+00:00", "ExtendedDialing"=>"false", "PSTNForwarding"=>"false", "E911Provisioning"=>"false", "PSTNTrunking"=>"false", "FreePSTNTrunking"=>"false", "BusyLampField"=>"true", "Contact"=>{"Name"=>"test", "Organization"=>"IceHook Systems", "Address"=>"123 Main St", "City"=>"New York", "State"=>"NY", "Zipcode"=>"10000", "Country"=>"United States of America", "CountryId"=>"207", "Phone"=>"1-212-555-1212", "Email"=>"test@icehook.com", "Modified"=>"2014-11-03T19:30:08+00:00"}, "Roles"=>{"Role"=>{"Name"=>"User"}}}}}}}.to_json
11
+ before { custom_stub(read_body, 'read', 'UserRead') }
12
+
13
+ it "with valid id" do
14
+ OnSIP.connect('http://read.onsip.com')
19
15
  user = OnSIP::User.read('260161')
20
16
  expect(user.class).to eq OnSIP::User
21
17
  end
22
18
 
23
19
  end
24
20
 
21
+ describe "add" do
22
+ add_body = {"Response"=>{"Context"=>{"Action"=>{ "IsCompleted"=>"true" },"Request"=>{"IsValid"=>"true","DateTime"=>"2014-04-21T16:19:55+00:00","Duration"=>"165","Parameters"=>{"Parameter"=>[{"Name"=>"Action","Value"=>"UserAdd"},{"Name"=>"SessionId","Value"=>"thqqva0i6jp3ea1ved17shcdg7"},{"Name"=>"OrganizationId","Value"=>"25018"},{"Name"=>"Username","Value"=>"docs"},{"Name"=>"Domain","Value"=>"example.onsip.com"},{"Name"=>"Name","Value"=>"Docs"},{"Name"=>"Email","Value"=>"docs@example.onsip.com"},{"Name"=>"AuthUsername","Value"=>"example"},{"Name"=>"Password","Value"=>"******"},{"Name"=>"PasswordConfirm","Value"=>"******"},{"Name"=>"Role","Value"=>"User"}]}},"Session"=>{"IsEstablished"=>"true","SessionId"=>"thqqva0i6jp3ea1ved17shcdg7","UserId"=>"152255","Roles"=>{"Role"=>{ "Name"=>"Account Admin" }}}},"Result"=>{"UserAdd"=>{"User"=>{"UserId"=>"218339","OrganizationId"=>"25018","AccountId"=>"22543","Flags"=>"0","Status"=>"enabled","Domain"=>"example.onsip.com","Username"=>"example","Password"=>"QPD2MLQhdaHB2hBW","AuthUsername"=>"example","Modified"=>"2014-04-21T16:19:55+00:00","Created"=>"2014-04-21T16:19:55+00:00","Ack911"=>"1970-01-01T00:00:00+00:00","SurveyCompleted"=>"1970-01-01T00:00:00+00:00","AckTrunkingTerms"=>"1970-01-01T00:00:00+00:00","AckTrunkingE911"=>"1970-01-01T00:00:00+00:00","AckHostedTerms"=>"1970-01-01T00:00:00+00:00","AckHostedE911"=>"1970-01-01T00:00:00+00:00","ExtendedDialing"=>"false","PSTNForwarding"=>"false","E911Provisioning"=>"false","PSTNTrunking"=>"false","FreePSTNTrunking"=>"false","BusyLampField"=>"false","Contact"=>{"Name"=>"Docs","Organization"=>"example","Address"=>"55 broad street","City"=>"Brooklyn","State"=>"NY","Zipcode"=>"11201","Country"=>"United States of America","CountryId"=>"207","Phone"=>"1-555-555-5555","Email"=>"docs@example.onsip.com","Modified"=>"2014-04-21T16:19:55+00:00"},"Roles"=>{"Role"=>{ "Name"=>"User" }}}}}}}.to_json
23
+ before {
24
+ stub_request(:get, Regexp.new("http://add.onsip.com/api?.*UserAdd.*"))
25
+ .to_return({
26
+ :body => add_body,
27
+ :status => 200,
28
+ :headers => { 'Content-Type' => 'application/json; charset=utf-8' }
29
+ })
30
+ }
31
+
32
+
33
+ it "with valid orgnization and attrs" do
34
+ OnSIP.connect('http://add.onsip.com')
35
+ org = OnSIP::Organization.new
36
+ attrs = {
37
+ 'SessionId' => 'thqqva0i6jp3ea1ved17shcdg7',
38
+ 'OrganizationId' => '2501',
39
+ 'Username' => 'docs',
40
+ 'Domain' => 'example.onsip.com',
41
+ 'Name' => 'Docs',
42
+ 'Email' => 'docs@example.onsip.com',
43
+ 'AuthUsername' => 'example',
44
+ 'Password' => 'mysuperpassword',
45
+ 'PasswordConfirm' => 'mysuperpassword'
46
+ }
47
+ user = OnSIP::User.add(org, attrs)
48
+ expect(user.class).to eq OnSIP::User
49
+ end
50
+ end
51
+
25
52
  end
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ $:.push File.expand_path('../lib', __FILE__)
2
2
  require 'bundler/setup'
3
3
  require 'webmock/rspec'
4
4
  require 'onsip'
5
+ require 'support/helpers'
5
6
 
6
7
  # This file was generated by the `rspec --init` command. Conventionally, all
7
8
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
@@ -31,6 +32,8 @@ RSpec.configure do |config|
31
32
  # # => "be bigger than 2 and smaller than 4"
32
33
  # ...rather than:
33
34
  # # => "be bigger than 2"
35
+
36
+ config.include Helpers
34
37
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
38
  end
36
39
 
@@ -0,0 +1,12 @@
1
+ module Helpers
2
+
3
+ def custom_stub(body, uri_matcher, uri_params)
4
+ stub_request(:get, Regexp.new("http://#{uri_matcher}.onsip.com/api?.*#{uri_params}.*"))
5
+ .to_return({
6
+ :body => body,
7
+ :status => 200,
8
+ :headers => { 'Content-Type' => 'application/json; charset=utf-8' }
9
+ })
10
+ end
11
+
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onsip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Larrimore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-04 00:00:00.000000000 Z
11
+ date: 2014-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -155,9 +155,6 @@ dependencies:
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
158
- - !ruby/object:Gem::Version
159
- version: 3.0.0
160
- - - "<="
161
158
  - !ruby/object:Gem::Version
162
159
  version: 4.0.0
163
160
  type: :runtime
@@ -165,9 +162,6 @@ dependencies:
165
162
  version_requirements: !ruby/object:Gem::Requirement
166
163
  requirements:
167
164
  - - ">="
168
- - !ruby/object:Gem::Version
169
- version: 3.0.0
170
- - - "<="
171
165
  - !ruby/object:Gem::Version
172
166
  version: 4.0.0
173
167
  - !ruby/object:Gem::Dependency
@@ -311,6 +305,7 @@ files:
311
305
  - lib/onsip/session.rb
312
306
  - lib/onsip/version.rb
313
307
  - onsip.gemspec
308
+ - spec/lib/onsip/model_spec.rb
314
309
  - spec/lib/onsip/models/account_spec.rb
315
310
  - spec/lib/onsip/models/cdr_spec.rb
316
311
  - spec/lib/onsip/models/external_address_spec.rb
@@ -320,6 +315,7 @@ files:
320
315
  - spec/lib/onsip/response_parser_spec.rb
321
316
  - spec/lib/onsip/session_spec.rb
322
317
  - spec/spec_helper.rb
318
+ - spec/support/helpers.rb
323
319
  homepage: http://icehook.com
324
320
  licenses:
325
321
  - MIT
@@ -345,6 +341,7 @@ signing_key:
345
341
  specification_version: 4
346
342
  summary: OnSIP ruby client.
347
343
  test_files:
344
+ - spec/lib/onsip/model_spec.rb
348
345
  - spec/lib/onsip/models/account_spec.rb
349
346
  - spec/lib/onsip/models/cdr_spec.rb
350
347
  - spec/lib/onsip/models/external_address_spec.rb
@@ -354,3 +351,4 @@ test_files:
354
351
  - spec/lib/onsip/response_parser_spec.rb
355
352
  - spec/lib/onsip/session_spec.rb
356
353
  - spec/spec_helper.rb
354
+ - spec/support/helpers.rb