onsip 0.0.8 → 0.0.9
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 +4 -4
- data/.rspec +2 -0
- data/bin/onsip +4 -2
- data/lib/onsip/connection.rb +7 -2
- data/lib/onsip/session.rb +29 -8
- data/lib/onsip/version.rb +1 -1
- data/lib/onsip.rb +12 -3
- data/onsip.gemspec +2 -1
- data/spec/lib/onsip/session_spec.rb +29 -0
- data/spec/spec_helper.rb +94 -0
- metadata +24 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e86219349aaabe949b5c8d61fa83a7532fec8049
|
4
|
+
data.tar.gz: 5e2a2ce635807c8e79db668e63cd5ab3f9e54346
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 775131b7aad62549de28d8d0d600d443faa312cc38dd88f83a4f8c5dbc799c2cb9cbdd335e5f4048b5fa3b01f8249a6dbed5528949c0fa5bdd587c979da10c59
|
7
|
+
data.tar.gz: 29ccf0628368492cfd8ce9c97c68b4b7eb00d25bec4d01a6dd8b8ba1fd3d2b5bc8f11edbac0cccd5500336feb8491acd8ac5666f2ff9b85d16fc66db78d3e017
|
data/.rspec
ADDED
data/bin/onsip
CHANGED
@@ -9,6 +9,8 @@ opts = Trollop::options do
|
|
9
9
|
opt :uri, "OnSIP URI", :type => :string
|
10
10
|
opt :username, "OnSIP Username", :type => :string
|
11
11
|
opt :password, "OnSIP Password", :type => :string
|
12
|
+
opt :log_response_headers, "Log Response Headers", :type => :boolean
|
13
|
+
opt :log_response_body, "Log Response Body", :type => :boolean
|
12
14
|
end
|
13
15
|
|
14
16
|
uri = opts.delete :uri
|
@@ -19,8 +21,8 @@ begin
|
|
19
21
|
OnSIP.connect(uri, opts)
|
20
22
|
OnSIP.auth!(username, password)
|
21
23
|
rescue StandardError => e
|
22
|
-
OnSIP.logger.
|
23
|
-
OnSIP.logger.
|
24
|
+
OnSIP.logger.warn e.message
|
25
|
+
OnSIP.logger.warn e.backtrace.join("\n")
|
24
26
|
end
|
25
27
|
|
26
28
|
pry.binding
|
data/lib/onsip/connection.rb
CHANGED
@@ -2,11 +2,15 @@ module OnSIP
|
|
2
2
|
class Connection
|
3
3
|
|
4
4
|
USER_AGENT = "onsip-client v#{OnSIP::VERSION}"
|
5
|
+
DEFAULT_OPTIONS = {
|
6
|
+
:log_response_headers => false,
|
7
|
+
:log_response_body => false
|
8
|
+
}
|
5
9
|
|
6
10
|
attr_accessor :options, :faraday
|
7
11
|
|
8
12
|
def initialize(options = {})
|
9
|
-
@options = options
|
13
|
+
@options = DEFAULT_OPTIONS.merge(options)
|
10
14
|
@faraday = self.create_faraday(options[:uri])
|
11
15
|
end
|
12
16
|
|
@@ -19,7 +23,7 @@ module OnSIP
|
|
19
23
|
|
20
24
|
c.response :json, :content_type => /\bjson$/
|
21
25
|
c.response :mashify
|
22
|
-
c.response :logger, OnSIP.logger
|
26
|
+
c.response :logger, OnSIP.logger if @options[:log_response_headers]
|
23
27
|
|
24
28
|
c.use :instrumentation
|
25
29
|
c.adapter Faraday.default_adapter
|
@@ -36,6 +40,7 @@ module OnSIP
|
|
36
40
|
env[:total_time] = Time.now.utc.to_f - sent_at.utc.to_f if sent_at
|
37
41
|
env[:request_params] = params
|
38
42
|
env[:request_options] = options
|
43
|
+
OnSIP.logger.debug env.body if @options[:log_response_body]
|
39
44
|
callback.call(env) if callback
|
40
45
|
}
|
41
46
|
|
data/lib/onsip/session.rb
CHANGED
@@ -15,6 +15,10 @@ module OnSIP
|
|
15
15
|
@attributes.UserId
|
16
16
|
end
|
17
17
|
|
18
|
+
def established?
|
19
|
+
@attributes.IsEstablished && @attributes.IsEstablished.downcase == 'true'
|
20
|
+
end
|
21
|
+
|
18
22
|
def user
|
19
23
|
@user ||= User.read(self.user_id)
|
20
24
|
end
|
@@ -23,6 +27,12 @@ module OnSIP
|
|
23
27
|
@account ||= self.user.account
|
24
28
|
end
|
25
29
|
|
30
|
+
def destroy!
|
31
|
+
session = self.class.destroy!(self.id)
|
32
|
+
self.attributes.merge!(session.attributes)
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
26
36
|
module ClassMethods
|
27
37
|
def create(username, password)
|
28
38
|
response = OnSIP.connection.get('/api', {'Action' => 'SessionCreate', 'Username' => username, 'Password' => password, 'Output' => 'json'}, {})
|
@@ -31,14 +41,25 @@ module OnSIP
|
|
31
41
|
|
32
42
|
def process_create_session_response(response)
|
33
43
|
session = nil
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
44
|
+
|
45
|
+
key_path = %w(Response Context Session)
|
46
|
+
a = ResponseParser.parse_response response, key_path
|
47
|
+
session = (a.map { |h| new h }).first if a
|
48
|
+
|
49
|
+
session
|
50
|
+
end
|
51
|
+
|
52
|
+
def destroy!(session_id)
|
53
|
+
response = OnSIP.connection.get('/api', {'Action' => 'SessionDestroy', 'SessionId' => session_id, 'Output' => 'json'}, {})
|
54
|
+
process_destroy_session_response response
|
55
|
+
end
|
56
|
+
|
57
|
+
def process_destroy_session_response(response)
|
58
|
+
session = nil
|
59
|
+
|
60
|
+
key_path = %w(Response Context Session)
|
61
|
+
a = ResponseParser.parse_response response, key_path
|
62
|
+
session = (a.map { |h| new h }).first if a
|
42
63
|
|
43
64
|
session
|
44
65
|
end
|
data/lib/onsip/version.rb
CHANGED
data/lib/onsip.rb
CHANGED
@@ -22,7 +22,6 @@ module OnSIP
|
|
22
22
|
autoload :CDR, 'onsip/models/cdr'
|
23
23
|
|
24
24
|
module ClassMethods
|
25
|
-
attr_accessor :session
|
26
25
|
attr_writer :logger
|
27
26
|
|
28
27
|
def logger
|
@@ -38,7 +37,7 @@ module OnSIP
|
|
38
37
|
|
39
38
|
def connect(uri, options = {})
|
40
39
|
@options = Hashie::Mash.new options
|
41
|
-
@connection = Connection.new(:uri => uri)
|
40
|
+
@connection = Connection.new(options.merge({:uri => uri}))
|
42
41
|
end
|
43
42
|
|
44
43
|
def connection
|
@@ -50,8 +49,18 @@ module OnSIP
|
|
50
49
|
end
|
51
50
|
|
52
51
|
def auth!(username, password)
|
53
|
-
@
|
52
|
+
@username, @password = username, password
|
53
|
+
@session = Session.create(@username, @password)
|
54
54
|
end
|
55
|
+
|
56
|
+
def session
|
57
|
+
if @session && @session.established?
|
58
|
+
@session
|
59
|
+
elsif @username && @password
|
60
|
+
@session = Session.create(@username, @password)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
55
64
|
end
|
56
65
|
|
57
66
|
extend ClassMethods
|
data/onsip.gemspec
CHANGED
@@ -23,10 +23,11 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency 'pry'
|
24
24
|
spec.add_development_dependency 'ffaker', '~> 1.15.0'
|
25
25
|
spec.add_development_dependency 'machinist', '~> 2.0'
|
26
|
-
spec.add_development_dependency 'webmock', '~> 1.
|
26
|
+
spec.add_development_dependency 'webmock', '~> 1.20.4'
|
27
27
|
spec.add_development_dependency 'guard-rspec', '~> 4.2.8'
|
28
28
|
spec.add_development_dependency 'rb-fsevent', '~> 0.9.3'
|
29
29
|
spec.add_development_dependency 'simplecov', '~> 0.8.2'
|
30
|
+
spec.add_development_dependency 'rspec', '>= 3.1.0'
|
30
31
|
spec.add_runtime_dependency 'activesupport', '>= 3.0.0'
|
31
32
|
spec.add_runtime_dependency 'trollop', '~> 2.0'
|
32
33
|
spec.add_runtime_dependency 'multi_json', '~> 1.10.1'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OnSIP::Session do
|
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?.*SessionCreate.*'))
|
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')
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "with valid username and password" do
|
17
|
+
it "can be created" do
|
18
|
+
session = OnSIP::Session.create('test', 'password')
|
19
|
+
expect(session.class).to eq OnSIP::Session
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should be established" do
|
23
|
+
session = OnSIP::Session.create('test', 'password')
|
24
|
+
expect(session.established?).to be(true)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
require 'onsip'
|
5
|
+
|
6
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
7
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
8
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
9
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
10
|
+
#
|
11
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
12
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
13
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
14
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
15
|
+
# a separate helper file that requires the additional dependencies and performs
|
16
|
+
# the additional setup, and require it from the spec files that actually need it.
|
17
|
+
#
|
18
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
19
|
+
# users commonly want.
|
20
|
+
#
|
21
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
22
|
+
RSpec.configure do |config|
|
23
|
+
# rspec-expectations config goes here. You can use an alternate
|
24
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
25
|
+
# assertions if you prefer.
|
26
|
+
config.expect_with :rspec do |expectations|
|
27
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
28
|
+
# and `failure_message` of custom matchers include text for helper methods
|
29
|
+
# defined using `chain`, e.g.:
|
30
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
31
|
+
# # => "be bigger than 2 and smaller than 4"
|
32
|
+
# ...rather than:
|
33
|
+
# # => "be bigger than 2"
|
34
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
35
|
+
end
|
36
|
+
|
37
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
38
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
39
|
+
config.mock_with :rspec do |mocks|
|
40
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
41
|
+
# a real object. This is generally recommended, and will default to
|
42
|
+
# `true` in RSpec 4.
|
43
|
+
mocks.verify_partial_doubles = true
|
44
|
+
end
|
45
|
+
|
46
|
+
# The settings below are suggested to provide a good initial experience
|
47
|
+
# with RSpec, but feel free to customize to your heart's content.
|
48
|
+
=begin
|
49
|
+
# These two settings work together to allow you to limit a spec run
|
50
|
+
# to individual examples or groups you care about by tagging them with
|
51
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
52
|
+
# get run.
|
53
|
+
config.filter_run :focus
|
54
|
+
config.run_all_when_everything_filtered = true
|
55
|
+
|
56
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
57
|
+
# For more details, see:
|
58
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
59
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
60
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
61
|
+
config.disable_monkey_patching!
|
62
|
+
|
63
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
64
|
+
# be too noisy due to issues in dependencies.
|
65
|
+
config.warnings = true
|
66
|
+
|
67
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
68
|
+
# file, and it's useful to allow more verbose output when running an
|
69
|
+
# individual spec file.
|
70
|
+
if config.files_to_run.one?
|
71
|
+
# Use the documentation formatter for detailed output,
|
72
|
+
# unless a formatter has already been configured
|
73
|
+
# (e.g. via a command-line flag).
|
74
|
+
config.default_formatter = 'doc'
|
75
|
+
end
|
76
|
+
|
77
|
+
# Print the 10 slowest examples and example groups at the
|
78
|
+
# end of the spec run, to help surface which specs are running
|
79
|
+
# particularly slow.
|
80
|
+
config.profile_examples = 10
|
81
|
+
|
82
|
+
# Run specs in random order to surface order dependencies. If you find an
|
83
|
+
# order dependency and want to debug it, you can fix the order by providing
|
84
|
+
# the seed, which is printed after each run.
|
85
|
+
# --seed 1234
|
86
|
+
config.order = :random
|
87
|
+
|
88
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
89
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
90
|
+
# test failures related to randomization by passing the same `--seed` value
|
91
|
+
# as the one that triggered the failure.
|
92
|
+
Kernel.srand config.seed
|
93
|
+
=end
|
94
|
+
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.0.
|
4
|
+
version: 0.0.9
|
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-
|
11
|
+
date: 2014-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 1.
|
89
|
+
version: 1.20.4
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 1.
|
96
|
+
version: 1.20.4
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: guard-rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: 0.8.2
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rspec
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 3.1.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 3.1.0
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: activesupport
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -271,6 +285,7 @@ extensions: []
|
|
271
285
|
extra_rdoc_files: []
|
272
286
|
files:
|
273
287
|
- ".gitignore"
|
288
|
+
- ".rspec"
|
274
289
|
- Gemfile
|
275
290
|
- LICENSE.txt
|
276
291
|
- README.md
|
@@ -290,6 +305,8 @@ files:
|
|
290
305
|
- lib/onsip/session.rb
|
291
306
|
- lib/onsip/version.rb
|
292
307
|
- onsip.gemspec
|
308
|
+
- spec/lib/onsip/session_spec.rb
|
309
|
+
- spec/spec_helper.rb
|
293
310
|
homepage: http://icehook.com
|
294
311
|
licenses:
|
295
312
|
- MIT
|
@@ -314,4 +331,6 @@ rubygems_version: 2.2.2
|
|
314
331
|
signing_key:
|
315
332
|
specification_version: 4
|
316
333
|
summary: OnSIP ruby client.
|
317
|
-
test_files:
|
334
|
+
test_files:
|
335
|
+
- spec/lib/onsip/session_spec.rb
|
336
|
+
- spec/spec_helper.rb
|