datawow 1.2.0 → 1.2.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 +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -18
- data/README.md +1 -1
- data/datawow.gemspec +1 -4
- data/lib/datawow/connector.rb +1 -0
- data/lib/datawow/version.rb +1 -1
- data/lib/datawow.rb +0 -3
- metadata +1 -58
- data/lib/datawow/connection.rb +0 -99
- data/lib/datawow/faraday/raise_http_exception.rb +0 -40
- data/test/datawow/connection_test.rb +0 -85
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 187a5c97f2c538e9f4a465ec2f639f87095ae07de3095ae18acd99bea2e87459
|
4
|
+
data.tar.gz: 7412151b8a8ca09502c4e50d7ea3baf54dbe2627d2146546443338115144a24f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91c660c19fcb1da84921a70caaf55bb660ec1d206c1e09895014c7bb9e988e9755dde8c3d73a4750920720c066270a9d57f83b2948c6d27f7566b79070952a8d
|
7
|
+
data.tar.gz: 412a95f8ec985fb456b34622cb1cf9203e404af61e20ecd3e8fa4503d439d06d417c3a73c717c7ea0f63bf8e40abf80ba6bcb53df3d5a6d953075919844a7306
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
datawow (1.2.
|
5
|
-
faraday (~> 0.13.1, >= 0.13.1)
|
6
|
-
faraday_middleware (~> 0.12.2, >= 0.12.2)
|
4
|
+
datawow (1.2.1)
|
7
5
|
json (~> 1.8, >= 1.8.3)
|
8
6
|
|
9
7
|
GEM
|
@@ -11,26 +9,12 @@ GEM
|
|
11
9
|
specs:
|
12
10
|
addressable (2.5.2)
|
13
11
|
public_suffix (>= 2.0.2, < 4.0)
|
14
|
-
byebug (10.0.2)
|
15
|
-
coderay (1.1.2)
|
16
12
|
crack (0.4.3)
|
17
13
|
safe_yaml (~> 1.0.0)
|
18
14
|
docile (1.1.5)
|
19
|
-
faraday (0.13.1)
|
20
|
-
multipart-post (>= 1.2, < 3)
|
21
|
-
faraday_middleware (0.12.2)
|
22
|
-
faraday (>= 0.7.4, < 1.0)
|
23
15
|
hashdiff (0.3.7)
|
24
16
|
json (1.8.6)
|
25
|
-
method_source (0.9.2)
|
26
17
|
minitest (5.11.3)
|
27
|
-
multipart-post (2.0.0)
|
28
|
-
pry (0.12.2)
|
29
|
-
coderay (~> 1.1.0)
|
30
|
-
method_source (~> 0.9.0)
|
31
|
-
pry-byebug (3.6.0)
|
32
|
-
byebug (~> 10.0)
|
33
|
-
pry (~> 0.10)
|
34
18
|
public_suffix (3.0.3)
|
35
19
|
rake (12.3.1)
|
36
20
|
safe_yaml (1.0.4)
|
@@ -50,7 +34,6 @@ PLATFORMS
|
|
50
34
|
DEPENDENCIES
|
51
35
|
datawow!
|
52
36
|
minitest (~> 5.11, >= 5.11.3)
|
53
|
-
pry-byebug (~> 3.6)
|
54
37
|
rake (~> 12.3)
|
55
38
|
simplecov (~> 0.15.1)
|
56
39
|
webmock (~> 3.3)
|
data/README.md
CHANGED
data/datawow.gemspec
CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = 'datawow'
|
8
|
-
s.version = '1.2.
|
8
|
+
s.version = '1.2.1'
|
9
9
|
s.date = '2018-11-27'
|
10
10
|
s.summary = 'HTTP RESTFul for calling DataWow APIs'
|
11
11
|
s.description = 'Moderation suite'
|
@@ -17,11 +17,8 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.license = 'Commercial'
|
18
18
|
s.require_paths = ['lib']
|
19
19
|
|
20
|
-
s.add_runtime_dependency 'faraday', '~> 0.13.1', '>= 0.13.1'
|
21
|
-
s.add_runtime_dependency 'faraday_middleware', '~> 0.12.2', '>= 0.12.2'
|
22
20
|
s.add_runtime_dependency 'json', '~> 1.8', '>= 1.8.3'
|
23
21
|
s.add_development_dependency 'minitest', '~> 5.11', '>= 5.11.3'
|
24
|
-
s.add_development_dependency 'pry-byebug', '~> 3.6'
|
25
22
|
s.add_development_dependency 'rake', '~> 12.3'
|
26
23
|
s.add_development_dependency 'simplecov', '~> 0.15.1'
|
27
24
|
s.add_development_dependency 'webmock', '~> 3.3'
|
data/lib/datawow/connector.rb
CHANGED
data/lib/datawow/version.rb
CHANGED
data/lib/datawow.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datawow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesdakorn Samittiauttakorn
|
@@ -10,46 +10,6 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2018-11-27 00:00:00.000000000 Z
|
12
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.13.1
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 0.13.1
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 0.13.1
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 0.13.1
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: faraday_middleware
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - "~>"
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: 0.12.2
|
40
|
-
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: 0.12.2
|
43
|
-
type: :runtime
|
44
|
-
prerelease: false
|
45
|
-
version_requirements: !ruby/object:Gem::Requirement
|
46
|
-
requirements:
|
47
|
-
- - "~>"
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: 0.12.2
|
50
|
-
- - ">="
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: 0.12.2
|
53
13
|
- !ruby/object:Gem::Dependency
|
54
14
|
name: json
|
55
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,20 +50,6 @@ dependencies:
|
|
90
50
|
- - ">="
|
91
51
|
- !ruby/object:Gem::Version
|
92
52
|
version: 5.11.3
|
93
|
-
- !ruby/object:Gem::Dependency
|
94
|
-
name: pry-byebug
|
95
|
-
requirement: !ruby/object:Gem::Requirement
|
96
|
-
requirements:
|
97
|
-
- - "~>"
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
version: '3.6'
|
100
|
-
type: :development
|
101
|
-
prerelease: false
|
102
|
-
version_requirements: !ruby/object:Gem::Requirement
|
103
|
-
requirements:
|
104
|
-
- - "~>"
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
version: '3.6'
|
107
53
|
- !ruby/object:Gem::Dependency
|
108
54
|
name: rake
|
109
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,10 +112,8 @@ files:
|
|
166
112
|
- datawow.gemspec
|
167
113
|
- lib/datawow.rb
|
168
114
|
- lib/datawow/client_response.rb
|
169
|
-
- lib/datawow/connection.rb
|
170
115
|
- lib/datawow/connector.rb
|
171
116
|
- lib/datawow/error.rb
|
172
|
-
- lib/datawow/faraday/raise_http_exception.rb
|
173
117
|
- lib/datawow/models/images/image_choices.rb
|
174
118
|
- lib/datawow/models/images/image_closed_questions.rb
|
175
119
|
- lib/datawow/models/images/image_messages.rb
|
@@ -185,7 +129,6 @@ files:
|
|
185
129
|
- lib/generators/datawow/install_generator.rb
|
186
130
|
- lib/generators/templates/datawow_api.rb
|
187
131
|
- test/datawow/client_response_test.rb
|
188
|
-
- test/datawow/connection_test.rb
|
189
132
|
- test/datawow/connector_test.rb
|
190
133
|
- test/datawow/image_choices_test.rb
|
191
134
|
- test/datawow/image_closed_questions_test.rb
|
data/lib/datawow/connection.rb
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require File.expand_path('faraday/raise_http_exception.rb', __dir__)
|
4
|
-
require File.expand_path('client_response.rb', __dir__)
|
5
|
-
|
6
|
-
module Datawow
|
7
|
-
# :nodoc:
|
8
|
-
class Connection
|
9
|
-
def initialize(model:, version_api: 'v1')
|
10
|
-
@model = model
|
11
|
-
@version_api = version_api
|
12
|
-
end
|
13
|
-
|
14
|
-
def get(path, options = {})
|
15
|
-
@response = connection.get do |request|
|
16
|
-
request.url("#{@version_api}#{path}")
|
17
|
-
request.headers['Content-Type'] = 'application/json'
|
18
|
-
request.headers['Authorization'] = options[:token] unless options[:token].nil?
|
19
|
-
request.params = options[:path_param] ? params_url_options(options) : options
|
20
|
-
end
|
21
|
-
Response.new(data, status_code, message, meta, total)
|
22
|
-
rescue Error, Faraday::Error => e
|
23
|
-
handle_error(e)
|
24
|
-
end
|
25
|
-
|
26
|
-
def post(path, options = {}, query_params = {})
|
27
|
-
@response = connection.post do |request|
|
28
|
-
request.url("#{@version_api}#{path}")
|
29
|
-
request.headers['Content-Type'] = 'application/json'
|
30
|
-
request.headers['Authorization'] = options[:token] unless options[:token].nil?
|
31
|
-
request.params = query_params
|
32
|
-
request.body = options unless options.nil?
|
33
|
-
end
|
34
|
-
Response.new(data, status_code, message, meta, nil)
|
35
|
-
rescue Error, Faraday::Error => e
|
36
|
-
handle_error(e)
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def connection
|
42
|
-
@connection ||= Faraday::Connection.new(base_point) do |connection|
|
43
|
-
connection.request :url_encoded
|
44
|
-
connection.request :json
|
45
|
-
connection.response :json
|
46
|
-
connection.use Datawow::FaradayMiddleware::RaiseHttpException
|
47
|
-
connection.use :gzip
|
48
|
-
connection.adapter Faraday.default_adapter
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def data
|
53
|
-
@response.body['data']
|
54
|
-
end
|
55
|
-
|
56
|
-
def meta
|
57
|
-
@response.body['meta']
|
58
|
-
end
|
59
|
-
|
60
|
-
def status_code
|
61
|
-
meta['code'] unless meta.nil?
|
62
|
-
end
|
63
|
-
|
64
|
-
def message
|
65
|
-
meta['message'] unless meta.nil?
|
66
|
-
end
|
67
|
-
|
68
|
-
def total
|
69
|
-
meta['total_count'] unless meta.nil?
|
70
|
-
end
|
71
|
-
|
72
|
-
def handle_error(exception)
|
73
|
-
if exception.is_a?(Faraday::ConnectionFailed)
|
74
|
-
code = 599
|
75
|
-
message = 'Connection Failed'
|
76
|
-
else
|
77
|
-
code = exception.to_s.partition(':').first
|
78
|
-
message = exception.to_s.partition(':').last
|
79
|
-
end
|
80
|
-
|
81
|
-
Response.new(nil, code, message, nil)
|
82
|
-
end
|
83
|
-
|
84
|
-
def params_url_options(options)
|
85
|
-
%i[id path_param].each { |e| options.delete(e) }
|
86
|
-
options
|
87
|
-
end
|
88
|
-
|
89
|
-
def base_point
|
90
|
-
options = {
|
91
|
-
image: 'https://kiyo-image.datawow.io/api/',
|
92
|
-
ai: 'https://kiyo-image.datawow.io/api/',
|
93
|
-
text: 'https://kiyo-text.datawow.io/api/',
|
94
|
-
video: 'https://kiyo-image.datawow.io/api/'
|
95
|
-
}
|
96
|
-
options[@model]
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'faraday_middleware'
|
2
|
-
|
3
|
-
module Datawow
|
4
|
-
module FaradayMiddleware
|
5
|
-
class RaiseHttpException < Faraday::Middleware
|
6
|
-
def call(request_env)
|
7
|
-
@app.call(request_env).on_complete do |response|
|
8
|
-
case response[:status].to_i
|
9
|
-
when 200, 201
|
10
|
-
# nothing to do here
|
11
|
-
when 400
|
12
|
-
error_message = error_message(response[:body])
|
13
|
-
raise BadRequest, "#{response[:status]}: #{error_message}"
|
14
|
-
when 403
|
15
|
-
error_message = error_message(response[:body])
|
16
|
-
raise NotPermitted, "#{response[:status]}: #{error_message}"
|
17
|
-
when 404
|
18
|
-
error_message = error_message(response[:body])
|
19
|
-
raise NotFound, "#{response[:status]}: #{error_message}"
|
20
|
-
else
|
21
|
-
request_method = response[:method].to_s.upcase
|
22
|
-
request_url = response[:url].to_s
|
23
|
-
response_status = response[:status]
|
24
|
-
error_message = error_message(response[:body])
|
25
|
-
raise Error, "#{response_status}: #{request_method} #{request_url} #{error_message}"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def error_message(response_body)
|
33
|
-
if !response_body.nil? && response_body.is_a?(String)
|
34
|
-
response_body = JSON.parse(response_body)
|
35
|
-
response_body['message']
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Datawow
|
4
|
-
class ConnectionTest < Minitest::Test
|
5
|
-
def test_get_success
|
6
|
-
stub_request(:get, 'https://kiyo-image.datawow.io/api/v1/images')
|
7
|
-
.to_return(body: JSON.generate(data: 'foo', meta: { message: 'success', code: 200 }), status: 200)
|
8
|
-
response = connection.get('/images', {})
|
9
|
-
assert_instance_of(Response, response)
|
10
|
-
assert_equal(200, response.status)
|
11
|
-
assert_equal('success', response.message)
|
12
|
-
assert_equal('success', response.meta['message'])
|
13
|
-
assert_equal(200, response.status)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_get_failed
|
17
|
-
stub_request(:get, 'https://kiyo-image.datawow.io/api/v1/images')
|
18
|
-
.to_return(body: JSON.generate(data: '', meta: { message: 'Internal Server Error', code: 500 }), status: 500)
|
19
|
-
response = connection.get('/images', {})
|
20
|
-
assert_instance_of(Response, response)
|
21
|
-
assert_equal(500, response.status)
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_post_success
|
25
|
-
stub_request(:post, 'https://kiyo-image.datawow.io/api/v1/images')
|
26
|
-
.to_return(body: JSON.generate(data: 'foo', meta: { code: 200 }), status: 200)
|
27
|
-
response = connection.post('/images', {})
|
28
|
-
assert_instance_of(Response, response)
|
29
|
-
assert_equal(200, response.status)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_post_failed
|
33
|
-
stub_request(:post, 'https://kiyo-image.datawow.io/api/v1/images')
|
34
|
-
.to_return(body: JSON.generate(data: '', meta: { code: 500, message: 'Internal Server Error' }), status: 500)
|
35
|
-
response = connection.post('/images', {})
|
36
|
-
assert_instance_of(Response, response)
|
37
|
-
assert_equal(500, response.status)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_connection_failed
|
41
|
-
stub_request(:get, 'https://kiyo-image.datawow.io/api/v1/images')
|
42
|
-
.to_raise(Faraday::ConnectionFailed.new('connection failed'))
|
43
|
-
response = connection.get('/images')
|
44
|
-
assert_instance_of(Response, response)
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_bad_request_status
|
48
|
-
stub_request(:get, 'https://kiyo-image.datawow.io/api/v1/images')
|
49
|
-
.to_return(status: 400, body: JSON.generate(data: '', meta: { message: 'bad request', code: 400 }))
|
50
|
-
response = connection.get('/images', {})
|
51
|
-
assert_instance_of(Response, response)
|
52
|
-
assert_equal(400, response.status)
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_forbidden_status
|
56
|
-
stub_request(:get, 'https://kiyo-image.datawow.io/api/v1/images')
|
57
|
-
.to_return(body: JSON.generate(data: '', meta: { message: 'forbidden', code: 403 }), status: 403)
|
58
|
-
response = connection.get('/images', {})
|
59
|
-
assert_instance_of(Response, response)
|
60
|
-
assert_equal(403, response.status)
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_not_found_status
|
64
|
-
stub_request(:get, 'https://kiyo-image.datawow.io/api/v1/images')
|
65
|
-
.to_return(body: JSON.generate(data: '', meta: { message: 'not found', code: 404 }), status: 404)
|
66
|
-
response = connection.get('/images', {})
|
67
|
-
assert_instance_of(Response, response)
|
68
|
-
assert_equal(404, response.status)
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_edge_case_error
|
72
|
-
stub_request(:get, 'https://kiyo-image.datawow.io/api/v1/images')
|
73
|
-
.to_return(body: JSON.generate(data: '', meta: { message: 'version not supported', code: 505 }), status: 505)
|
74
|
-
response = connection.get('/images', {})
|
75
|
-
assert_instance_of(Response, response)
|
76
|
-
assert_equal(505, response.status)
|
77
|
-
end
|
78
|
-
|
79
|
-
private
|
80
|
-
|
81
|
-
def connection
|
82
|
-
@connection ||= Datawow::Connection.new(model: :image)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|