kazoo-ruby-sdk 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ecbde70ef3fe8ddaa2b4da5c1f17476ff9586145
4
+ data.tar.gz: 43cba6044df426331decec266ea01666ac0cc911
5
+ SHA512:
6
+ metadata.gz: ade7b3e505d08fa96c7a3370a1e3b4983722cde58965684805b9287e0f6c6527348b02e9eb9928c4abd596f4433850bd11dd8a3ac9869368a54288da07628e33
7
+ data.tar.gz: 632ac22eb62212e9f4c29c308e2e3ecc43635f87bec68883befc01b8bbb680833a09995fa3fe9a32734ccb477f875fba11b3b126d52bd5cecfea10c00f248175
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.idea
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kazoo-ruby-sdk.gemspec
4
+ gemspec
5
+
6
+ gem 'faraday'
7
+ gem 'faraday_middleware'
8
+ gem 'multi_json'
9
+ gem 'hashie'
10
+ gem 'yajl-ruby'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Aleksey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Kazoo::Ruby::Sdk
2
+
3
+ SDK for Kazoo API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'kazoo-ruby-sdk'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install kazoo-ruby-sdk
20
+
21
+ ## Config
22
+
23
+ Create config/initializers/kazoo_ruby_sdk.rb
24
+ ```ruby
25
+ KazooRubySdk.auth_url = 'http://yourserver.com:8000/v1'
26
+ KazooRubySdk.realm = 'your-realm'
27
+ KazooRubySdk.username = 'your-username'
28
+ KazooRubySdk.password = 'your-password'
29
+ ```
30
+
31
+ ## Usage
32
+ ```ruby
33
+ api = Whistle::Sdk::AuthSession.new
34
+ session = api.new_session
35
+ devices = session.list_devices.data
36
+ device_id = devices[0].id
37
+ device = session.get_device(device_id)
38
+ ```
39
+
40
+ ## List of methods
41
+
42
+ * list_devices()
43
+ * get_device(device_id)
44
+ * get_device_statuses
45
+ * create_device(name)
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pohodnya/kazoo-ruby-sdk.
50
+
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
55
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kazoo-ruby-sdk/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kazoo-ruby-sdk"
8
+ spec.version = KazooRubySdk::VERSION
9
+ spec.authors = ["Aleksey Pohodnya"]
10
+ spec.email = ["pohodnyaa@gmail.com"]
11
+
12
+ spec.summary = 'SDK for Kazoo API'
13
+ spec.description = 'You can specify the data to access your Kazoo server and use the Kazoo API using the methods of this sdk.'
14
+ spec.homepage = "https://github.com/pohodnya/kazoo-ruby-sdk"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.14"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ end
@@ -0,0 +1,14 @@
1
+ require 'kazoo-ruby-sdk/version'
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+ require 'digest/md5'
5
+
6
+ require 'kazoo-ruby-sdk/base'
7
+ require 'kazoo-ruby-sdk/auth_session'
8
+ require 'kazoo-ruby-sdk/api_session'
9
+
10
+ module KazooRubySDK
11
+ class<< self
12
+ attr_accessor :auth_url, :realm, :username, :password
13
+ end
14
+ end
@@ -0,0 +1,35 @@
1
+ module KazooRubySdk
2
+ class ApiSession < Base
3
+ attr_reader :auth_token, :api_url, :realm, :account_id, :owner_id, :pipe
4
+
5
+ def initialize(options)
6
+ @auth_token = options[:auth_token]
7
+ @api_url = options[:api_url]
8
+ @realm = options[:realm]
9
+ @account_id = options[:account_id]
10
+ @owner_id = options[:owner_id]
11
+ @pipe = create_conn_object(api_url)
12
+ end
13
+
14
+ def list_devices()
15
+ return pipe.get("accounts/#{account_id}/devices",
16
+ 'X-Auth-Token' => auth_token).body
17
+ end
18
+
19
+ def get_device(device_id)
20
+ return pipe.get("accounts/#{account_id}/devices/#{device_id}",
21
+ 'X-Auth-Token' => auth_token).body
22
+ end
23
+
24
+ def get_device_statuses
25
+ return pipe.get("accounts/#{account_id}/devices/status",
26
+ 'X-Auth-Token' => auth_token).body
27
+ end
28
+
29
+ def create_device(name)
30
+ return pipe.put("accounts/#{account_id}/devices",
31
+ {:data => {:name => name}},
32
+ 'X-Auth-Token' => auth_token).body
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,57 @@
1
+ module KazooRubySdk
2
+ class AuthSession < Base
3
+ attr_accessor :auth_url, :realm, :username, :password
4
+ attr_reader :auth_pipe, :auth_token, :account_id, :owner_id, :api_url, :api_pipe, :api_token
5
+
6
+ def initialize
7
+ @auth_url = KazooRubySdk.auth_url
8
+ @realm = KazooRubySdk.realm
9
+ @username = KazooRubySdk.username
10
+ @password = KazooRubySdk.password
11
+
12
+ @auth_pipe = create_conn_object(auth_url)
13
+ end
14
+
15
+ def is_authenticated?
16
+ return !auth_token.nil?
17
+ end
18
+
19
+ def new_session
20
+ authenticate! unless is_authenticated?
21
+ return ApiSession.new(:auth_token => api_token, :api_url => api_url, :realm => realm, :account_id => account_id, :owner_id => owner_id)
22
+ end
23
+
24
+ def get_credentials_hash
25
+ return Digest::MD5.hexdigest("#{username}:#{password}")
26
+ end
27
+
28
+ def authenticate!
29
+ req = {:data => {:credentials => get_credentials_hash, :realm => realm}, :verb => 'PUT'}
30
+ response = auth_pipe.put 'user_auth', req
31
+ @auth_token = response.body.auth_token
32
+ @account_id = response.body.data.account_id
33
+ @owner_id = response.body.data.owner_id
34
+
35
+ @api_url = select_session_endpoint_app('voip')
36
+ @api_pipe = create_conn_object(api_url)
37
+ shared_auth
38
+ end
39
+
40
+ def shared_auth
41
+ req = {:data => {:realm => realm, :account_id => account_id, :shared_token => auth_token}, :verb => 'PUT'}
42
+ resp = @api_pipe.put 'shared_auth', req
43
+ @api_token = resp.body.auth_token
44
+ return api_token
45
+ end
46
+
47
+ def get_endpoint_apps
48
+ auth_pipe.get "accounts/#{account_id}/users/#{owner_id}", 'X-Auth-Token' => auth_token
49
+ end
50
+
51
+ def select_session_endpoint_app(name)
52
+ apps = get_endpoint_apps
53
+ @api_url = apps.body.data.apps[name].api_url
54
+ return api_url
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,15 @@
1
+ module KazooRubySdk
2
+ class Base
3
+ def create_conn_object(url)
4
+ Faraday.new(:url => url,
5
+ :user_agent => 'Kazoo Ruby SDK') do |builder|
6
+ builder.use Faraday::Response::Mashify
7
+ builder.use Faraday::Response::ParseJson
8
+ builder.use Faraday::Response::RaiseError
9
+ builder.use Faraday::Request::JSON
10
+ builder.use Faraday::Request::UrlEncoded
11
+ builder.adapter Faraday.default_adapter
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module KazooRubySdk
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kazoo-ruby-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aleksey Pohodnya
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-05 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
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
+ description: You can specify the data to access your Kazoo server and use the Kazoo
42
+ API using the methods of this sdk.
43
+ email:
44
+ - pohodnyaa@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - kazoo-ruby-sdk.gemspec
55
+ - lib/kazoo-ruby-sdk.rb
56
+ - lib/kazoo-ruby-sdk/api_session.rb
57
+ - lib/kazoo-ruby-sdk/auth_session.rb
58
+ - lib/kazoo-ruby-sdk/base.rb
59
+ - lib/kazoo-ruby-sdk/version.rb
60
+ homepage: https://github.com/pohodnya/kazoo-ruby-sdk
61
+ licenses:
62
+ - MIT
63
+ metadata:
64
+ allowed_push_host: https://rubygems.org
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.5.1
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: SDK for Kazoo API
85
+ test_files: []