onsip 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/bin/onsip +26 -0
- data/lib/onsip/connection.rb +76 -0
- data/lib/onsip/exceptions.rb +17 -0
- data/lib/onsip/model.rb +17 -0
- data/lib/onsip/models/account.rb +67 -0
- data/lib/onsip/models/address.rb +73 -0
- data/lib/onsip/models/cdr.rb +30 -0
- data/lib/onsip/models/organization.rb +50 -0
- data/lib/onsip/models/user.rb +126 -0
- data/lib/onsip/response_parser.rb +38 -0
- data/lib/onsip/session.rb +49 -0
- data/lib/onsip/version.rb +3 -0
- data/lib/onsip.rb +57 -0
- data/onsip.gemspec +39 -0
- metadata +316 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2be0daf7d54e528171e05247afc13bc8292ca16b
|
4
|
+
data.tar.gz: 0979fce2489bb830de163c04e7c4e4cccd6cccef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 41981783d3fa9e92086df4f402db4c2132d9a8866e59fe40e7e47b5c13acb46c87e73248e95ba44a13da5eeb0c65f4820dccc2747a1221141ee8084b62ed026e
|
7
|
+
data.tar.gz: 36f7be133fca3b439db169c05d4df46728a05f7f19b7293e866ff62e820731b66037630b5d5e08a8c3eb1c9822661a38c46d00220f9be11d814c384e1fe92971
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Keith Larrimore
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# OnSIP
|
2
|
+
|
3
|
+
A Ruby Gem that can be used for integration with the OnSIP platform.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'onsip'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install onsip
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
|
25
|
+
OnSIP.connect('https://api.onsip.com/api')
|
26
|
+
OnSIP.auth!(<username>, <password>)
|
27
|
+
|
28
|
+
account = OnSIP.session.account # Find the account associated with this session
|
29
|
+
users = account.users # Find the Users associated with that account
|
30
|
+
pp
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/icehook/onsip/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/onsip
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'pry'
|
5
|
+
|
6
|
+
require File.expand_path('../../lib/onsip', __FILE__)
|
7
|
+
|
8
|
+
opts = Trollop::options do
|
9
|
+
opt :uri, "OnSIP URI", :type => :string
|
10
|
+
opt :username, "OnSIP Username", :type => :string
|
11
|
+
opt :password, "OnSIP Password", :type => :string
|
12
|
+
end
|
13
|
+
|
14
|
+
uri = opts.delete :uri
|
15
|
+
username = opts.delete :username
|
16
|
+
password = opts.delete :password
|
17
|
+
|
18
|
+
begin
|
19
|
+
OnSIP.connect(uri, opts)
|
20
|
+
OnSIP.auth!(username, password)
|
21
|
+
rescue StandardError => e
|
22
|
+
OnSIP.logger.debug e.message
|
23
|
+
OnSIP.logger.debug e.backtrace.join("\n")
|
24
|
+
end
|
25
|
+
|
26
|
+
pry.binding
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module OnSIP
|
2
|
+
class Connection
|
3
|
+
|
4
|
+
USER_AGENT = "onsip-client v#{OnSIP::VERSION}"
|
5
|
+
|
6
|
+
attr_accessor :options, :faraday
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@options = options
|
10
|
+
@faraday = self.create_faraday(options[:uri])
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_faraday(uri)
|
14
|
+
@faraday = Faraday.new uri do |c|
|
15
|
+
c.headers['User-Agent'] = USER_AGENT
|
16
|
+
|
17
|
+
c.request :multipart
|
18
|
+
c.request :url_encoded
|
19
|
+
|
20
|
+
c.response :json, :content_type => /\bjson$/
|
21
|
+
c.response :mashify
|
22
|
+
c.response :logger, OnSIP.logger
|
23
|
+
|
24
|
+
c.use :instrumentation
|
25
|
+
c.adapter Faraday.default_adapter
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def request(method, path, params, options, &callback)
|
30
|
+
sent_at = nil
|
31
|
+
|
32
|
+
response = @faraday.send(method) { |request|
|
33
|
+
sent_at = Time.now
|
34
|
+
request = config_request(request, method, path, params, options)
|
35
|
+
}.on_complete { |env|
|
36
|
+
env[:total_time] = Time.now.utc.to_f - sent_at.utc.to_f if sent_at
|
37
|
+
env[:request_params] = params
|
38
|
+
env[:request_options] = options
|
39
|
+
callback.call(env) if callback
|
40
|
+
}
|
41
|
+
|
42
|
+
response
|
43
|
+
end
|
44
|
+
|
45
|
+
def config_request(request, method, path, params, options)
|
46
|
+
request.headers['Content-Type'] = 'application/json'
|
47
|
+
|
48
|
+
case method.to_sym
|
49
|
+
when :delete, :get
|
50
|
+
request.url(path, params)
|
51
|
+
when :post, :put
|
52
|
+
request.path = path
|
53
|
+
request.body = MultiJson.dump(params) unless params.empty?
|
54
|
+
end
|
55
|
+
|
56
|
+
request
|
57
|
+
end
|
58
|
+
|
59
|
+
def get(path, params={}, options={}, &callback)
|
60
|
+
request(:get, path, params, options, &callback)
|
61
|
+
end
|
62
|
+
|
63
|
+
def delete(path, params={}, options={}, &callback)
|
64
|
+
request(:delete, path, params, options, &callback)
|
65
|
+
end
|
66
|
+
|
67
|
+
def post(path, params={}, options={}, &callback)
|
68
|
+
request(:post, path, params, options, &callback)
|
69
|
+
end
|
70
|
+
|
71
|
+
def put(path, params={}, options={}, &callback)
|
72
|
+
request(:put, path, params, options, &callback)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module OnSIP
|
2
|
+
class OnSIPException < StandardError
|
3
|
+
attr_accessor :options, :exception
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
@options = options
|
7
|
+
@message = @options[:message]
|
8
|
+
@exception = @options[:exception]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class OnSIPRequestException < OnSIPException
|
13
|
+
def response
|
14
|
+
@options[:response]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/onsip/model.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
module OnSIP
|
2
|
+
class Account
|
3
|
+
include Model
|
4
|
+
|
5
|
+
def id
|
6
|
+
@attributes.AccountId
|
7
|
+
end
|
8
|
+
|
9
|
+
def organization_id
|
10
|
+
@attributes.OrganizationId
|
11
|
+
end
|
12
|
+
|
13
|
+
def organizations
|
14
|
+
Organization.browse self.id
|
15
|
+
end
|
16
|
+
|
17
|
+
def users(session = nil)
|
18
|
+
User.browse self.id
|
19
|
+
end
|
20
|
+
|
21
|
+
module ClassMethods
|
22
|
+
def read(account_id)
|
23
|
+
response = OnSIP.connection.get('/api', {'Action' => 'AccountRead', 'AccountId' => account_id, 'SessionId' => OnSIP.session.id, 'Output' => 'json'}, {})
|
24
|
+
process_read_account_response response
|
25
|
+
end
|
26
|
+
|
27
|
+
def process_read_account_response(response)
|
28
|
+
account = nil
|
29
|
+
|
30
|
+
key_path = %w(Response Result AccountRead Account)
|
31
|
+
a = ResponseParser.parse_response response, key_path
|
32
|
+
account = (a.map { |h| new h }).first if a
|
33
|
+
|
34
|
+
account
|
35
|
+
end
|
36
|
+
|
37
|
+
// TODO
|
38
|
+
def edit_contact(*args)
|
39
|
+
raise NotImplementedError
|
40
|
+
end
|
41
|
+
|
42
|
+
// TODO
|
43
|
+
def edit_add_credit(*args)
|
44
|
+
raise NotImplementedError
|
45
|
+
end
|
46
|
+
|
47
|
+
// TODO
|
48
|
+
def edit_recharge(*args)
|
49
|
+
raise NotImplementedError
|
50
|
+
end
|
51
|
+
|
52
|
+
// TODO
|
53
|
+
def invoice_read(*args)
|
54
|
+
raise NotImplementedError
|
55
|
+
end
|
56
|
+
|
57
|
+
// TODO
|
58
|
+
def invoice_browse(*args)
|
59
|
+
raise NotImplementedError
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
extend ClassMethods
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module OnSIP
|
2
|
+
class Address
|
3
|
+
include Model
|
4
|
+
|
5
|
+
DEFAULT_CALL_TIMEOUT = 60
|
6
|
+
|
7
|
+
def id
|
8
|
+
@attributes.AddressId
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def browse(args)
|
13
|
+
params = args.merge({'Action' => 'UserAddressBrowse', 'SessionId' => OnSIP.session.id, 'Output' => 'json'})
|
14
|
+
response = OnSIP.connection.get('/api', params, {})
|
15
|
+
process_browse_address_response response
|
16
|
+
end
|
17
|
+
|
18
|
+
def process_browse_address_response(response)
|
19
|
+
addresses = []
|
20
|
+
|
21
|
+
key_path = %w(Response Result UserAddressBrowse UserAddresses UserAddress)
|
22
|
+
a = ResponseParser.parse_response response, key_path
|
23
|
+
addresses = a.map { |h| new h } if a
|
24
|
+
|
25
|
+
addresses
|
26
|
+
end
|
27
|
+
|
28
|
+
def add(user, attrs = {})
|
29
|
+
params = { 'Username' => user.attributes.Username,
|
30
|
+
'Domain' => user.attributes.Domain,
|
31
|
+
'Timeout' => DEFAULT_CALL_TIMEOUT }.merge(attrs)
|
32
|
+
|
33
|
+
params = params.merge({ 'Action' => 'UserAddressAdd',
|
34
|
+
'SessionId' => OnSIP.session.id,
|
35
|
+
'OrganizationId' => user.organization_id,
|
36
|
+
'UserId' => user.id,
|
37
|
+
'Output' => 'json' })
|
38
|
+
|
39
|
+
response = OnSIP.connection.get('/api', params, {})
|
40
|
+
process_add_address_response response
|
41
|
+
end
|
42
|
+
|
43
|
+
def process_add_address_response(response)
|
44
|
+
address = nil
|
45
|
+
|
46
|
+
key_path = %w(Response Result UserAddressAdd UserAddress)
|
47
|
+
a = ResponseParser.parse_response response, key_path
|
48
|
+
address = (a.map { |h| new h }).first if a
|
49
|
+
|
50
|
+
address
|
51
|
+
end
|
52
|
+
|
53
|
+
// TODO
|
54
|
+
def read(*args)
|
55
|
+
raise NotImplementedError
|
56
|
+
end
|
57
|
+
|
58
|
+
// TODO
|
59
|
+
def edit(*args)
|
60
|
+
raise NotImplementedError
|
61
|
+
end
|
62
|
+
|
63
|
+
// TODO
|
64
|
+
def delete(*args)
|
65
|
+
raise NotImplementedError
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
extend ClassMethods
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module OnSIP
|
2
|
+
class CDR
|
3
|
+
include Model
|
4
|
+
|
5
|
+
def id
|
6
|
+
@attributes.CdrId
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def browse(args = {})
|
11
|
+
params = args.merge({'Action' => 'CdrBrowse', 'SessionId' => OnSIP.session.id, 'Output' => 'json'})
|
12
|
+
response = OnSIP.connection.get('/api', params, {})
|
13
|
+
process_browse_cdrs_response response
|
14
|
+
end
|
15
|
+
|
16
|
+
def process_browse_cdrs_response(response)
|
17
|
+
cdrs = []
|
18
|
+
|
19
|
+
key_path = %w(Response Result CdrBrowse Cdrs Cdr)
|
20
|
+
a = ResponseParser.parse_response response, key_path
|
21
|
+
cdrs = a.map { |h| new h } if a
|
22
|
+
|
23
|
+
cdrs
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
extend ClassMethods
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module OnSIP
|
2
|
+
class Organization
|
3
|
+
include Model
|
4
|
+
|
5
|
+
def id
|
6
|
+
@attributes.OrganizationId
|
7
|
+
end
|
8
|
+
|
9
|
+
def add_user(attrs = {})
|
10
|
+
User.add self, attrs
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def browse(account_id)
|
15
|
+
params = {'Action' => 'OrganizationBrowse', 'AccountId' => account_id, 'SessionId' => OnSIP.session.id, 'Output' => 'json'}
|
16
|
+
response = OnSIP.connection.get('/api', params, {})
|
17
|
+
process_browse_organization_response response
|
18
|
+
end
|
19
|
+
|
20
|
+
def process_browse_organization_response(response)
|
21
|
+
organizations = []
|
22
|
+
|
23
|
+
key_path = %w(Response Result OrganizationBrowse Organizations Organization)
|
24
|
+
a = ResponseParser.parse_response response, key_path
|
25
|
+
organizations = a.map { |h| new h } if a
|
26
|
+
|
27
|
+
organizations
|
28
|
+
end
|
29
|
+
|
30
|
+
def read(organization_id)
|
31
|
+
params = {'Action' => 'OrganizationRead', 'OrganizationId' => organization_id, 'SessionId' => OnSIP.session.id, 'Output' => 'json'}
|
32
|
+
response = OnSIP.connection.get('/api', params, {})
|
33
|
+
process_read_organization_response response
|
34
|
+
end
|
35
|
+
|
36
|
+
def process_read_organization_response(response)
|
37
|
+
organization = nil
|
38
|
+
|
39
|
+
key_path = %w(Response Result OrganizationRead Organization)
|
40
|
+
a = ResponseParser.parse_response response, key_path
|
41
|
+
organization = (a.map { |h| new h }).first if a
|
42
|
+
|
43
|
+
organization
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
extend ClassMethods
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
module OnSIP
|
2
|
+
class User
|
3
|
+
include Model
|
4
|
+
|
5
|
+
def id
|
6
|
+
@attributes.UserId
|
7
|
+
end
|
8
|
+
|
9
|
+
def account_id
|
10
|
+
@attributes.AccountId
|
11
|
+
end
|
12
|
+
|
13
|
+
def organization_id
|
14
|
+
@attributes.OrganizationId
|
15
|
+
end
|
16
|
+
|
17
|
+
def account
|
18
|
+
Account.read self.account_id
|
19
|
+
end
|
20
|
+
|
21
|
+
def add(organization = nil)
|
22
|
+
self.class.add organization, @attributes
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete!
|
26
|
+
self.class.delete! self.id
|
27
|
+
end
|
28
|
+
|
29
|
+
def organization
|
30
|
+
@organization ||= Organization.read(self.organization_id)
|
31
|
+
end
|
32
|
+
|
33
|
+
def addresses
|
34
|
+
Address.browse({'UserId' => self.id})
|
35
|
+
end
|
36
|
+
|
37
|
+
module ClassMethods
|
38
|
+
def browse(account_id)
|
39
|
+
params = {'Action' => 'UserBrowse', 'AccountId' => account_id, 'SessionId' => OnSIP.session.id, 'Output' => 'json'}
|
40
|
+
response = OnSIP.connection.get('/api', params, {})
|
41
|
+
process_browse_user_response response
|
42
|
+
end
|
43
|
+
|
44
|
+
def process_browse_user_response(response)
|
45
|
+
users = []
|
46
|
+
|
47
|
+
key_path = %w(Response Result UserBrowse Users User)
|
48
|
+
a = ResponseParser.parse_response response, key_path
|
49
|
+
users = a.map { |h| new h } if a
|
50
|
+
|
51
|
+
users
|
52
|
+
end
|
53
|
+
|
54
|
+
def delete!(user_id)
|
55
|
+
params = {'Action' => 'UserDelete', 'SessionId' => OnSIP.session.id, 'UserId' => user_id, 'Output' => 'json'}
|
56
|
+
response = OnSIP.connection.get('/api', params, {})
|
57
|
+
process_delete_user_response response
|
58
|
+
end
|
59
|
+
|
60
|
+
def process_delete_user_response(response)
|
61
|
+
r = response.env.body['Response']
|
62
|
+
|
63
|
+
if r && r['Context'] && r['Context']['Action'] && r['Context']['Action']
|
64
|
+
return true
|
65
|
+
else
|
66
|
+
raise OnSIPRequestException, 'Problem with user request'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def edit_status(user_id, attrs = {})
|
71
|
+
params = attrs.merge({'Action' => 'UserEditStatus', 'SessionId' => OnSIP.session.id, 'UserId' => user_id, 'Output' => 'json'})
|
72
|
+
response = OnSIP.connection.get('/api', params, {})
|
73
|
+
process_edit_user_status_response response
|
74
|
+
end
|
75
|
+
|
76
|
+
def process_edit_user_status_response(response)
|
77
|
+
user = nil
|
78
|
+
r = response.env.body['Response']
|
79
|
+
|
80
|
+
key_path = %w(Response Result UserEditStatus User)
|
81
|
+
a = ResponseParser.parse_response response, key_path
|
82
|
+
user = (a.map { |h| new h }).first if a
|
83
|
+
|
84
|
+
user
|
85
|
+
end
|
86
|
+
|
87
|
+
def add(organization, attrs = {})
|
88
|
+
params = attrs.merge({'Action' => 'UserAdd',
|
89
|
+
'SessionId' => OnSIP.session.id,
|
90
|
+
'OrganizationId' => organization.id,
|
91
|
+
'Domain' => organization.attributes.Domain,
|
92
|
+
'Output' => 'json'})
|
93
|
+
response = OnSIP.connection.get('/api', params, {})
|
94
|
+
process_add_user_response response
|
95
|
+
end
|
96
|
+
|
97
|
+
def process_add_user_response(response)
|
98
|
+
user = nil
|
99
|
+
|
100
|
+
key_path = %w(Response Result UserAdd User)
|
101
|
+
a = ResponseParser.parse_response response, key_path
|
102
|
+
user = (a.map { |h| new h }).first if a
|
103
|
+
|
104
|
+
user
|
105
|
+
end
|
106
|
+
|
107
|
+
def read(user_id)
|
108
|
+
response = OnSIP.connection.get('/api', {'Action' => 'UserRead', 'UserId' => user_id, 'SessionId' => OnSIP.session.id, 'Output' => 'json'}, {})
|
109
|
+
process_read_user_response response
|
110
|
+
end
|
111
|
+
|
112
|
+
def process_read_user_response(response)
|
113
|
+
user = nil
|
114
|
+
|
115
|
+
key_path = %w(Response Result UserRead User)
|
116
|
+
a = ResponseParser.parse_response response, key_path
|
117
|
+
user = (a.map { |h| new h }).first if a
|
118
|
+
|
119
|
+
user
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
extend ClassMethods
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module OnSIP
|
2
|
+
module ResponseParser
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
def parse_response(response, key_path = [], ignore_result_keys = [])
|
6
|
+
result = []
|
7
|
+
|
8
|
+
return result unless response && !response.env.body.blank?
|
9
|
+
|
10
|
+
r = response.env.body
|
11
|
+
|
12
|
+
key_path.each_with_index do |key, i|
|
13
|
+
if i < (key_path.length - 1) && r[key]
|
14
|
+
r = r[key]
|
15
|
+
elsif i == (key_path.length - 1) && r[key] && r[key].kind_of?(Array)
|
16
|
+
a = r[key]
|
17
|
+
result = a.flatten.map { |h| h.delete_if { |k| ignore_result_keys.include?(k) }; h }
|
18
|
+
elsif i == (key_path.length - 1) && r[key] && r[key].kind_of?(Hash)
|
19
|
+
h = r[key]
|
20
|
+
h.delete_if { |k| ignore_result_keys.include?(k) }
|
21
|
+
result = [h]
|
22
|
+
else
|
23
|
+
break
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
result
|
28
|
+
rescue StandardError => e
|
29
|
+
raise OnSIPRequestException.new(:message => 'Problem with parsing response',
|
30
|
+
:exception => e,
|
31
|
+
:response => response)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
extend ClassMethods
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module OnSIP
|
2
|
+
class Session
|
3
|
+
|
4
|
+
attr_accessor :attributes
|
5
|
+
|
6
|
+
def initialize(attributes = {})
|
7
|
+
@attributes = Hashie::Mash.new attributes
|
8
|
+
end
|
9
|
+
|
10
|
+
def id
|
11
|
+
@attributes.SessionId
|
12
|
+
end
|
13
|
+
|
14
|
+
def user_id
|
15
|
+
@attributes.UserId
|
16
|
+
end
|
17
|
+
|
18
|
+
def user
|
19
|
+
@user ||= User.read(self.user_id)
|
20
|
+
end
|
21
|
+
|
22
|
+
def account
|
23
|
+
@account ||= self.user.account
|
24
|
+
end
|
25
|
+
|
26
|
+
module ClassMethods
|
27
|
+
def create(username, password)
|
28
|
+
response = OnSIP.connection.get('/api', {'Action' => 'SessionCreate', 'Username' => username, 'Password' => password, 'Output' => 'json'}, {})
|
29
|
+
process_create_session_response response
|
30
|
+
end
|
31
|
+
|
32
|
+
def process_create_session_response(response)
|
33
|
+
session = nil
|
34
|
+
r = response.env.body['Response']['Context']
|
35
|
+
|
36
|
+
if r['Request'] && (r['Request']['IsValid'] == 'true') && r['Session']
|
37
|
+
h = r['Session'].delete_if { |key| %w().include?(key) }
|
38
|
+
session = new h
|
39
|
+
else
|
40
|
+
raise OnSIPRequestException, 'Problem with session request'
|
41
|
+
end
|
42
|
+
|
43
|
+
session
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
extend ClassMethods
|
48
|
+
end
|
49
|
+
end
|
data/lib/onsip.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'trollop'
|
3
|
+
require 'multi_json'
|
4
|
+
require 'awesome_print'
|
5
|
+
require 'active_support/core_ext'
|
6
|
+
require 'hashie'
|
7
|
+
require 'faraday'
|
8
|
+
require 'faraday_middleware'
|
9
|
+
require 'onsip/exceptions'
|
10
|
+
require 'onsip/version'
|
11
|
+
|
12
|
+
module OnSIP
|
13
|
+
autoload :Connection, 'onsip/connection'
|
14
|
+
autoload :Session, 'onsip/session'
|
15
|
+
autoload :ResponseParser, 'onsip/response_parser'
|
16
|
+
autoload :Model, 'onsip/model'
|
17
|
+
autoload :Account, 'onsip/models/account'
|
18
|
+
autoload :User, 'onsip/models/user'
|
19
|
+
autoload :Organization, 'onsip/models/organization'
|
20
|
+
autoload :Address, 'onsip/models/address'
|
21
|
+
autoload :CDR, 'onsip/models/cdr'
|
22
|
+
|
23
|
+
module ClassMethods
|
24
|
+
attr_accessor :session
|
25
|
+
attr_writer :logger
|
26
|
+
|
27
|
+
def logger
|
28
|
+
@logger ||= init_logger
|
29
|
+
end
|
30
|
+
|
31
|
+
def init_logger
|
32
|
+
@logger = Logger.new(STDOUT)
|
33
|
+
@logger.level = Logger::DEBUG
|
34
|
+
|
35
|
+
@logger
|
36
|
+
end
|
37
|
+
|
38
|
+
def connect(uri, options = {})
|
39
|
+
@options = Hashie::Mash.new options
|
40
|
+
@connection = Connection.new(:uri => uri)
|
41
|
+
end
|
42
|
+
|
43
|
+
def connection
|
44
|
+
@connection
|
45
|
+
end
|
46
|
+
|
47
|
+
def options
|
48
|
+
@options
|
49
|
+
end
|
50
|
+
|
51
|
+
def auth!(username, password)
|
52
|
+
@session = Session.create(username, password)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
extend ClassMethods
|
57
|
+
end
|
data/onsip.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'onsip/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "onsip"
|
8
|
+
spec.version = OnSIP::VERSION
|
9
|
+
spec.authors = ["Keith Larrimore"]
|
10
|
+
spec.email = ["klarrimore@icehook.com"]
|
11
|
+
spec.summary = %q{Onsip Ruby client.}
|
12
|
+
spec.description = %q{Onsip Ruby client.}
|
13
|
+
spec.homepage = "http://icehook.com"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'pry'
|
24
|
+
spec.add_development_dependency 'ffaker', '~> 1.15.0'
|
25
|
+
spec.add_development_dependency 'machinist', '~> 2.0'
|
26
|
+
spec.add_development_dependency 'webmock', '~> 1.17.4'
|
27
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.2.8'
|
28
|
+
spec.add_development_dependency 'rb-fsevent', '~> 0.9.3'
|
29
|
+
spec.add_development_dependency 'simplecov', '~> 0.8.2'
|
30
|
+
spec.add_runtime_dependency 'activesupport', '>= 3.0.0'
|
31
|
+
spec.add_runtime_dependency 'trollop', '~> 2.0'
|
32
|
+
spec.add_runtime_dependency 'multi_json', '~> 1.10.1'
|
33
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.6.1'
|
34
|
+
spec.add_runtime_dependency 'faraday', '~> 0.9.0'
|
35
|
+
spec.add_runtime_dependency 'faraday_middleware', '~> 0.9.1'
|
36
|
+
spec.add_runtime_dependency 'awesome_print', '~> 1.2.0'
|
37
|
+
spec.add_runtime_dependency 'builder', '~> 3.2.2'
|
38
|
+
spec.add_runtime_dependency 'hashie', '~> 3.3.1'
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,316 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: onsip
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Keith Larrimore
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ffaker
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.15.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.15.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: machinist
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.17.4
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.17.4
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 4.2.8
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 4.2.8
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rb-fsevent
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.9.3
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.9.3
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.8.2
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.8.2
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: activesupport
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 3.0.0
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 3.0.0
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: trollop
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '2.0'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '2.0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: multi_json
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 1.10.1
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 1.10.1
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: nokogiri
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: 1.6.1
|
188
|
+
type: :runtime
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 1.6.1
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: faraday
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - "~>"
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: 0.9.0
|
202
|
+
type: :runtime
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - "~>"
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: 0.9.0
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: faraday_middleware
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - "~>"
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: 0.9.1
|
216
|
+
type: :runtime
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - "~>"
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: 0.9.1
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: awesome_print
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - "~>"
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: 1.2.0
|
230
|
+
type: :runtime
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - "~>"
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: 1.2.0
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
name: builder
|
239
|
+
requirement: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - "~>"
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: 3.2.2
|
244
|
+
type: :runtime
|
245
|
+
prerelease: false
|
246
|
+
version_requirements: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - "~>"
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: 3.2.2
|
251
|
+
- !ruby/object:Gem::Dependency
|
252
|
+
name: hashie
|
253
|
+
requirement: !ruby/object:Gem::Requirement
|
254
|
+
requirements:
|
255
|
+
- - "~>"
|
256
|
+
- !ruby/object:Gem::Version
|
257
|
+
version: 3.3.1
|
258
|
+
type: :runtime
|
259
|
+
prerelease: false
|
260
|
+
version_requirements: !ruby/object:Gem::Requirement
|
261
|
+
requirements:
|
262
|
+
- - "~>"
|
263
|
+
- !ruby/object:Gem::Version
|
264
|
+
version: 3.3.1
|
265
|
+
description: Onsip Ruby client.
|
266
|
+
email:
|
267
|
+
- klarrimore@icehook.com
|
268
|
+
executables:
|
269
|
+
- onsip
|
270
|
+
extensions: []
|
271
|
+
extra_rdoc_files: []
|
272
|
+
files:
|
273
|
+
- ".gitignore"
|
274
|
+
- Gemfile
|
275
|
+
- LICENSE.txt
|
276
|
+
- README.md
|
277
|
+
- Rakefile
|
278
|
+
- bin/onsip
|
279
|
+
- lib/onsip.rb
|
280
|
+
- lib/onsip/connection.rb
|
281
|
+
- lib/onsip/exceptions.rb
|
282
|
+
- lib/onsip/model.rb
|
283
|
+
- lib/onsip/models/account.rb
|
284
|
+
- lib/onsip/models/address.rb
|
285
|
+
- lib/onsip/models/cdr.rb
|
286
|
+
- lib/onsip/models/organization.rb
|
287
|
+
- lib/onsip/models/user.rb
|
288
|
+
- lib/onsip/response_parser.rb
|
289
|
+
- lib/onsip/session.rb
|
290
|
+
- lib/onsip/version.rb
|
291
|
+
- onsip.gemspec
|
292
|
+
homepage: http://icehook.com
|
293
|
+
licenses:
|
294
|
+
- MIT
|
295
|
+
metadata: {}
|
296
|
+
post_install_message:
|
297
|
+
rdoc_options: []
|
298
|
+
require_paths:
|
299
|
+
- lib
|
300
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
301
|
+
requirements:
|
302
|
+
- - ">="
|
303
|
+
- !ruby/object:Gem::Version
|
304
|
+
version: '0'
|
305
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
306
|
+
requirements:
|
307
|
+
- - ">="
|
308
|
+
- !ruby/object:Gem::Version
|
309
|
+
version: '0'
|
310
|
+
requirements: []
|
311
|
+
rubyforge_project:
|
312
|
+
rubygems_version: 2.2.0
|
313
|
+
signing_key:
|
314
|
+
specification_version: 4
|
315
|
+
summary: Onsip Ruby client.
|
316
|
+
test_files: []
|