voicearchive_client 0.0.2
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 +7 -0
- data/.exrc +3 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +9 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +34 -0
- data/Rakefile +12 -0
- data/lib/voicearchive/client.rb +78 -0
- data/lib/voicearchive/common_client.rb +34 -0
- data/lib/voicearchive/customer_client.rb +32 -0
- data/lib/voicearchive/factory.rb +18 -0
- data/lib/voicearchive/file_client.rb +9 -0
- data/lib/voicearchive/order_client.rb +74 -0
- data/lib/voicearchive/supplier_client.rb +31 -0
- data/lib/voicearchive/task_client.rb +50 -0
- data/lib/voicearchive/terms_of_payment_client.rb +16 -0
- data/lib/voicearchive/user_client.rb +9 -0
- data/lib/voicearchive/v2/client.rb +12 -0
- data/lib/voicearchive/v2/invoicing_client.rb +16 -0
- data/lib/voicearchive/v2/supplier_client.rb +55 -0
- data/lib/voicearchive/virtualrecording_client.rb +13 -0
- data/lib/voicearchive_client.rb +5 -0
- data/lib/voicearchive_client/version.rb +3 -0
- data/scripts/boostrap +15 -0
- data/scripts/console +13 -0
- data/scripts/server +15 -0
- data/scripts/setup +10 -0
- data/scripts/test +20 -0
- data/scripts/update +9 -0
- data/spec/fixtures/lib/voicearchive/supplier/suppliers_with_relations.json +1 -0
- data/spec/lib/voicearchive/supplier_client_spec.rb +26 -0
- data/spec/spec_helper.rb +18 -0
- data/tags +36 -0
- data/voicearchive_client.gemspec +29 -0
- metadata +194 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 01e35e715a156914a65a201c6c54c4ecf11feb548fd91ecbd4c52df70821ec81
|
4
|
+
data.tar.gz: fa9402baecf70c3ffcaa8245d647601bc6ba39f8d193cfb7abbe0bbd2072dd61
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4673794d9f387bc015754263891f80013f9cffd0f0488c95bf6f8db90529ed15d1e5dda01d5aca5c0c959c08e207fb58870e6a9365b6960df76847e27a0ff226
|
7
|
+
data.tar.gz: 4f69a88d00c789c01ae5f849555480d0027916cb2ccd3e995e31edf5931d827c208533bce0bef2447e470116896841dd6a22f31bd5e83ff11c80031191d4a021
|
data/.exrc
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
> Why is this change proposed? How will it affect the code base? Which results are expected from the change? Include context, UI before/after screenshots, assumptions, knowledge, research, links, references, etc.
|
2
|
+
|
3
|
+
---
|
4
|
+
|
5
|
+
- [ ] This change is a [deliverable change](https://github.com/ArnsboMedia/playbook/tree/master/code-review#pull-requests), that can be deployed in isolation
|
6
|
+
- [ ] Commits in this PR follow our [commit ruleset](https://github.com/ArnsboMedia/playbook/tree/master/code-review#commits) and guidelines
|
7
|
+
- [ ] This PR follows our [styleguides](https://github.com/ArnsboMedia/playbook#code-style) & conventions
|
8
|
+
|
9
|
+
> If any of the above are left blank, argue why..
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Claus Witt
|
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,34 @@
|
|
1
|
+
# VoiceArchive Client Gem [](https://travis-ci.com/ArnsboMedia/voicearchive_client)
|
2
|
+
|
3
|
+
VoiceArchive API client gem, for use i Ruby projects. The projects implements some of the exposed API endpoint, from [Arnsbo Media Engine](https://github.com/ArnsboMedia/systemet).
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
- [Ruby](https://www.ruby-lang.org/en/news/2014/11/13/ruby-1-9-3-p551-is-released/) 1.9.3
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
```shell
|
12
|
+
$ scripts/setup
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
`scripts/server` will start an `irb` console, to play around with the Gem:
|
18
|
+
|
19
|
+
```shell
|
20
|
+
$ scripts/server
|
21
|
+
```
|
22
|
+
|
23
|
+
To use in an applicaiton, add this line to the Gemfile:
|
24
|
+
|
25
|
+
```sh
|
26
|
+
gem 'voicearchive_client', git: 'https://github.com/ArnsboMedia/voicearchive_client.git'
|
27
|
+
```
|
28
|
+
.. and then run `$ bundle` :rocket:
|
29
|
+
|
30
|
+
## Test
|
31
|
+
|
32
|
+
```shell
|
33
|
+
$ scripts/test
|
34
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
class Rake::Task
|
3
|
+
def overwrite(&block)
|
4
|
+
@actions.clear
|
5
|
+
enhance(&block)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
Rake::Task[:release].overwrite do
|
10
|
+
p "This task is bypassed on purpose, to ensure we do not accidentally push the gem to Rubygems"
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require "active_support/core_ext/object/to_query"
|
2
|
+
require "json"
|
3
|
+
require "net/http"
|
4
|
+
require "uri"
|
5
|
+
require "openssl"
|
6
|
+
|
7
|
+
module Voicearchive
|
8
|
+
class Client
|
9
|
+
attr_reader :api_key
|
10
|
+
attr_accessor :version
|
11
|
+
|
12
|
+
@@rest_path = 'rest'
|
13
|
+
@@auth_header = 'X-API-KEY'
|
14
|
+
|
15
|
+
def initialize(api_key = '', version = 1, host = 'https://system.voicearchive.com')
|
16
|
+
@api_key = api_key
|
17
|
+
@version = version
|
18
|
+
@host = host
|
19
|
+
end
|
20
|
+
|
21
|
+
def call(end_point, params={}, request_type="get")
|
22
|
+
url = get_url_object(end_point)
|
23
|
+
http = Net::HTTP.new url.host, url.port
|
24
|
+
http.read_timeout = 360
|
25
|
+
http.use_ssl = false
|
26
|
+
if url.scheme == 'https'
|
27
|
+
http.use_ssl = true
|
28
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
29
|
+
end
|
30
|
+
|
31
|
+
http.start do |http|
|
32
|
+
http.request(self.send("get_#{request_type.downcase}_request".to_sym,url, params))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_simple_endpoint_default_values(params)
|
37
|
+
if not params.key?(:pageSize)
|
38
|
+
params[:pageSize] = 10000000
|
39
|
+
end
|
40
|
+
params
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def get_url_object(end_point)
|
46
|
+
URI.parse("#{@host}/#{@@rest_path}/v#{@version.to_s}/#{end_point}/")
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_get_request(url, params={})
|
50
|
+
path = url.path.concat("?#{params.to_query}")
|
51
|
+
request = Net::HTTP::Get.new(path)
|
52
|
+
set_request_authentication(request)
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_post_request(url, params={})
|
56
|
+
request = Net::HTTP::Post.new(url.path)
|
57
|
+
request.body = params.to_json
|
58
|
+
set_request_authentication(request)
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_put_request(url, params={})
|
62
|
+
request = Net::HTTP::Put.new(url.path)
|
63
|
+
request.body = params.to_json
|
64
|
+
set_request_authentication(request)
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_delete_request(url, params={})
|
68
|
+
request = Net::HTTP::Delete.new(url.path)
|
69
|
+
set_request_authentication(request)
|
70
|
+
end
|
71
|
+
|
72
|
+
def set_request_authentication(request)
|
73
|
+
request.add_field(@@auth_header, @api_key)
|
74
|
+
request
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'voicearchive/client'
|
2
|
+
|
3
|
+
module Voicearchive
|
4
|
+
class CommonClient < Client
|
5
|
+
attr_accessor :endpoint
|
6
|
+
|
7
|
+
def all(params = {})
|
8
|
+
params = set_simple_endpoint_default_values(params)
|
9
|
+
response = call("#{@endpoint}", params, 'get')
|
10
|
+
JSON.parse(response.body)
|
11
|
+
end
|
12
|
+
|
13
|
+
def find(id, params = {})
|
14
|
+
params = set_simple_endpoint_default_values(params)
|
15
|
+
response = call("#{@endpoint}/#{id}", params, 'get')
|
16
|
+
JSON.parse(response.body)
|
17
|
+
end
|
18
|
+
|
19
|
+
def create(params = {})
|
20
|
+
response = call(@endpoint, params, 'post')
|
21
|
+
JSON.parse(response.body)
|
22
|
+
end
|
23
|
+
|
24
|
+
def update(id, params = {})
|
25
|
+
response = call("#{@endpoint}/#{id}", params, 'put')
|
26
|
+
JSON.parse(response.body)
|
27
|
+
end
|
28
|
+
|
29
|
+
def destroy(id)
|
30
|
+
response = call("#{@endpoint}/#{id}", params, 'delete')
|
31
|
+
JSON.parse(response.body)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'voicearchive/client'
|
2
|
+
module Voicearchive
|
3
|
+
class CustomerClient < Client
|
4
|
+
def get_customers(params={})
|
5
|
+
params = set_simple_endpoint_default_values(params)
|
6
|
+
response = call('customer', params)
|
7
|
+
JSON.parse(response.body)
|
8
|
+
end
|
9
|
+
def get_customer(id, params={})
|
10
|
+
params = set_simple_endpoint_default_values(params)
|
11
|
+
response = call("customer/#{id}", params)
|
12
|
+
JSON.parse(response.body)
|
13
|
+
end
|
14
|
+
def update_customer(id, params = {})
|
15
|
+
response = call("customer/#{id}", params, "put")
|
16
|
+
JSON.parse(response.body)
|
17
|
+
end
|
18
|
+
def get_customer_contacts(id, params={})
|
19
|
+
params = set_simple_endpoint_default_values(params)
|
20
|
+
response = call("customer/#{id}/contacts", params)
|
21
|
+
JSON.parse(response.body)
|
22
|
+
end
|
23
|
+
def get_customer_contact(customer_id, contact_id, params={})
|
24
|
+
response = call("customer/#{customer_id}/contacts/#{contact_id}", params)
|
25
|
+
JSON.parse(response.body)
|
26
|
+
end
|
27
|
+
def update_customer_contact(customer_id, contact_id, params={})
|
28
|
+
response = call("customer/#{customer_id}/contacts/#{contact_id}", params, "put")
|
29
|
+
JSON.parse(response.body)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'active_support/core_ext/string/inflections'
|
2
|
+
module Voicearchive
|
3
|
+
class Factory
|
4
|
+
attr_reader :api_key
|
5
|
+
def initialize api_key
|
6
|
+
@api_key = api_key
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_client name
|
10
|
+
name = name.to_s # allow symbols to be stringified
|
11
|
+
name = "#{name}_client" # suffix with client
|
12
|
+
require "voicearchive/#{name}" # require the file
|
13
|
+
constant_name = "Voicearchive::#{name.camelize}" # the constant name of the class (in the Voicearchive module)
|
14
|
+
constant_name.constantize.new(api_key) # return the new class, with the correct api_key
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'voicearchive/client'
|
2
|
+
require 'voicearchive/task_client'
|
3
|
+
|
4
|
+
module Voicearchive
|
5
|
+
class OrderClient < Client
|
6
|
+
def get_orders(params = {})
|
7
|
+
response = call("order", params)
|
8
|
+
JSON.parse(response.body)
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_order(order_id, params = {})
|
12
|
+
response = call("order/#{order_id}", params)
|
13
|
+
JSON.parse(response.body)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_order(order_id, params = {})
|
17
|
+
response = call("order/#{order_id}", params, 'put')
|
18
|
+
JSON.parse(response.body)
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_order_tasks(order_id, params = {})
|
22
|
+
response = call("order/#{order_id}/tasks", params)
|
23
|
+
JSON.parse(response.body)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_order_task(order_id, task_id, params = {})
|
27
|
+
response = call("order/#{order_id}/tasks/#{task_id}", params)
|
28
|
+
JSON.parse(response.body)
|
29
|
+
end
|
30
|
+
|
31
|
+
def update_order_task(order_id, task_id, params = {})
|
32
|
+
response = call("order/#{order_id}/tasks/#{task_id}", params, 'put')
|
33
|
+
JSON.parse(response.body)
|
34
|
+
end
|
35
|
+
|
36
|
+
def task_with_order(task_id, customer_id=false)
|
37
|
+
task = task_client.get_task(task_id)
|
38
|
+
order = get_order(task['orderid'].to_i)
|
39
|
+
if customer_id
|
40
|
+
if order['customer'].to_i != customer_id.to_i
|
41
|
+
raise 'Customer does not match'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
task['order'] = order
|
45
|
+
task
|
46
|
+
end
|
47
|
+
|
48
|
+
def count_orders(options = {})
|
49
|
+
options[:count] = true
|
50
|
+
response = call('order', options, 'get')
|
51
|
+
|
52
|
+
json = JSON.parse(response.body)
|
53
|
+
return json unless json.key?('count')
|
54
|
+
json['count'].to_i
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_products(order_id)
|
58
|
+
response = call("order/#{order_id}/products")
|
59
|
+
JSON.parse(response.body)
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_services(order_id)
|
63
|
+
response = call("order/#{order_id}/services")
|
64
|
+
JSON.parse(response.body)
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def task_client
|
70
|
+
@task_client ||= TaskClient.new(@api_key)
|
71
|
+
@task_client
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'voicearchive/client'
|
2
|
+
module Voicearchive
|
3
|
+
class SupplierClient < Client
|
4
|
+
def get_supplier_search_options
|
5
|
+
response = call('supplier/form-schema')
|
6
|
+
JSON.parse(response.body)
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_supplier_languages
|
10
|
+
response = call('supplier/languages')
|
11
|
+
JSON.parse(response.body)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_suppliers
|
15
|
+
response = call('supplier', {:includeRelations=>1})
|
16
|
+
JSON.parse(response.body)
|
17
|
+
end
|
18
|
+
|
19
|
+
def search_suppliers(params)
|
20
|
+
params[:includeRelations] = 1
|
21
|
+
response = call('supplier', params)
|
22
|
+
JSON.parse(response.body)
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_supplier_demo_types()
|
26
|
+
params = set_simple_endpoint_default_values({})
|
27
|
+
response = call('supplierpromotype', params)
|
28
|
+
JSON.parse(response.body)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'voicearchive/client'
|
2
|
+
module Voicearchive
|
3
|
+
class TaskClient < Client
|
4
|
+
def set_supplier_on_task(task_id, supplier_id)
|
5
|
+
response = call("task/#{task_id}/SetSupplier", {:supplierId=>supplier_id}, 'put')
|
6
|
+
JSON.parse(response.body)
|
7
|
+
end
|
8
|
+
|
9
|
+
def set_task_data(task_id, supplier_id, comments, script)
|
10
|
+
response = call("task/#{task_id}/SetTaskData", {:supplierId=>supplier_id, :comments=>comments, :script=>script}, 'put')
|
11
|
+
JSON.parse(response.body)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_retake(task_id, reason_id, params = {})
|
15
|
+
response = call("task/#{task_id}/create-retake", params.merge({
|
16
|
+
reasonId: reason_id
|
17
|
+
}), 'put');
|
18
|
+
|
19
|
+
JSON.parse(response.body)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_task(task_id)
|
23
|
+
response = call("ordertask/#{task_id}")
|
24
|
+
JSON.parse(response.body)
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_tasks(search_options, options)
|
28
|
+
response = call('ordertask', options.merge({
|
29
|
+
search: search_options,
|
30
|
+
}), 'get')
|
31
|
+
|
32
|
+
JSON.parse(response.body)
|
33
|
+
end
|
34
|
+
|
35
|
+
def search_tasks(search_options, options)
|
36
|
+
response = call('ordertask/search', options.merge({
|
37
|
+
search: search_options,
|
38
|
+
}), 'post')
|
39
|
+
|
40
|
+
JSON.parse(response.body)
|
41
|
+
end
|
42
|
+
|
43
|
+
def count_tasks(options = {})
|
44
|
+
options[:count] = true
|
45
|
+
response = call("task", options, 'get')
|
46
|
+
|
47
|
+
JSON.parse(response.body)["count"].to_i
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|