gpdb_client 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +68 -0
- data/LICENSE.txt +21 -0
- data/README.md +182 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gpdb_client.gemspec +34 -0
- data/lib/gpdb.rb +9 -0
- data/lib/gpdb/configuration.rb +23 -0
- data/lib/gpdb/credentials.rb +27 -0
- data/lib/gpdb/http_client.rb +41 -0
- data/lib/gpdb/model.rb +13 -0
- data/lib/gpdb/rest/base_resource.rb +13 -0
- data/lib/gpdb/rest/client.rb +27 -0
- data/lib/gpdb/rest/pronunciation/model.rb +30 -0
- data/lib/gpdb/rest/pronunciation/resource.rb +73 -0
- data/lib/gpdb/rest/pronunciation/response.rb +17 -0
- data/lib/gpdb/rest/pronunciation/target.rb +23 -0
- data/lib/gpdb/rest/pronunciation/target_list_response.rb +20 -0
- data/lib/gpdb/rest/pronunciation/target_response.rb +20 -0
- data/lib/gpdb/rest/recording_request/model.rb +21 -0
- data/lib/gpdb/rest/recording_request/resource.rb +33 -0
- data/lib/gpdb/rest/recording_request/response.rb +17 -0
- data/lib/gpdb/rest/request.rb +13 -0
- data/lib/gpdb/rest/response.rb +33 -0
- data/lib/gpdb/version.rb +5 -0
- data/lib/gpdb_client.rb +28 -0
- metadata +170 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f8c0ce46227d9f72cfc83cf8b9a352f9a5bb1287a9ec4cabe89840dad444b498
|
4
|
+
data.tar.gz: 33dd7334bae03b1251053eb1e95dc5af4c455d07a5f64379e62e7fa205c76492
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fbdbe1dff6ccf3677260e0256eb64ae0388125f3ab6022c6f689d4e44d4dd51bd66467a057cfd87de8532a62b52b2be7e27377f5882b5a973ea61ae7b0662134
|
7
|
+
data.tar.gz: aaaf2a283bfc9e173c9d7f1a8fa9aa2590b22716f5d8602ceaf370f213c12cc9bd6905c09f1d5745bb6bee0ce7dfca92d9d1bdcf546a9a9ac39ae12f77262a68
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gpdb_client (0.1)
|
5
|
+
activesupport
|
6
|
+
faraday
|
7
|
+
jwt
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (6.0.3.4)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (>= 0.7, < 2)
|
15
|
+
minitest (~> 5.1)
|
16
|
+
tzinfo (~> 1.1)
|
17
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
18
|
+
addressable (2.7.0)
|
19
|
+
public_suffix (>= 2.0.2, < 5.0)
|
20
|
+
concurrent-ruby (1.1.7)
|
21
|
+
crack (0.4.4)
|
22
|
+
diff-lcs (1.4.4)
|
23
|
+
faraday (1.1.0)
|
24
|
+
multipart-post (>= 1.2, < 3)
|
25
|
+
ruby2_keywords
|
26
|
+
hashdiff (1.0.1)
|
27
|
+
i18n (1.8.5)
|
28
|
+
concurrent-ruby (~> 1.0)
|
29
|
+
jwt (2.2.2)
|
30
|
+
minitest (5.14.2)
|
31
|
+
multipart-post (2.1.1)
|
32
|
+
public_suffix (4.0.6)
|
33
|
+
rake (10.5.0)
|
34
|
+
rspec (3.10.0)
|
35
|
+
rspec-core (~> 3.10.0)
|
36
|
+
rspec-expectations (~> 3.10.0)
|
37
|
+
rspec-mocks (~> 3.10.0)
|
38
|
+
rspec-core (3.10.0)
|
39
|
+
rspec-support (~> 3.10.0)
|
40
|
+
rspec-expectations (3.10.0)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.10.0)
|
43
|
+
rspec-mocks (3.10.0)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.10.0)
|
46
|
+
rspec-support (3.10.0)
|
47
|
+
ruby2_keywords (0.0.2)
|
48
|
+
thread_safe (0.3.6)
|
49
|
+
tzinfo (1.2.7)
|
50
|
+
thread_safe (~> 0.1)
|
51
|
+
webmock (3.9.3)
|
52
|
+
addressable (>= 2.3.6)
|
53
|
+
crack (>= 0.3.2)
|
54
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
55
|
+
zeitwerk (2.4.1)
|
56
|
+
|
57
|
+
PLATFORMS
|
58
|
+
ruby
|
59
|
+
|
60
|
+
DEPENDENCIES
|
61
|
+
bundler (~> 2.1.4)
|
62
|
+
gpdb_client!
|
63
|
+
rake (~> 10.0)
|
64
|
+
rspec (~> 3.0)
|
65
|
+
webmock (~> 3.9.2)
|
66
|
+
|
67
|
+
BUNDLED WITH
|
68
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 alexander.yundin
|
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,182 @@
|
|
1
|
+
# Gpdb Client
|
2
|
+
|
3
|
+
The gem is a simple wrapper around NameCoach GPDB (General Pronunciation Database) API.
|
4
|
+
It is useful to external developers who wish to add NameCoach services to an application.
|
5
|
+
|
6
|
+
For more information on NameCoach GPDB APi, you can visit [documentation page](https://namecoachgpdb.docs.apiary.io/#).
|
7
|
+
|
8
|
+
- [Installation](#installation)
|
9
|
+
- [Usage](#usage)
|
10
|
+
- [API](#api)
|
11
|
+
- [Pronunciations](#pronunciations)
|
12
|
+
- [Simple search](#simple-search)
|
13
|
+
- [Complex search](#complex-search)
|
14
|
+
- [Create](#create-a-pronunciation)
|
15
|
+
- [Recording requests](#recording-request)
|
16
|
+
- [Create](#create-recording-request)
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'gpdb_client'
|
24
|
+
```
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
$ bundle
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
$ gem install gpdb_client
|
33
|
+
|
34
|
+
#### Required ENV variables:
|
35
|
+
|
36
|
+
`GPDB_API_URL`
|
37
|
+
|
38
|
+
`GPDB_NAMESPACE` - specifies the API version (e.g. `'/api/public/v1'`)
|
39
|
+
|
40
|
+
`GPDB_ACCESS_KEY_ID`, `GPDB_SECRET_ACCESS_KEY` -
|
41
|
+
During your API onboarding with NameCoach, you will be given these values
|
42
|
+
|
43
|
+
## Usage
|
44
|
+
|
45
|
+
You need to create a client instance to perform requests. Basic example:
|
46
|
+
|
47
|
+
gpdb_client = Gpdb::REST::Client.new
|
48
|
+
|
49
|
+
result = gpdb_client.pronunciations.simple_search(target: 'Alex', app_sig: 'app_sig', app_type: 'app_type')
|
50
|
+
|
51
|
+
# Each response has common methods:
|
52
|
+
result.success? # => true
|
53
|
+
result.status # => 200
|
54
|
+
|
55
|
+
# As well as specific response attributes
|
56
|
+
result.target # => Gpdb::REST::Pronunciation::Target instance
|
57
|
+
|
58
|
+
|
59
|
+
The client instance contains two resources: `pronunciations` and `recording_requests`.
|
60
|
+
Each resource has its own unique methods which are described below.
|
61
|
+
|
62
|
+
You can find detailed information about all possible parameters and the response format
|
63
|
+
on the [documentation page](https://namecoachgpdb.docs.apiary.io/#).
|
64
|
+
Links to the specific methods are placed at the end of each paragraph.
|
65
|
+
|
66
|
+
## API
|
67
|
+
|
68
|
+
### Pronunciations
|
69
|
+
|
70
|
+
#### Simple search
|
71
|
+
|
72
|
+
Quick / simple request to get pronunciation for a single target.
|
73
|
+
|
74
|
+
result = gpdb_client.pronunciations.simple_search(
|
75
|
+
target: 'Alex',
|
76
|
+
app_sig: 'app_sig',
|
77
|
+
app_type: 'app_type'
|
78
|
+
)
|
79
|
+
|
80
|
+
result.meta
|
81
|
+
# => Name Parser and Recommendation Model version info
|
82
|
+
|
83
|
+
result.target
|
84
|
+
# => Gpdb::REST::Pronunciation::Target instance that contains target attributes
|
85
|
+
|
86
|
+
pronunciations = result.target.pronunciations
|
87
|
+
# => an array of Gpdb::REST::Pronunciation::Model instances
|
88
|
+
|
89
|
+
pronunciations.first.audio_url
|
90
|
+
# => a link to an audio
|
91
|
+
|
92
|
+
[Simple search documentation](https://namecoachgpdb.docs.apiary.io/#reference/pronunciations/simple-search/simple-search)
|
93
|
+
|
94
|
+
#### Complex search
|
95
|
+
|
96
|
+
Perform a search in GPDB given between 1 and 10 search targets.
|
97
|
+
|
98
|
+
result = gpdb_client.pronunciations.complex_search(
|
99
|
+
targets: [
|
100
|
+
{
|
101
|
+
target: "praveen",
|
102
|
+
target_type_sig: "person_first_name"
|
103
|
+
},
|
104
|
+
{
|
105
|
+
target: "rob",
|
106
|
+
target_type_sig: "person_first_name"
|
107
|
+
}
|
108
|
+
],
|
109
|
+
application_context: {
|
110
|
+
app_type_sig: "myCoolApp",
|
111
|
+
instance_sig: "anInstanceID"
|
112
|
+
}
|
113
|
+
)
|
114
|
+
|
115
|
+
result.target_results
|
116
|
+
# => an array of Gpdb::REST::Pronunciation::Target instances
|
117
|
+
|
118
|
+
result.meta
|
119
|
+
# => Name Parser and Recommendation Model version info
|
120
|
+
|
121
|
+
[Complex search documentation](https://namecoachgpdb.docs.apiary.io/#reference/pronunciations/complex-search/complex-search)
|
122
|
+
|
123
|
+
#### Create a pronunciation
|
124
|
+
|
125
|
+
In order to create recordings, you will need to provide audio data in the base64 format.
|
126
|
+
|
127
|
+
result = gpdb_client.pronunciations.create(
|
128
|
+
name: 'mary',
|
129
|
+
target_type_sig: 'person_first_name',
|
130
|
+
base64_audio: base64_audio_text,
|
131
|
+
application_context: {
|
132
|
+
app_type_sig: 'myCoolApp',
|
133
|
+
instance_sig: 'anInstanceID'
|
134
|
+
},
|
135
|
+
user_context: {
|
136
|
+
signature: 'u_sign'
|
137
|
+
},
|
138
|
+
name_owner_context: {
|
139
|
+
signature: 'u_name_own'
|
140
|
+
}
|
141
|
+
)
|
142
|
+
|
143
|
+
result.pronunciation
|
144
|
+
# => Gpdb::REST::Pronunciation::Model instance
|
145
|
+
|
146
|
+
result.errors # will contain errors if attrobutes you provided are not valid
|
147
|
+
# => { audio_data: "can't be blank" }
|
148
|
+
|
149
|
+
[Create a pronunciation documentation](https://namecoachgpdb.docs.apiary.io/#reference/pronunciations/create-a-pronunciation/create-a-pronunciation)
|
150
|
+
|
151
|
+
### Recording request
|
152
|
+
|
153
|
+
#### Create recording request
|
154
|
+
|
155
|
+
If we are missing a pronunciation needed for you, you can request it
|
156
|
+
|
157
|
+
result = gpdb_client.recording_requests.create(
|
158
|
+
target: 'franka',
|
159
|
+
target_type_sig: 'person_first_name',
|
160
|
+
target_owner_context: {
|
161
|
+
signature: 'sign'
|
162
|
+
},
|
163
|
+
user_context: {
|
164
|
+
signature: 'u_sign'
|
165
|
+
},
|
166
|
+
application_context: {
|
167
|
+
app_type_sig: 'myCoolApp',
|
168
|
+
instance_sig: 'anInstanceID'
|
169
|
+
}
|
170
|
+
)
|
171
|
+
|
172
|
+
result.recording_request
|
173
|
+
# Gpdb::REST::RecordingRequest::Model instance
|
174
|
+
|
175
|
+
result.errors # will contain errors if attributes you provided are not valid
|
176
|
+
# => { target: "can't be blank" }
|
177
|
+
|
178
|
+
[Recording request documentation](https://namecoachgpdb.docs.apiary.io/#reference/recording-requests/recording-requests/recording-requests)
|
179
|
+
|
180
|
+
## License
|
181
|
+
|
182
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gpdb_client"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/gpdb_client.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'gpdb/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'gpdb_client'
|
9
|
+
spec.version = GpdbClient::VERSION
|
10
|
+
spec.authors = ['NameCoachDevTeam']
|
11
|
+
spec.email = ['dev-team@name-coach.com']
|
12
|
+
|
13
|
+
spec.summary = %q{Summary}
|
14
|
+
spec.description = %q{Description}
|
15
|
+
spec.homepage = ''
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 2.1.4'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
spec.add_development_dependency 'webmock', '~> 3.9.2'
|
30
|
+
|
31
|
+
spec.add_dependency 'activesupport'
|
32
|
+
spec.add_dependency 'faraday'
|
33
|
+
spec.add_dependency 'jwt'
|
34
|
+
end
|
data/lib/gpdb.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gpdb
|
4
|
+
class Configuration
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
attr_accessor :namespace
|
8
|
+
attr_accessor :api_url
|
9
|
+
attr_accessor :access_key_id
|
10
|
+
attr_accessor :secret_access_key
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
self.api_url = ENV.fetch('GPDB_API_URL')
|
14
|
+
self.namespace = ENV.fetch('GPDB_NAMESPACE')
|
15
|
+
self.access_key_id = ENV.fetch('GPDB_ACCESS_KEY_ID')
|
16
|
+
self.secret_access_key = ENV.fetch('GPDB_SECRET_ACCESS_KEY')
|
17
|
+
end
|
18
|
+
|
19
|
+
def credentials
|
20
|
+
Credentials.new(access_key_id, secret_access_key)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gpdb
|
4
|
+
class Credentials
|
5
|
+
def initialize(access_key_id, secret_access_key)
|
6
|
+
@access_key_id = access_key_id
|
7
|
+
@secret_access_key = secret_access_key
|
8
|
+
end
|
9
|
+
|
10
|
+
def signature
|
11
|
+
::JWT.encode(
|
12
|
+
{ ts: Time.now.since(30.seconds).to_i * 1000 },
|
13
|
+
@secret_access_key,
|
14
|
+
'HS256',
|
15
|
+
{ access_key_id: @access_key_id }
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
def signature_header
|
20
|
+
"Bearer:#{signature}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def signature_url_encoded
|
24
|
+
{ signature: signature }.to_query
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gpdb
|
4
|
+
class HttpClient
|
5
|
+
class JsonParseMiddleware < ::Faraday::Response::Middleware
|
6
|
+
def on_complete(env)
|
7
|
+
env[:body] = JSON.parse(env[:body], symbolize_names: true) if env.parse_body?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class HeadersMiddleware < ::Faraday::Middleware
|
12
|
+
def call(env)
|
13
|
+
env[:request_headers]['Content-Type'] = if [:post, :put].include?(env.method)
|
14
|
+
'multipart/form-data'
|
15
|
+
else
|
16
|
+
'application/json'
|
17
|
+
end
|
18
|
+
|
19
|
+
env[:request_headers]['Accept'] = 'application/json'
|
20
|
+
env[:request_headers]['User-Agent'] = "gpdb-api-client/#{GpdbClient::VERSION}"
|
21
|
+
|
22
|
+
@app.call(env)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def request(request)
|
27
|
+
conn = Faraday.new(url: request.api_url) do |f|
|
28
|
+
f.headers = request.headers
|
29
|
+
f.use(HeadersMiddleware)
|
30
|
+
|
31
|
+
f.request(:multipart)
|
32
|
+
f.request(:url_encoded)
|
33
|
+
|
34
|
+
f.use(JsonParseMiddleware)
|
35
|
+
f.adapter(Faraday.default_adapter)
|
36
|
+
end
|
37
|
+
|
38
|
+
conn.public_send(request.method, request.path, request.params)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/gpdb/model.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gpdb
|
4
|
+
module REST
|
5
|
+
class Client
|
6
|
+
attr_accessor :http_client
|
7
|
+
attr_accessor :recording_requests, :pronunciations
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
self.http_client = HttpClient.new
|
11
|
+
|
12
|
+
self.recording_requests = Gpdb::REST::RecordingRequest::Resource.new(self)
|
13
|
+
self.pronunciations = Gpdb::REST::Pronunciation::Resource.new(self)
|
14
|
+
end
|
15
|
+
|
16
|
+
def request(request, namespace: Gpdb.configuration.namespace)
|
17
|
+
request.api_url = Gpdb.configuration.api_url
|
18
|
+
request.path = "#{namespace}#{request.path}"
|
19
|
+
request.headers = { 'Authorization': Gpdb.configuration.credentials.signature_header }
|
20
|
+
|
21
|
+
response = http_client.request(request)
|
22
|
+
|
23
|
+
Response.new(body: response.body, status: response.status, _response: response)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gpdb
|
4
|
+
module REST
|
5
|
+
module Pronunciation
|
6
|
+
class Model < ::Gpdb::Model
|
7
|
+
attr_accessor :id, :created_at, :updated_at, :audio_url, :allow_user_responses,
|
8
|
+
:language_metadata, :phonetic_transcriptions, :user_responses,
|
9
|
+
:audio_source, :audio_owner_signature, :name_owner_signature, :name_text
|
10
|
+
|
11
|
+
def initialize(attributes = {})
|
12
|
+
self.id = attributes[:id]
|
13
|
+
self.audio_url = attributes[:audio_url]
|
14
|
+
self.allow_user_responses = attributes[:allow_user_responses]
|
15
|
+
self.language_metadata = attributes[:language_metadata]
|
16
|
+
self.phonetic_transcriptions = attributes[:phonetic_transcriptions]
|
17
|
+
self.user_responses = attributes[:user_responses]
|
18
|
+
self.created_at = attributes[:created_at]
|
19
|
+
self.updated_at = attributes[:updated_at]
|
20
|
+
|
21
|
+
# The next attributes are present only for the 'create' action
|
22
|
+
self.audio_source = attributes[:audio_source]
|
23
|
+
self.audio_owner_signature = attributes[:audio_owner_signature]
|
24
|
+
self.name_owner_signature = attributes[:name_owner_signature]
|
25
|
+
self.name_text = attributes[:name_text]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gpdb
|
4
|
+
module REST
|
5
|
+
module Pronunciation
|
6
|
+
class Resource < Gpdb::REST::BaseResource
|
7
|
+
# @param [String] target
|
8
|
+
# @param [String] app_sig
|
9
|
+
# @param [String] app_type
|
10
|
+
# @param [Hash] options
|
11
|
+
# @return [Gpdb::REST::Pronunciation::TargetResponse]
|
12
|
+
def simple_search(target:, app_sig:, app_type:, **options)
|
13
|
+
request = ::Gpdb::REST::Request.new(
|
14
|
+
method: :get,
|
15
|
+
path: '/pronunciations',
|
16
|
+
params: {
|
17
|
+
target: target,
|
18
|
+
application_sig: app_sig,
|
19
|
+
application_type_sig: app_type
|
20
|
+
}.merge(options)
|
21
|
+
)
|
22
|
+
|
23
|
+
::Gpdb::REST::Pronunciation::TargetResponse.new(
|
24
|
+
client.request(request, namespace: 'api/public/v1')
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
# @param [Array] targets
|
29
|
+
# @param [Object] application_context
|
30
|
+
# @param [Object] user_context
|
31
|
+
# @return [Gpdb::REST::Pronunciation::TargetListResponse]
|
32
|
+
def complex_search(targets:, application_context:, user_context: {})
|
33
|
+
request = ::Gpdb::REST::Request.new(
|
34
|
+
method: :post,
|
35
|
+
path: '/pronunciations/search',
|
36
|
+
params: {
|
37
|
+
targets: targets,
|
38
|
+
application_context: application_context,
|
39
|
+
user_context: user_context
|
40
|
+
}
|
41
|
+
)
|
42
|
+
|
43
|
+
::Gpdb::REST::Pronunciation::TargetListResponse.new(
|
44
|
+
client.request(request, namespace: 'api/public/v1')
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
# @param [String] name
|
49
|
+
# @param [String] base64_audio
|
50
|
+
# @param [Object] application_context
|
51
|
+
# @param [Object] user_context
|
52
|
+
# @param [Hash] options
|
53
|
+
# @return [Gpdb::REST::Pronunciation::Response]
|
54
|
+
def create(name:, base64_audio:, application_context:, user_context:, **options)
|
55
|
+
request = ::Gpdb::REST::Request.new(
|
56
|
+
method: :post,
|
57
|
+
path: '/pronunciations',
|
58
|
+
params: {
|
59
|
+
name_text: name,
|
60
|
+
audio_data: base64_audio,
|
61
|
+
application_context: application_context,
|
62
|
+
user_context: user_context
|
63
|
+
}.merge(options)
|
64
|
+
)
|
65
|
+
|
66
|
+
::Gpdb::REST::Pronunciation::Response.new(
|
67
|
+
client.request(request, namespace: 'api/public/v1')
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gpdb
|
4
|
+
module REST
|
5
|
+
module Pronunciation
|
6
|
+
class Response < ::Gpdb::REST::Response
|
7
|
+
attr_accessor :pronunciation
|
8
|
+
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
|
12
|
+
self.pronunciation = Gpdb::REST::Pronunciation::Model.new(body) if success?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gpdb
|
4
|
+
module REST
|
5
|
+
module Pronunciation
|
6
|
+
class Target < ::Gpdb::Model
|
7
|
+
attr_accessor :pagination_info, :origin, :links,
|
8
|
+
:transcription, :id, :pronunciations
|
9
|
+
|
10
|
+
def initialize(attributes = {})
|
11
|
+
self.pagination_info = attributes[:target_pagination_info]
|
12
|
+
self.origin = attributes[:target_origin]
|
13
|
+
self.links = attributes[:links]
|
14
|
+
self.transcription = attributes[:target_transcription]
|
15
|
+
self.id = attributes[:target_id]
|
16
|
+
self.pronunciations = attributes[:pronunciations]&.map do |pronunciation|
|
17
|
+
::Gpdb::REST::Pronunciation::Model.new(pronunciation)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gpdb
|
4
|
+
module REST
|
5
|
+
module Pronunciation
|
6
|
+
class TargetListResponse < ::Gpdb::REST::Response
|
7
|
+
attr_accessor :target_results, :meta
|
8
|
+
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
|
12
|
+
return unless success?
|
13
|
+
|
14
|
+
self.target_results = body[:target_results].map { |target| ::Gpdb::REST::Pronunciation::Target.new(target) }
|
15
|
+
self.meta = body[:meta]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gpdb
|
4
|
+
module REST
|
5
|
+
module Pronunciation
|
6
|
+
class TargetResponse < ::Gpdb::REST::Response
|
7
|
+
attr_accessor :target, :meta
|
8
|
+
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
|
12
|
+
return unless success?
|
13
|
+
|
14
|
+
self.target = ::Gpdb::REST::Pronunciation::Target.new(body[:target_result])
|
15
|
+
self.meta = body[:meta]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gpdb
|
4
|
+
module REST
|
5
|
+
module RecordingRequest
|
6
|
+
class Model < ::Gpdb::Model
|
7
|
+
attr_accessor :recording_request_id, :target, :target_type_sig,
|
8
|
+
:target_owner_context, :user_context, :application_context
|
9
|
+
|
10
|
+
def initialize(attributes = {})
|
11
|
+
self.id = attributes[:recording_request_id]
|
12
|
+
self.target = attributes[:target]
|
13
|
+
self.target_type_sig = attributes[:target_owner_context]
|
14
|
+
self.user_context = attributes[:user_context]
|
15
|
+
self.application_context = attributes[:application_context]
|
16
|
+
self.target_owner_context = attributes[:target_owner_context]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gpdb
|
4
|
+
module REST
|
5
|
+
module RecordingRequest
|
6
|
+
class Resource < Gpdb::REST::BaseResource
|
7
|
+
# @param [String] target
|
8
|
+
# @param [String] target_type_sig
|
9
|
+
# @param [Object] target_owner_context
|
10
|
+
# @param [Object] application_context
|
11
|
+
# @param [Object] user_context
|
12
|
+
# @return [Gpdb::REST::RecordingRequest::Response]
|
13
|
+
def create(target:, target_type_sig:, target_owner_context:, application_context:, user_context:)
|
14
|
+
request = ::Gpdb::REST::Request.new(
|
15
|
+
method: :post,
|
16
|
+
path: '/recording_requests',
|
17
|
+
params: {
|
18
|
+
target: target,
|
19
|
+
target_type_sig: target_type_sig,
|
20
|
+
target_owner_context: target_owner_context,
|
21
|
+
application_context: application_context,
|
22
|
+
user_context: user_context
|
23
|
+
}
|
24
|
+
)
|
25
|
+
|
26
|
+
::Gpdb::REST::RecordingRequest::Response.new(
|
27
|
+
client.request(request, namespace: 'api/public/v1')
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gpdb
|
4
|
+
module REST
|
5
|
+
module RecordingRequest
|
6
|
+
class Response < ::Gpdb::REST::Response
|
7
|
+
attr_accessor :recording_request
|
8
|
+
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
|
12
|
+
self.recording_request = Gpdb::REST::RecordingRequest::Model.new(body) if success?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gpdb
|
4
|
+
module REST
|
5
|
+
class Response < ::Gpdb::Model
|
6
|
+
attr_accessor :body, :status, :_response, :errors
|
7
|
+
|
8
|
+
delegate :success?, to: :_response
|
9
|
+
|
10
|
+
def initialize(*args)
|
11
|
+
if args[0].is_a?(Hash)
|
12
|
+
super
|
13
|
+
elsif args[0].is_a?(::Gpdb::REST::Response)
|
14
|
+
super(
|
15
|
+
body: args[0].body,
|
16
|
+
status: args[0].status,
|
17
|
+
_response: args[0]._response
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
self.errors = body[:errors] if body.is_a?(Hash)
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
"<#{self.class} #{status} #{_response.reason_phrase} #{_response.headers['x-runtime']}s #{body.present? ? 'with body' : nil}>"
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
to_s
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/gpdb/version.rb
ADDED
data/lib/gpdb_client.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'active_support/core_ext/module'
|
2
|
+
require 'jwt'
|
3
|
+
require 'faraday'
|
4
|
+
|
5
|
+
require 'gpdb'
|
6
|
+
require 'gpdb/credentials'
|
7
|
+
require 'gpdb/configuration'
|
8
|
+
require 'gpdb/http_client'
|
9
|
+
require 'gpdb/model'
|
10
|
+
require 'gpdb/version'
|
11
|
+
|
12
|
+
require 'gpdb/rest/base_resource'
|
13
|
+
require 'gpdb/rest/client'
|
14
|
+
require 'gpdb/rest/request'
|
15
|
+
require 'gpdb/rest/response'
|
16
|
+
|
17
|
+
require 'gpdb/rest/recording_request/model'
|
18
|
+
require 'gpdb/rest/recording_request/resource'
|
19
|
+
require 'gpdb/rest/recording_request/response'
|
20
|
+
|
21
|
+
require 'gpdb/rest/pronunciation/model'
|
22
|
+
require 'gpdb/rest/pronunciation/resource'
|
23
|
+
require 'gpdb/rest/pronunciation/response'
|
24
|
+
require 'gpdb/rest/pronunciation/target'
|
25
|
+
require 'gpdb/rest/pronunciation/target_response'
|
26
|
+
require 'gpdb/rest/pronunciation/target_list_response'
|
27
|
+
|
28
|
+
module GpdbClient; end
|
metadata
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gpdb_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- NameCoachDevTeam
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-03 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: 2.1.4
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.1.4
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.9.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.9.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: jwt
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Description
|
112
|
+
email:
|
113
|
+
- dev-team@name-coach.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- Gemfile
|
120
|
+
- Gemfile.lock
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- bin/console
|
125
|
+
- bin/setup
|
126
|
+
- gpdb_client.gemspec
|
127
|
+
- lib/gpdb.rb
|
128
|
+
- lib/gpdb/configuration.rb
|
129
|
+
- lib/gpdb/credentials.rb
|
130
|
+
- lib/gpdb/http_client.rb
|
131
|
+
- lib/gpdb/model.rb
|
132
|
+
- lib/gpdb/rest/base_resource.rb
|
133
|
+
- lib/gpdb/rest/client.rb
|
134
|
+
- lib/gpdb/rest/pronunciation/model.rb
|
135
|
+
- lib/gpdb/rest/pronunciation/resource.rb
|
136
|
+
- lib/gpdb/rest/pronunciation/response.rb
|
137
|
+
- lib/gpdb/rest/pronunciation/target.rb
|
138
|
+
- lib/gpdb/rest/pronunciation/target_list_response.rb
|
139
|
+
- lib/gpdb/rest/pronunciation/target_response.rb
|
140
|
+
- lib/gpdb/rest/recording_request/model.rb
|
141
|
+
- lib/gpdb/rest/recording_request/resource.rb
|
142
|
+
- lib/gpdb/rest/recording_request/response.rb
|
143
|
+
- lib/gpdb/rest/request.rb
|
144
|
+
- lib/gpdb/rest/response.rb
|
145
|
+
- lib/gpdb/version.rb
|
146
|
+
- lib/gpdb_client.rb
|
147
|
+
homepage: ''
|
148
|
+
licenses:
|
149
|
+
- MIT
|
150
|
+
metadata: {}
|
151
|
+
post_install_message:
|
152
|
+
rdoc_options: []
|
153
|
+
require_paths:
|
154
|
+
- lib
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
requirements: []
|
166
|
+
rubygems_version: 3.0.3
|
167
|
+
signing_key:
|
168
|
+
specification_version: 4
|
169
|
+
summary: Summary
|
170
|
+
test_files: []
|