kazoo-ruby-sdk 1.0.3 → 1.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
- SHA1:
3
- metadata.gz: 03b2d3ddd7d4f7ad73e7b26c8fb3066dc389ebdf
4
- data.tar.gz: 92aa660f9f2196429b567ba6a64fac3b1f2ec5ff
2
+ SHA256:
3
+ metadata.gz: 9ddd42a741be3478676af431df106f209a9cc20fd38c04aacdbf74c8c3ba34d1
4
+ data.tar.gz: 07d7239b07498bb8c48ea2513ffb77d6dc2ed71cd7d6540b5cc2b98ef7932bf2
5
5
  SHA512:
6
- metadata.gz: add34d864fdec876a36676dfa9d7086a488cbcc74583dd277031595b5712146ae27b76908f3f2f9f32505656872afe0351cb159b0a23fea8c22b3b892177d859
7
- data.tar.gz: 5170deb08ffb28c77bfa5c3e7bfd4467a3e8b8a5ebc0ad682d783b320ec7d4d4f0fa00e54dfdd89d980ae905f2f78c99599e9a17bc4b53947858e62da3061141
6
+ metadata.gz: 6bd8d8278371a48769bc374d79039b3bfb87a5b6daf9993ca89bec5b49f80766083d5a5a2bd81ce66386a1eb05e94b35d2ccc21030236068d930be51b448212d
7
+ data.tar.gz: 2297d0d4963346e639d77440434776a6c0fa57dce936f7d7dc6a052c3eb7547da6680639e34a4146bc521ec099f8a6e30532d202ea8bd2be2fad5abfe657d0fb
data/README.md CHANGED
@@ -32,39 +32,58 @@ end
32
32
 
33
33
  ## Usage
34
34
  ```ruby
35
- devices = KazooRubySdk::Devices.list.data
35
+ devices = KazooRubySdk::Devices.new.list.data
36
36
  device_id = devices[0].id
37
37
  device = KazooRubySdk::Devices.get(device_id)
38
38
  ```
39
+
40
+ By default each method of this SDK will be use the configuration from initializer.
41
+ Also you can explicitly specify a configuration before calling any method.
42
+
43
+ ```ruby
44
+ configuration = {
45
+ auth_url: 'http://your_other_server.com:8000/v1',
46
+ realm: 'your-other-realm',
47
+ username: 'your-other-username',
48
+ password: 'your-other-password'
49
+ }
50
+ devices = KazooRubySdk::Devices.new(configuration).list.data
51
+ ```
39
52
 
40
53
  ## List of methods
41
54
 
42
- #### Devices
55
+ #### Callflows
43
56
  * list()
44
- * get(device_id)
45
- * get_statuses
57
+ * get(id)
46
58
  * create(attributes)
47
59
  * update(id, attributes)
48
60
  * destroy(id)
49
61
 
50
- #### Users
62
+ #### CDRs
63
+ * range(from, to)
64
+ * get(cdr_id)
65
+ * get_all_by_user(user_id)
66
+
67
+ #### Devices
51
68
  * list()
52
- * get(id)
69
+ * get(device_id)
70
+ * get_statuses
53
71
  * create(attributes)
54
72
  * update(id, attributes)
55
73
  * destroy(id)
56
74
 
57
- #### Callflows
75
+ #### Phone Numbers
76
+ * create(phone_number, data)
77
+ * butch_create(phone_numbers)
78
+ * destroy(phone_number)
79
+
80
+ #### Users
58
81
  * list()
59
82
  * get(id)
60
83
  * create(attributes)
61
84
  * update(id, attributes)
62
85
  * destroy(id)
63
86
 
64
- #### CDRs
65
- * range(from, to)
66
- * get(cdr_id)
67
- * get_all_by_user(user_id)
68
87
 
69
88
  ## Contributing
70
89
 
@@ -3,6 +3,7 @@ require 'faraday'
3
3
  require 'faraday_middleware'
4
4
  require 'kazoo-ruby-sdk/version'
5
5
 
6
+ require 'kazoo-ruby-sdk/connection'
6
7
  require 'kazoo-ruby-sdk/base'
7
8
  require 'kazoo-ruby-sdk/callflows'
8
9
  require 'kazoo-ruby-sdk/cdrs'
@@ -1,33 +1,26 @@
1
1
  module KazooRubySdk
2
2
  class Base
3
- class << self
4
- attr_accessor :auth_token, :api_url, :realm, :account_id, :owner_id, :pipe
5
- end
6
-
7
- private
8
-
9
- def self.auth_token
10
- KazooRubySdk::Session.auth_token
11
- end
3
+ include KazooRubySdk::Connection
12
4
 
13
- def self.api_url
14
- KazooRubySdk::Session.api_url
5
+ def initialize(configuration = {})
6
+ @session = KazooRubySdk::Session.new(configuration)
7
+ @configuration = configuration
15
8
  end
16
9
 
17
- def self.realm
18
- KazooRubySdk::Session.realm
10
+ def auth_token
11
+ @session.auth_token
19
12
  end
20
13
 
21
- def self.account_id
22
- KazooRubySdk::Session.account_id
14
+ def account_id
15
+ @session.account_id
23
16
  end
24
17
 
25
- def self.owner_id
26
- KazooRubySdk::Session.owner_id
18
+ def owner_id
19
+ @session.owner_id
27
20
  end
28
21
 
29
- def self.pipe
30
- KazooRubySdk::Session.pipe
22
+ def pipe
23
+ pipeline(@configuration[:api_url])
31
24
  end
32
25
  end
33
26
  end
@@ -1,42 +1,42 @@
1
1
  module KazooRubySdk
2
2
  class Callflows < Base
3
- class << self
4
- def create(attributes)
5
- pipe.put do |request|
6
- request.url "accounts/#{account_id}/callflows"
7
- request.headers['X-Auth-Token'] = auth_token
8
- request.body = { data: attributes }
9
- end.body
10
- end
11
3
 
12
- def update(callflow_id, attributes)
13
- pipe.patch do |request|
14
- request.url "accounts/#{account_id}/callflows/#{callflow_id}"
15
- request.headers['X-Auth-Token'] = auth_token
16
- request.body = { data: attributes }
17
- end.body
18
- end
4
+ def create(attributes)
5
+ pipe.put do |request|
6
+ request.url "accounts/#{account_id}/callflows"
7
+ request.headers['X-Auth-Token'] = auth_token
8
+ request.body = { data: attributes }
9
+ end.body
10
+ end
11
+
12
+ def update(callflow_id, attributes)
13
+ pipe.patch do |request|
14
+ request.url "accounts/#{account_id}/callflows/#{callflow_id}"
15
+ request.headers['X-Auth-Token'] = auth_token
16
+ request.body = { data: attributes }
17
+ end.body
18
+ end
19
19
 
20
- def list
21
- pipe.get do |request|
22
- request.url "accounts/#{account_id}/callflows"
23
- request.headers['X-Auth-Token'] = auth_token
24
- end.body
25
- end
20
+ def list
21
+ pipe.get do |request|
22
+ request.url "accounts/#{account_id}/callflows"
23
+ request.headers['X-Auth-Token'] = auth_token
24
+ end.body
25
+ end
26
26
 
27
- def get(callflow_id)
28
- pipe.get do |request|
29
- request.url "accounts/#{account_id}/callflows/#{callflow_id}"
30
- request.headers['X-Auth-Token'] = auth_token
31
- end.body
32
- end
27
+ def get(callflow_id)
28
+ pipe.get do |request|
29
+ request.url "accounts/#{account_id}/callflows/#{callflow_id}"
30
+ request.headers['X-Auth-Token'] = auth_token
31
+ end.body
32
+ end
33
33
 
34
- def destroy(callflow_id)
35
- pipe.delete do |request|
36
- request.url "accounts/#{account_id}/callflows/#{callflow_id}"
37
- request.headers['X-Auth-Token'] = auth_token
38
- end.body
39
- end
34
+ def destroy(callflow_id)
35
+ pipe.delete do |request|
36
+ request.url "accounts/#{account_id}/callflows/#{callflow_id}"
37
+ request.headers['X-Auth-Token'] = auth_token
38
+ end.body
40
39
  end
40
+
41
41
  end
42
42
  end
@@ -1,26 +1,26 @@
1
1
  module KazooRubySdk
2
2
  class CDRs < Base
3
- class << self
4
- def range(from, to)
5
- pipe.get do |request|
6
- request.url "accounts/#{account_id}/cdrs?created_from=#{from}&created_to=#{to}"
7
- request.headers['X-Auth-Token'] = auth_token
8
- end.body
9
- end
10
3
 
11
- def get(cdr_id)
12
- pipe.get do |request|
13
- request.url "accounts/#{account_id}/cdrs/#{cdr_id}"
14
- request.headers['X-Auth-Token'] = auth_token
15
- end.body
16
- end
4
+ def range(from, to)
5
+ pipe.get do |request|
6
+ request.url "accounts/#{account_id}/cdrs?created_from=#{from}&created_to=#{to}"
7
+ request.headers['X-Auth-Token'] = auth_token
8
+ end.body
9
+ end
10
+
11
+ def get(cdr_id)
12
+ pipe.get do |request|
13
+ request.url "accounts/#{account_id}/cdrs/#{cdr_id}"
14
+ request.headers['X-Auth-Token'] = auth_token
15
+ end.body
16
+ end
17
17
 
18
- def get_all_by_user(user_id)
19
- pipe.get do |request|
20
- request.url "accounts/#{account_id}/users/#{user_id}/cdrs"
21
- request.headers['X-Auth-Token'] = auth_token
22
- end.body
23
- end
18
+ def get_all_by_user(user_id)
19
+ pipe.get do |request|
20
+ request.url "accounts/#{account_id}/users/#{user_id}/cdrs"
21
+ request.headers['X-Auth-Token'] = auth_token
22
+ end.body
24
23
  end
24
+
25
25
  end
26
26
  end
@@ -0,0 +1,22 @@
1
+ module KazooRubySdk
2
+ module Connection
3
+
4
+ def pipeline(api_url = nil)
5
+ api_url ||= KazooRubySdk.configuration.api_url
6
+ create_conn_object(api_url)
7
+ end
8
+
9
+ private
10
+
11
+ def create_conn_object(url)
12
+ Faraday.new(:url => url, ssl: { verify: false }) do |builder|
13
+ builder.use Faraday::Response::Mashify
14
+ builder.use Faraday::Response::ParseJson
15
+ builder.use Faraday::Response::RaiseError
16
+ builder.use FaradayMiddleware::EncodeJson
17
+ builder.use Faraday::Request::UrlEncoded
18
+ builder.adapter Faraday.default_adapter
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,49 +1,49 @@
1
1
  module KazooRubySdk
2
2
  class Devices < Base
3
- class << self
4
- def list
5
- pipe.get do |request|
6
- request.url "accounts/#{account_id}/devices"
7
- request.headers['X-Auth-Token'] = auth_token
8
- end.body
9
- end
10
3
 
11
- def get(device_id)
12
- pipe.get do |request|
13
- request.url "accounts/#{account_id}/devices/#{device_id}"
14
- request.headers['X-Auth-Token'] = auth_token
15
- end.body
16
- end
4
+ def list
5
+ pipe.get do |request|
6
+ request.url "accounts/#{account_id}/devices"
7
+ request.headers['X-Auth-Token'] = auth_token
8
+ end.body
9
+ end
17
10
 
18
- def get_statuses
19
- pipe.get do |request|
20
- request.url "accounts/#{account_id}/devices/status"
21
- request.headers['X-Auth-Token'] = auth_token
22
- end.body
23
- end
11
+ def get(device_id)
12
+ pipe.get do |request|
13
+ request.url "accounts/#{account_id}/devices/#{device_id}"
14
+ request.headers['X-Auth-Token'] = auth_token
15
+ end.body
16
+ end
24
17
 
25
- def create(attributes)
26
- pipe.put do |request|
27
- request.url "accounts/#{account_id}/devices"
28
- request.headers['X-Auth-Token'] = auth_token
29
- request.body = { data: attributes }
30
- end.body
31
- end
18
+ def get_statuses
19
+ pipe.get do |request|
20
+ request.url "accounts/#{account_id}/devices/status"
21
+ request.headers['X-Auth-Token'] = auth_token
22
+ end.body
23
+ end
32
24
 
33
- def update(device_id, attributes)
34
- pipe.patch do |request|
35
- request.url "accounts/#{account_id}/devices/#{device_id}"
36
- request.headers['X-Auth-Token'] = auth_token
37
- request.body = { data: attributes }
38
- end.body
39
- end
25
+ def create(attributes)
26
+ pipe.put do |request|
27
+ request.url "accounts/#{account_id}/devices"
28
+ request.headers['X-Auth-Token'] = auth_token
29
+ request.body = { data: attributes }
30
+ end.body
31
+ end
40
32
 
41
- def destroy(device_id)
42
- pipe.delete do |request|
43
- request.url "accounts/#{account_id}/devices/#{device_id}"
44
- request.headers['X-Auth-Token'] = auth_token
45
- end.body
46
- end
33
+ def update(device_id, attributes)
34
+ pipe.patch do |request|
35
+ request.url "accounts/#{account_id}/devices/#{device_id}"
36
+ request.headers['X-Auth-Token'] = auth_token
37
+ request.body = { data: attributes }
38
+ end.body
47
39
  end
40
+
41
+ def destroy(device_id)
42
+ pipe.delete do |request|
43
+ request.url "accounts/#{account_id}/devices/#{device_id}"
44
+ request.headers['X-Auth-Token'] = auth_token
45
+ end.body
46
+ end
47
+
48
48
  end
49
49
  end
@@ -1,39 +1,39 @@
1
1
  module KazooRubySdk
2
2
  class PhoneNumbers < Base
3
- class << self
4
- # Creates phone number in kazoo for specific account
5
- # @param phone_number [String] the phone number
6
- # @param data [Hash] number's data. see https://github.com/2600hz/kazoo/blob/master/applications/crossbar/doc/phone_numbers.md#schema
7
- # @return [Hashie::Mash] response body
8
- def create(phone_number, data = {})
9
- pipe.put do |request|
10
- request.url "accounts/#{account_id}/phone_numbers/#{phone_number}"
11
- request.headers['X-Auth-Token'] = auth_token
12
- request.body = { data: data }
13
- end.body
14
- end
15
3
 
16
- # Creates list of phone numbers in kazoo for specific account
17
- # @param phone_number [Array] list of phone numbers
18
- # @return [Hashie::Mash] response body
19
- def butch_create(phone_numbers)
20
- pipe.put do |request|
21
- request.url "accounts/#{account_id}/phone_numbers/collection"
22
- request.headers['X-Auth-Token'] = auth_token
23
- request.body = { data: {numbers: phone_numbers} }
24
- end.body
25
- end
4
+ # Creates phone number in kazoo for specific account
5
+ # @param phone_number [String] the phone number
6
+ # @param data [Hash] number's data. see https://github.com/2600hz/kazoo/blob/master/applications/crossbar/doc/phone_numbers.md#schema
7
+ # @return [Hashie::Mash] response body
8
+ def create(phone_number, data = {})
9
+ pipe.put do |request|
10
+ request.url "accounts/#{account_id}/phone_numbers/#{phone_number}"
11
+ request.headers['X-Auth-Token'] = auth_token
12
+ request.body = { data: data }
13
+ end.body
14
+ end
15
+
16
+ # Creates list of phone numbers in kazoo for specific account
17
+ # @param phone_number [Array] list of phone numbers
18
+ # @return [Hashie::Mash] response body
19
+ def butch_create(phone_numbers)
20
+ pipe.put do |request|
21
+ request.url "accounts/#{account_id}/phone_numbers/collection"
22
+ request.headers['X-Auth-Token'] = auth_token
23
+ request.body = { data: {numbers: phone_numbers} }
24
+ end.body
25
+ end
26
26
 
27
27
 
28
- # Delete a specific phone number
29
- # @param phone_number [Array] the phone number
30
- # @return [Hashie::Mash] response body
31
- def destroy(phone_numbers)
32
- pipe.delete do |request|
33
- request.url "accounts/#{account_id}/phone_numbers/#{phone_number}"
34
- request.headers['X-Auth-Token'] = auth_token
35
- end.body
36
- end
28
+ # Delete a specific phone number
29
+ # @param phone_number [Array] the phone number
30
+ # @return [Hashie::Mash] response body
31
+ def destroy(phone_number)
32
+ pipe.delete do |request|
33
+ request.url "accounts/#{account_id}/phone_numbers/#{phone_number}"
34
+ request.headers['X-Auth-Token'] = auth_token
35
+ end.body
37
36
  end
37
+
38
38
  end
39
39
  end
@@ -1,56 +1,42 @@
1
1
  module KazooRubySdk
2
2
  class Session
3
- class << self
4
- attr_writer :api_url, :realm, :account_id, :owner_id, :auth_token, :pipe
5
- end
6
-
7
- class << self
8
- def api_url
9
- KazooRubySdk.configuration.api_url
10
- end
11
-
12
- def realm
13
- KazooRubySdk.configuration.realm
14
- end
3
+ include KazooRubySdk::Connection
15
4
 
16
- def account_id
17
- auth_response.data.account_id
18
- end
19
-
20
- def owner_id
21
- auth_response.data.owner_id
22
- end
5
+ def initialize(configuration = {})
6
+ @api_url = configuration[:api_url]
7
+ @realm = configuration[:realm] || KazooRubySdk.configuration.realm
8
+ @username = configuration[:username] || KazooRubySdk.configuration.username
9
+ @password = configuration[:password] || KazooRubySdk.configuration.password
10
+ end
23
11
 
24
- def auth_token
25
- auth_response.auth_token
26
- end
12
+ def account_id
13
+ auth_response.data.account_id
14
+ end
27
15
 
28
- def pipe
29
- create_conn_object(api_url)
30
- end
16
+ def owner_id
17
+ auth_response.data.owner_id
18
+ end
31
19
 
32
- def create_conn_object(url)
33
- Faraday.new(:url => url, ssl: { verify: false }) do |builder|
34
- builder.use Faraday::Response::Mashify
35
- builder.use Faraday::Response::ParseJson
36
- builder.use Faraday::Response::RaiseError
37
- builder.use FaradayMiddleware::EncodeJson
38
- builder.use Faraday::Request::UrlEncoded
39
- builder.adapter Faraday.default_adapter
40
- end
41
- end
20
+ def auth_token
21
+ auth_response.auth_token
22
+ end
42
23
 
43
- def auth_response
44
- KazooRubySdk.cache.fetch('auth_response') do
45
- req = {:data => {:credentials => get_credentials_hash, :realm => self.realm}, :verb => 'PUT'}
46
- response = pipe.put 'user_auth', req
47
- response.body
48
- end
49
- end
24
+ private
25
+
26
+ def auth_response
27
+ req = {
28
+ :data => {
29
+ :credentials => get_credentials_hash,
30
+ :realm => @realm
31
+ },
32
+ :verb => 'PUT'
33
+ }
34
+ response = pipeline(@api_url).put 'user_auth', req
35
+ response.body
36
+ end
50
37
 
51
- def get_credentials_hash
52
- Digest::MD5.hexdigest("#{KazooRubySdk.configuration.username}:#{KazooRubySdk.configuration.password}")
53
- end
38
+ def get_credentials_hash
39
+ Digest::MD5.hexdigest("#{@username}:#{@password}")
54
40
  end
55
41
  end
56
42
  end
@@ -1,42 +1,42 @@
1
1
  module KazooRubySdk
2
2
  class Users < Base
3
- class << self
4
- def create(attributes)
5
- pipe.put do |request|
6
- request.url "accounts/#{account_id}/users"
7
- request.headers['X-Auth-Token'] = auth_token
8
- request.body = { data: attributes }
9
- end.body
10
- end
11
3
 
12
- def update(user_id, attributes)
13
- pipe.patch do |request|
14
- request.url "accounts/#{account_id}/users/#{user_id}"
15
- request.headers['X-Auth-Token'] = auth_token
16
- request.body = { data: attributes }
17
- end.body
18
- end
4
+ def create(attributes)
5
+ pipe.put do |request|
6
+ request.url "accounts/#{account_id}/users"
7
+ request.headers['X-Auth-Token'] = auth_token
8
+ request.body = { data: attributes }
9
+ end.body
10
+ end
11
+
12
+ def update(user_id, attributes)
13
+ pipe.patch do |request|
14
+ request.url "accounts/#{account_id}/users/#{user_id}"
15
+ request.headers['X-Auth-Token'] = auth_token
16
+ request.body = { data: attributes }
17
+ end.body
18
+ end
19
19
 
20
- def list
21
- pipe.get do |request|
22
- request.url "accounts/#{account_id}/users"
23
- request.headers['X-Auth-Token'] = auth_token
24
- end.body
25
- end
20
+ def list
21
+ pipe.get do |request|
22
+ request.url "accounts/#{account_id}/users"
23
+ request.headers['X-Auth-Token'] = auth_token
24
+ end.body
25
+ end
26
26
 
27
- def get(user_id)
28
- pipe.get do |request|
29
- request.url "accounts/#{account_id}/users/#{user_id}"
30
- request.headers['X-Auth-Token'] = auth_token
31
- end.body
32
- end
27
+ def get(user_id)
28
+ pipe.get do |request|
29
+ request.url "accounts/#{account_id}/users/#{user_id}"
30
+ request.headers['X-Auth-Token'] = auth_token
31
+ end.body
32
+ end
33
33
 
34
- def destroy(user_id)
35
- pipe.delete do |request|
36
- request.url "accounts/#{account_id}/users/#{user_id}"
37
- request.headers['X-Auth-Token'] = auth_token
38
- end.body
39
- end
34
+ def destroy(user_id)
35
+ pipe.delete do |request|
36
+ request.url "accounts/#{account_id}/users/#{user_id}"
37
+ request.headers['X-Auth-Token'] = auth_token
38
+ end.body
40
39
  end
40
+
41
41
  end
42
42
  end
@@ -1,3 +1,3 @@
1
1
  module KazooRubySdk
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kazoo-ruby-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksey Pohodnya
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-25 00:00:00.000000000 Z
11
+ date: 2017-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -128,6 +128,7 @@ files:
128
128
  - lib/kazoo-ruby-sdk/callflows.rb
129
129
  - lib/kazoo-ruby-sdk/cdrs.rb
130
130
  - lib/kazoo-ruby-sdk/configuration.rb
131
+ - lib/kazoo-ruby-sdk/connection.rb
131
132
  - lib/kazoo-ruby-sdk/devices.rb
132
133
  - lib/kazoo-ruby-sdk/phone_numbers.rb
133
134
  - lib/kazoo-ruby-sdk/session.rb
@@ -154,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
155
  version: '0'
155
156
  requirements: []
156
157
  rubyforge_project:
157
- rubygems_version: 2.6.13
158
+ rubygems_version: 2.7.1
158
159
  signing_key:
159
160
  specification_version: 4
160
161
  summary: SDK for Kazoo API