amdapi 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 +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +10 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +92 -0
- data/LICENSE.txt +21 -0
- data/README.md +97 -0
- data/Rakefile +12 -0
- data/amdapi.gemspec +42 -0
- data/bin/console +17 -0
- data/bin/setup +8 -0
- data/lib/amdapi/client.rb +73 -0
- data/lib/amdapi/collection.rb +23 -0
- data/lib/amdapi/error.rb +23 -0
- data/lib/amdapi/object.rb +20 -0
- data/lib/amdapi/objects/call.rb +19 -0
- data/lib/amdapi/resource.rb +48 -0
- data/lib/amdapi/resources/delete_call.rb +25 -0
- data/lib/amdapi/resources/get_call.rb +31 -0
- data/lib/amdapi/resources/post_call.rb +31 -0
- data/lib/amdapi/validation.rb +33 -0
- data/lib/amdapi/version.rb +5 -0
- data/lib/amdapi.rb +20 -0
- metadata +138 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 252c0c7d2629267ff18319cff6a043df535b4c60b6883ad0d449436111540768
|
|
4
|
+
data.tar.gz: d7f8451a47e9464c82b30f7cc3cec4954571c49e398ec95a4c45e6e0e7fe1d38
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3e8dd22f689de82a1f04137784f66ace7c011e975698cbf6272b5613c88630ac8630c4a9b89a8f689381f7f563cdcfaecb2c67b9c74bba37ced9055288291da0
|
|
7
|
+
data.tar.gz: 9a8575f1cac0cadcd14e69eaaefa00d74ecee591ebe9c59fdefaf704068fb85d18cf50ff16d87c836a1c533da6074fc954e7d0eb555271d7f36cda4b7a30154d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
amdapi (0.1.0)
|
|
5
|
+
faraday
|
|
6
|
+
faraday_middleware
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
ast (2.4.2)
|
|
12
|
+
coderay (1.1.3)
|
|
13
|
+
diff-lcs (1.5.0)
|
|
14
|
+
dotenv (2.7.6)
|
|
15
|
+
faraday (1.10.0)
|
|
16
|
+
faraday-em_http (~> 1.0)
|
|
17
|
+
faraday-em_synchrony (~> 1.0)
|
|
18
|
+
faraday-excon (~> 1.1)
|
|
19
|
+
faraday-httpclient (~> 1.0)
|
|
20
|
+
faraday-multipart (~> 1.0)
|
|
21
|
+
faraday-net_http (~> 1.0)
|
|
22
|
+
faraday-net_http_persistent (~> 1.0)
|
|
23
|
+
faraday-patron (~> 1.0)
|
|
24
|
+
faraday-rack (~> 1.0)
|
|
25
|
+
faraday-retry (~> 1.0)
|
|
26
|
+
ruby2_keywords (>= 0.0.4)
|
|
27
|
+
faraday-em_http (1.0.0)
|
|
28
|
+
faraday-em_synchrony (1.0.0)
|
|
29
|
+
faraday-excon (1.1.0)
|
|
30
|
+
faraday-httpclient (1.0.1)
|
|
31
|
+
faraday-multipart (1.0.3)
|
|
32
|
+
multipart-post (>= 1.2, < 3)
|
|
33
|
+
faraday-net_http (1.0.1)
|
|
34
|
+
faraday-net_http_persistent (1.2.0)
|
|
35
|
+
faraday-patron (1.0.0)
|
|
36
|
+
faraday-rack (1.0.0)
|
|
37
|
+
faraday-retry (1.0.3)
|
|
38
|
+
faraday_middleware (1.2.0)
|
|
39
|
+
faraday (~> 1.0)
|
|
40
|
+
method_source (1.0.0)
|
|
41
|
+
multipart-post (2.1.1)
|
|
42
|
+
parallel (1.21.0)
|
|
43
|
+
parser (3.1.1.0)
|
|
44
|
+
ast (~> 2.4.1)
|
|
45
|
+
pry (0.14.1)
|
|
46
|
+
coderay (~> 1.1)
|
|
47
|
+
method_source (~> 1.0)
|
|
48
|
+
rainbow (3.1.1)
|
|
49
|
+
rake (13.0.6)
|
|
50
|
+
regexp_parser (2.2.1)
|
|
51
|
+
rexml (3.2.5)
|
|
52
|
+
rspec (3.11.0)
|
|
53
|
+
rspec-core (~> 3.11.0)
|
|
54
|
+
rspec-expectations (~> 3.11.0)
|
|
55
|
+
rspec-mocks (~> 3.11.0)
|
|
56
|
+
rspec-core (3.11.0)
|
|
57
|
+
rspec-support (~> 3.11.0)
|
|
58
|
+
rspec-expectations (3.11.0)
|
|
59
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
60
|
+
rspec-support (~> 3.11.0)
|
|
61
|
+
rspec-mocks (3.11.0)
|
|
62
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
63
|
+
rspec-support (~> 3.11.0)
|
|
64
|
+
rspec-support (3.11.0)
|
|
65
|
+
rubocop (0.93.1)
|
|
66
|
+
parallel (~> 1.10)
|
|
67
|
+
parser (>= 2.7.1.5)
|
|
68
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
69
|
+
regexp_parser (>= 1.8)
|
|
70
|
+
rexml
|
|
71
|
+
rubocop-ast (>= 0.6.0)
|
|
72
|
+
ruby-progressbar (~> 1.7)
|
|
73
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
|
74
|
+
rubocop-ast (1.16.0)
|
|
75
|
+
parser (>= 3.1.1.0)
|
|
76
|
+
ruby-progressbar (1.11.0)
|
|
77
|
+
ruby2_keywords (0.0.5)
|
|
78
|
+
unicode-display_width (1.8.0)
|
|
79
|
+
|
|
80
|
+
PLATFORMS
|
|
81
|
+
x86_64-linux
|
|
82
|
+
|
|
83
|
+
DEPENDENCIES
|
|
84
|
+
amdapi!
|
|
85
|
+
dotenv
|
|
86
|
+
pry
|
|
87
|
+
rake (~> 13.0)
|
|
88
|
+
rspec (~> 3.0)
|
|
89
|
+
rubocop (~> 0.80)
|
|
90
|
+
|
|
91
|
+
BUNDLED WITH
|
|
92
|
+
2.2.3
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Martfed
|
|
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,97 @@
|
|
|
1
|
+
# Amdapi
|
|
2
|
+
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/amdapi`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'amdapi'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle install
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install amdapi
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
## initialize the Amdapi client
|
|
27
|
+
client = Amdapi::Client.new(client_id: ENV["client_id"], client_secret: ENV["client_secret"])
|
|
28
|
+
|
|
29
|
+
## GET one call
|
|
30
|
+
client.find(call_uuid)
|
|
31
|
+
|
|
32
|
+
## GET a batch of calls
|
|
33
|
+
client.all(params: search_params_hash) # based on the filters you have provided
|
|
34
|
+
client.all # will get the first page of the calls linked to your entreprise
|
|
35
|
+
|
|
36
|
+
## Analize a call (create the call info in our DB + analyse asyncronously the audio)
|
|
37
|
+
client.analize(params: call_params_hash, file: audio_file)
|
|
38
|
+
|
|
39
|
+
## Delete a specific audio (this includes delete the call in our Database + the audio)
|
|
40
|
+
client.delete(call_uuid)
|
|
41
|
+
```
|
|
42
|
+
### Search params
|
|
43
|
+
| key | description | format |
|
|
44
|
+
| --- | ----------- | ------ |
|
|
45
|
+
| **client_id** | look for calls that only belong to a specific `client` | integer |
|
|
46
|
+
| **agent_id** | look for calls that only belong to a specific `agent` | integer |
|
|
47
|
+
| **customer_id** | look for calls that only belong to a specific `customer` | integer |
|
|
48
|
+
| **start_date** | ook for all calls that have been made from start_date until the current date unless end_date is provided | DD/MM/YYYY |
|
|
49
|
+
| **end_date** | look for all the calls that have been made from start_date until end_date | DD/MM/YYYY |
|
|
50
|
+
|
|
51
|
+
```JSON
|
|
52
|
+
{
|
|
53
|
+
"agent_id": 42,
|
|
54
|
+
"client_id": 420,
|
|
55
|
+
"customer_id": 152,
|
|
56
|
+
"start_date": "24/01/2021",
|
|
57
|
+
"end_date": "04/05/2021"
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Call params
|
|
62
|
+
| key | description | format |
|
|
63
|
+
| --- | ----------- | ------ |
|
|
64
|
+
| **company_name** | The name of your company | string |
|
|
65
|
+
| **call_id** | The ID of the call from your DB | string |
|
|
66
|
+
| **client_id** | The ID of your client. The one that operates the contact center | integer |
|
|
67
|
+
| **agent_id** | The ID of the agent that operates the call. Value from your DB | integer |
|
|
68
|
+
| **customer_id** | The ID of the customer that makes/receives the call. Value from your DB | integer |
|
|
69
|
+
| **origin** | Was the call Inbound -or- Outbound? | string |
|
|
70
|
+
| **language** | ISO code of the language used in the call. Values currently available: en - en-in - fr | string |
|
|
71
|
+
| **summary** | Generates an automatic summary of the conversation if the value is true | boolean |
|
|
72
|
+
| **filename** | The name of the call recording file | string |
|
|
73
|
+
|
|
74
|
+
```JSON
|
|
75
|
+
{
|
|
76
|
+
"company_name": "your_company_name",
|
|
77
|
+
"call_id": 273,
|
|
78
|
+
"client_id": 412,
|
|
79
|
+
"agent_id": 42,
|
|
80
|
+
"customer_id": 140,
|
|
81
|
+
"origin": "Inbound",
|
|
82
|
+
"language": "en-in",
|
|
83
|
+
"summary": true,
|
|
84
|
+
"filename": "name_of_the_audio_file"
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### File
|
|
89
|
+
The file can be sent the following way. Needs to be a .wav format
|
|
90
|
+
|
|
91
|
+
```ruby
|
|
92
|
+
file = File.read('[path to the audio file]')
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/amdapi.gemspec
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/amdapi/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "amdapi"
|
|
7
|
+
spec.version = Amdapi::VERSION
|
|
8
|
+
spec.authors = ["Martfed"]
|
|
9
|
+
spec.email = ["federico@amdapi.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "API wrapper for amdapi api"
|
|
12
|
+
spec.description = "API wrapper for amdapi api"
|
|
13
|
+
spec.homepage = "https://www.amdapi.com/"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
|
16
|
+
|
|
17
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
|
18
|
+
|
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/AMDA-pi/amda-pi-api-gem"
|
|
21
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
|
22
|
+
|
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
|
27
|
+
end
|
|
28
|
+
spec.bindir = "exe"
|
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
30
|
+
spec.require_paths = ["lib"]
|
|
31
|
+
|
|
32
|
+
# Uncomment to register a new dependency of your gem
|
|
33
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
|
34
|
+
|
|
35
|
+
# For more information and examples about making a new gem, checkout our
|
|
36
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
37
|
+
spec.add_dependency "faraday"
|
|
38
|
+
spec.add_dependency "faraday_middleware"
|
|
39
|
+
spec.add_development_dependency "rspec"
|
|
40
|
+
spec.add_development_dependency "pry"
|
|
41
|
+
spec.add_development_dependency "dotenv"
|
|
42
|
+
end
|
data/bin/console
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "amdapi"
|
|
6
|
+
require "dotenv/load"
|
|
7
|
+
|
|
8
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
9
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
10
|
+
|
|
11
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
12
|
+
# require "pry"
|
|
13
|
+
# Pry.start
|
|
14
|
+
|
|
15
|
+
client = Amdapi::Client.new(client_id: ENV["client_id"], client_secret: ENV["client_secret"])
|
|
16
|
+
require "irb"
|
|
17
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "faraday"
|
|
4
|
+
require "faraday_middleware"
|
|
5
|
+
require "base64"
|
|
6
|
+
require "json"
|
|
7
|
+
|
|
8
|
+
module Amdapi
|
|
9
|
+
class Client
|
|
10
|
+
BASE_URL = "https://auth.api-amdapi.com"
|
|
11
|
+
attr_reader :client_id, :client_secret, :token, :adapter
|
|
12
|
+
|
|
13
|
+
def initialize(client_id:, client_secret:, adapter: Faraday.default_adapter, stubs: nil)
|
|
14
|
+
@client_id = client_id
|
|
15
|
+
@client_secret = client_secret
|
|
16
|
+
@adapter = adapter
|
|
17
|
+
@stubs = stubs
|
|
18
|
+
@token = generate_token
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def generate_new_token
|
|
22
|
+
@token = generate_token
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def inspect
|
|
26
|
+
"#<Amdapi::Client>"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def find(call_uuid)
|
|
30
|
+
GetCall.new(call_uuid, token, adapter, @stubs).find
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def all(params: {})
|
|
34
|
+
GetCall.new(token, adapter, @stubs).all(params)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def analize(params:, file:)
|
|
38
|
+
raise ParamsError unless ParamsValidator.new(params).valid?
|
|
39
|
+
|
|
40
|
+
PostCall.new(token, params, file, adapter, @stubs).create
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def delete(call_uuid)
|
|
44
|
+
DeleteCall.new(token, call_uuid, adapter, @stubs).delete
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
def generate_token
|
|
50
|
+
response = connection.post("/oauth2/token") do |req|
|
|
51
|
+
req.headers = headers
|
|
52
|
+
req.params["grant_type"] = "client_credentials"
|
|
53
|
+
end
|
|
54
|
+
token = JSON.parse(response.body)["access_token"]
|
|
55
|
+
raise TokenError if token.nil?
|
|
56
|
+
|
|
57
|
+
token
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def connection
|
|
61
|
+
@connection ||= Faraday.new do |conn|
|
|
62
|
+
conn.url_prefix = BASE_URL
|
|
63
|
+
conn.adapter adapter, @stubs
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def headers
|
|
68
|
+
string = "#{client_id}:#{client_secret}"
|
|
69
|
+
base64_encoded = Base64.encode64(string)
|
|
70
|
+
{ "Authorization" => "Basic #{base64_encoded}".gsub("\n", ""), "Content-Type": "application/x-www-form-urlencoded" }
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Amdapi
|
|
4
|
+
class Collection
|
|
5
|
+
attr_reader :data, :current_page, :next_page, :is_last_page
|
|
6
|
+
|
|
7
|
+
def self.from_response(response, key: "calls", type: Call)
|
|
8
|
+
new(
|
|
9
|
+
data: response[key].map { |attrs| type.new(attrs, call_uuid: attrs["call_uuid"]) },
|
|
10
|
+
current_page: response["current_page"],
|
|
11
|
+
next_page: response["next_page"],
|
|
12
|
+
is_last_page: response["is_last_page"]
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def initialize(data:, current_page:, next_page:, is_last_page:)
|
|
17
|
+
@current_page = current_page
|
|
18
|
+
@next_page = next_page
|
|
19
|
+
@is_last_page = is_last_page
|
|
20
|
+
@data = data
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/amdapi/error.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Amdapi
|
|
4
|
+
class Error < StandardError; end
|
|
5
|
+
|
|
6
|
+
class TokenError < StandardError
|
|
7
|
+
def initialize(msg = "wrong credentials")
|
|
8
|
+
super
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class ParamsError < StandardError
|
|
13
|
+
def initialize(msg = "Malformed Params")
|
|
14
|
+
super
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class CallNotFoundError < StandardError
|
|
19
|
+
def initialize(msg = "Call not found")
|
|
20
|
+
super
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "ostruct"
|
|
4
|
+
|
|
5
|
+
module Amdapi
|
|
6
|
+
class Object
|
|
7
|
+
def initialize(attr)
|
|
8
|
+
@attributes = OpenStruct.new(attr)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def method_missing(method, *args, &block)
|
|
12
|
+
attribute = @attributes.send(method, *args, &block)
|
|
13
|
+
attribute.is_a?(Hash) ? Object.new(attribute) : attribute
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def respond_to_missing?(method, include_private = false)
|
|
17
|
+
true
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Amdapi
|
|
4
|
+
class Call < Object
|
|
5
|
+
attr_reader :call_uuid
|
|
6
|
+
|
|
7
|
+
def initialize(attr = {}, call_uuid: "", token: "")
|
|
8
|
+
super(attr)
|
|
9
|
+
@call_uuid = call_uuid
|
|
10
|
+
@token = token
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def refetch(adapter: Faraday.default_adapter, stubs: nil)
|
|
14
|
+
response = GetCall.new(call_uuid, @token, adapter, stubs).find
|
|
15
|
+
@attributes = OpenStruct.new(response)
|
|
16
|
+
true
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Amdapi
|
|
4
|
+
class Resource
|
|
5
|
+
BASE_URL = "https://api-amdapi.com"
|
|
6
|
+
|
|
7
|
+
def initialize(token, adapter: Faraday.default_adapter, stubs: nil)
|
|
8
|
+
@token = token
|
|
9
|
+
@adapter = adapter
|
|
10
|
+
@stubs = stubs
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def get_request(call_uuid = nil, params: {}, headers: {})
|
|
14
|
+
connection.get("v1/calls/#{call_uuid}", params, default_headers.merge(headers))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def get_all_request(params: {}, headers: {})
|
|
18
|
+
connection.get("v1/calls", params, default_headers.merge(headers))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def post_call_request(params, headers: {})
|
|
22
|
+
connection.post("amda-pi-storage", params.to_json, default_headers.merge(headers))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def post_audio_request(url, file, headers: {})
|
|
26
|
+
connection.put(url, file, headers)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def delete_call(call_uuid, params: {}, headers: {})
|
|
30
|
+
connection.delete("v1/calls/#{call_uuid}", params, default_headers.merge(headers))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
attr_reader :token, :adapter
|
|
36
|
+
|
|
37
|
+
def connection
|
|
38
|
+
@connection ||= Faraday.new do |conn|
|
|
39
|
+
conn.url_prefix = BASE_URL
|
|
40
|
+
conn.adapter adapter, @stubs
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def default_headers
|
|
45
|
+
{ "Authorization" => "Bearer #{token}" }
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Amdapi
|
|
4
|
+
class DeleteCall < Resource
|
|
5
|
+
attr_reader :call_uuid
|
|
6
|
+
|
|
7
|
+
def initialize(token, call_uuid, adapter, stubs)
|
|
8
|
+
super(token, adapter: adapter, stubs: stubs)
|
|
9
|
+
@call_uuid = call_uuid
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def delete
|
|
13
|
+
response = delete_call(call_uuid, headers: headers)
|
|
14
|
+
raise CallNotFoundError if response.status == 404
|
|
15
|
+
|
|
16
|
+
JSON.parse(response.body)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def headers
|
|
22
|
+
{ "Content-Type": "application/json" }
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Amdapi
|
|
4
|
+
class GetCall < Resource
|
|
5
|
+
attr_reader :call_uuid
|
|
6
|
+
|
|
7
|
+
def initialize(call_uuid = "", token, adapter, stubs)
|
|
8
|
+
@call_uuid = call_uuid
|
|
9
|
+
super(token, adapter: adapter, stubs: stubs)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def find
|
|
13
|
+
response = get_request(call_uuid, headers: headers)
|
|
14
|
+
raise CallNotFoundError if response.status == 404
|
|
15
|
+
|
|
16
|
+
data = JSON.parse(response.body)["data"]
|
|
17
|
+
Call.new data, call_uuid: data["call_uuid"], token: token
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def all(params = {})
|
|
21
|
+
response = get_all_request(params: params, headers: headers)
|
|
22
|
+
Collection.from_response JSON.parse(response.body)["data"]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def headers
|
|
28
|
+
{ "Content-Type": "application/json" }
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Amdapi
|
|
4
|
+
class PostCall < Resource
|
|
5
|
+
attr_reader :params, :file, :token
|
|
6
|
+
|
|
7
|
+
def initialize(token, params, file, adapter, stubs)
|
|
8
|
+
super(token, adapter: adapter, stubs: stubs)
|
|
9
|
+
@params = params
|
|
10
|
+
@file = file
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def create
|
|
14
|
+
response = JSON.parse(post_call_request(params, headers: call_headers).body)
|
|
15
|
+
call_url = response["data"]["url"]
|
|
16
|
+
call_uuid = response["data"]["call_uuid"]
|
|
17
|
+
post_audio_request(call_url, file, headers: audio_headers)
|
|
18
|
+
Call.new call_uuid: call_uuid, token: token
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def call_headers
|
|
24
|
+
{ "Content-Type": "application/json" }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def audio_headers
|
|
28
|
+
{ "Content-Type": "audio/wav", "x-amz-acl": "public-read" }
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Amdapi
|
|
2
|
+
class ParamsValidator
|
|
3
|
+
def initialize(params)
|
|
4
|
+
@params = params
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def valid?
|
|
8
|
+
symbolize_keys
|
|
9
|
+
params_keys.all? { |key| params[key] }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
attr_reader :params
|
|
15
|
+
|
|
16
|
+
def symbolize_keys
|
|
17
|
+
params.keys.each do |key|
|
|
18
|
+
params[(key.to_sym rescue key) || key] = params.delete(key)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def params_keys
|
|
23
|
+
%i[agent_id
|
|
24
|
+
client_id
|
|
25
|
+
customer_id
|
|
26
|
+
origin
|
|
27
|
+
language
|
|
28
|
+
call_id
|
|
29
|
+
filename
|
|
30
|
+
company_name]
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
data/lib/amdapi.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "amdapi/version"
|
|
4
|
+
|
|
5
|
+
module Amdapi
|
|
6
|
+
autoload :Client, "amdapi/client"
|
|
7
|
+
autoload :Error, "amdapi/error"
|
|
8
|
+
autoload :TokenError, "amdapi/error"
|
|
9
|
+
autoload :ParamsError, "amdapi/error"
|
|
10
|
+
autoload :CallNotFoundError, "amdapi/error"
|
|
11
|
+
|
|
12
|
+
autoload :Collection, "amdapi/collection"
|
|
13
|
+
autoload :Object, "amdapi/object"
|
|
14
|
+
autoload :Call, "amdapi/objects/call"
|
|
15
|
+
autoload :Resource, "amdapi/resource"
|
|
16
|
+
autoload :GetCall, "amdapi/resources/get_call"
|
|
17
|
+
autoload :PostCall, "amdapi/resources/post_call"
|
|
18
|
+
autoload :DeleteCall, "amdapi/resources/delete_call"
|
|
19
|
+
autoload :ParamsValidator, "amdapi/validation"
|
|
20
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: amdapi
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Martfed
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2022-03-26 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: faraday
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: faraday_middleware
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
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: pry
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: dotenv
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
description: API wrapper for amdapi api
|
|
84
|
+
email:
|
|
85
|
+
- federico@amdapi.com
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- ".gitignore"
|
|
91
|
+
- ".rspec"
|
|
92
|
+
- ".rubocop.yml"
|
|
93
|
+
- Gemfile
|
|
94
|
+
- Gemfile.lock
|
|
95
|
+
- LICENSE.txt
|
|
96
|
+
- README.md
|
|
97
|
+
- Rakefile
|
|
98
|
+
- amdapi.gemspec
|
|
99
|
+
- bin/console
|
|
100
|
+
- bin/setup
|
|
101
|
+
- lib/amdapi.rb
|
|
102
|
+
- lib/amdapi/client.rb
|
|
103
|
+
- lib/amdapi/collection.rb
|
|
104
|
+
- lib/amdapi/error.rb
|
|
105
|
+
- lib/amdapi/object.rb
|
|
106
|
+
- lib/amdapi/objects/call.rb
|
|
107
|
+
- lib/amdapi/resource.rb
|
|
108
|
+
- lib/amdapi/resources/delete_call.rb
|
|
109
|
+
- lib/amdapi/resources/get_call.rb
|
|
110
|
+
- lib/amdapi/resources/post_call.rb
|
|
111
|
+
- lib/amdapi/validation.rb
|
|
112
|
+
- lib/amdapi/version.rb
|
|
113
|
+
homepage: https://www.amdapi.com/
|
|
114
|
+
licenses:
|
|
115
|
+
- MIT
|
|
116
|
+
metadata:
|
|
117
|
+
homepage_uri: https://www.amdapi.com/
|
|
118
|
+
source_code_uri: https://github.com/AMDA-pi/amda-pi-api-gem
|
|
119
|
+
post_install_message:
|
|
120
|
+
rdoc_options: []
|
|
121
|
+
require_paths:
|
|
122
|
+
- lib
|
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
|
+
requirements:
|
|
125
|
+
- - ">="
|
|
126
|
+
- !ruby/object:Gem::Version
|
|
127
|
+
version: 2.3.0
|
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
|
+
requirements:
|
|
130
|
+
- - ">="
|
|
131
|
+
- !ruby/object:Gem::Version
|
|
132
|
+
version: '0'
|
|
133
|
+
requirements: []
|
|
134
|
+
rubygems_version: 3.3.10
|
|
135
|
+
signing_key:
|
|
136
|
+
specification_version: 4
|
|
137
|
+
summary: API wrapper for amdapi api
|
|
138
|
+
test_files: []
|