kaze_client 0.2.1 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/kaze_client/request/request.rb +33 -13
- data/lib/kaze_client/request/requests/cancel_job_request.rb +21 -0
- data/lib/kaze_client/request/requests/job_document_request.rb +17 -0
- data/lib/kaze_client/request/requests/partners_request.rb +1 -1
- data/lib/kaze_client/request/requests/upload_image_request.rb +46 -0
- data/lib/kaze_client/request/requests/users_request.rb +18 -0
- data/lib/kaze_client/version.rb +1 -1
- data/lib/kaze_client.rb +2 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 483e914296f78875d5a5eb30e3207f7f99d8db4c7bfddbc8440f3983e99f5605
|
4
|
+
data.tar.gz: ebb0a204c158f59fa6cdde4d04573b1beaeaa94b07f86b8b7815ce59c9e40ca0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3006d994cb61c5b180449f58dce770ddb7f12cf3636cb3247b2b669f7ea387b3d4a71085645a1671d0aea0e298ba1f28db984227dbcc5c9d1e39809041ba0b7
|
7
|
+
data.tar.gz: a96e0bcd0089c80c89bed0573ff829d62e727f5b3e4d6de0b87b0a6b3158cb17bb1c5344fbd35bca8a52ced6b9466024365e004dc02fc704005e662a8b34615d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
## [0.3.1] - 2022-11-30
|
4
|
+
|
5
|
+
- Update error handling for more clarity.
|
6
|
+
|
7
|
+
## [0.3.0] - 2022-09-28
|
8
|
+
|
9
|
+
- Add new requests:
|
10
|
+
- Cancel job
|
11
|
+
- Get job document
|
12
|
+
- List users
|
13
|
+
- Upload image
|
14
|
+
|
1
15
|
## [0.2.1] - 2022-06-17
|
2
16
|
|
3
17
|
- Add methods and utilities to get and set data in the response.
|
@@ -10,7 +10,7 @@ module KazeClient
|
|
10
10
|
# Those headers are added on all requests by default
|
11
11
|
DEFAULT_HEADERS = {
|
12
12
|
'Content-Type' => 'application/json',
|
13
|
-
'Accept'
|
13
|
+
'Accept' => 'application/json'
|
14
14
|
}.freeze
|
15
15
|
|
16
16
|
# @return [String, Symbol] The HTTP verb to use for the request
|
@@ -64,19 +64,12 @@ module KazeClient
|
|
64
64
|
# @param response [HTTParty::Response] The response object from HTTParty call
|
65
65
|
# @return [KazeClient::Error::Generic] The adequate error object according to the given response
|
66
66
|
def error_for(response)
|
67
|
-
|
68
|
-
|
69
|
-
return KazeClient::Error::NotFound.new if response.code == 404
|
67
|
+
error = response.parsed_response['error']
|
68
|
+
message = response.parsed_response['message']
|
70
69
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
rescue NameError
|
75
|
-
# This means no error class exists for the error code in the response, we fallback to a
|
76
|
-
# generic error
|
77
|
-
Error::Generic.new(status: response.code,
|
78
|
-
error: response.parsed_response['error'],
|
79
|
-
message: response.parsed_response['message'])
|
70
|
+
return non_generic_error(error, message, response) if error != 'generic'
|
71
|
+
|
72
|
+
generic_http_error(error, message, response)
|
80
73
|
end
|
81
74
|
|
82
75
|
protected
|
@@ -100,6 +93,8 @@ module KazeClient
|
|
100
93
|
@body
|
101
94
|
when Hash
|
102
95
|
@body.to_json
|
96
|
+
else
|
97
|
+
@body.to_s
|
103
98
|
end
|
104
99
|
end
|
105
100
|
|
@@ -109,5 +104,30 @@ module KazeClient
|
|
109
104
|
|
110
105
|
@query
|
111
106
|
end
|
107
|
+
|
108
|
+
def non_generic_error(error, message, response)
|
109
|
+
# Return the adequate error class for the error code in the response
|
110
|
+
"KazeClient::Error::#{error.camelize}".constantize.new(message)
|
111
|
+
rescue NameError
|
112
|
+
# This means no error class exists for the error code in the response, we fallback to a
|
113
|
+
# generic error
|
114
|
+
Error::Generic.new(status: response.code, error: error, message: message)
|
115
|
+
end
|
116
|
+
|
117
|
+
def generic_http_error(error, message, response)
|
118
|
+
case response.code
|
119
|
+
when 401
|
120
|
+
KazeClient::Error::Unauthorized.new(message)
|
121
|
+
when 403
|
122
|
+
KazeClient::Error::Forbidden.new(message)
|
123
|
+
when 404
|
124
|
+
KazeClient::Error::NotFound.new
|
125
|
+
when 500
|
126
|
+
KazeClient::Error::InternalServerError.new(message)
|
127
|
+
else
|
128
|
+
# This means no error class exists for the response code, we fallback to a generic error
|
129
|
+
Error::Generic.new(status: response.code, error: error, message: message)
|
130
|
+
end
|
131
|
+
end
|
112
132
|
end
|
113
133
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
# @author chevre_a@modulotech.fr
|
5
|
+
# Cancel a job.
|
6
|
+
# @see KazeClient::Request
|
7
|
+
# @see KazeClient::Utils::FinalRequest
|
8
|
+
# @see KazeClient::Utils::AuthentifiedRequest
|
9
|
+
# @since 0.3.0
|
10
|
+
class CancelJobRequest < Utils::FinalRequest
|
11
|
+
include Utils::AuthentifiedRequest
|
12
|
+
|
13
|
+
def initialize(job_id, cancel_reason_id)
|
14
|
+
super(:put, "api/jobs/#{job_id}/cancel")
|
15
|
+
|
16
|
+
@body = {
|
17
|
+
job: { cancel_reason_id: cancel_reason_id }
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
# @author chevre_a@modulotech.fr
|
5
|
+
# Retrieve a job document from a job.
|
6
|
+
# @see KazeClient::Request
|
7
|
+
# @see KazeClient::Utils::FinalRequest
|
8
|
+
# @see KazeClient::Utils::AuthentifiedRequest
|
9
|
+
# @since 0.3.0
|
10
|
+
class JobDocumentRequest < Utils::FinalRequest
|
11
|
+
include Utils::AuthentifiedRequest
|
12
|
+
|
13
|
+
def initialize(job_id, job_document_id)
|
14
|
+
super(:get, "api/jobs/#{job_id}/documents/#{job_document_id}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -7,7 +7,7 @@ module KazeClient
|
|
7
7
|
# @see KazeClient::Utils::FinalRequest
|
8
8
|
# @see KazeClient::Utils::AuthentifiedRequest
|
9
9
|
# @see KazeClient::Utils::ListRequest
|
10
|
-
# @since 0.1.
|
10
|
+
# @since 0.1.1
|
11
11
|
class PartnersRequest < Utils::FinalRequest
|
12
12
|
include Utils::AuthentifiedRequest
|
13
13
|
include Utils::ListRequest
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
# @author pourch_t@modulotech.fr
|
5
|
+
# @author ciappa_m@modulotech.fr
|
6
|
+
# Upload an image to a job document from a job.
|
7
|
+
# @see KazeClient::Request
|
8
|
+
# @see KazeClient::Utils::FinalRequest
|
9
|
+
# @see KazeClient::Utils::AuthentifiedRequest
|
10
|
+
# @since 0.3.0
|
11
|
+
# @example How to use
|
12
|
+
# request = KazeClient::UploadImageRequest.new(Rails.root.join('public/images/test.jpg'))
|
13
|
+
# response = KazeClient::Client.new(URL).execute(request)
|
14
|
+
# request.send_image(response['direct_upload'])
|
15
|
+
class UploadImageRequest < Utils::FinalRequest
|
16
|
+
|
17
|
+
include Utils::AuthentifiedRequest
|
18
|
+
|
19
|
+
def initialize(filepath)
|
20
|
+
super(:post, 'api/direct_uploads')
|
21
|
+
@filepath = if filepath.is_a?(Pathname)
|
22
|
+
filepath
|
23
|
+
else
|
24
|
+
Pathname.new(filepath.to_s)
|
25
|
+
end
|
26
|
+
@filename = @filepath.basename.to_s
|
27
|
+
|
28
|
+
@body = {
|
29
|
+
blob: {
|
30
|
+
filename: @filename,
|
31
|
+
byte_size: File.size(@filepath),
|
32
|
+
checksum: Digest::MD5.base64digest(@filepath.read),
|
33
|
+
content_type: "image/#{@filename.split('.')[1]}"
|
34
|
+
}
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def send_image(direct_uploads)
|
39
|
+
body = @filepath.read
|
40
|
+
header = direct_uploads['headers']
|
41
|
+
HTTParty.put(direct_uploads['url'], { body: body, headers: header })
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
# @author chevre_a@modulotech.fr
|
5
|
+
# List the users from the current user's company.
|
6
|
+
# @see KazeClient::Request
|
7
|
+
# @see KazeClient::Utils::FinalRequest
|
8
|
+
# @see KazeClient::Utils::AuthentifiedRequest
|
9
|
+
# @since 0.3.0
|
10
|
+
class UsersRequest < Utils::FinalRequest
|
11
|
+
include Utils::AuthentifiedRequest
|
12
|
+
include Utils::ListRequest
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
super(:get, 'api/users')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/kaze_client/version.rb
CHANGED
data/lib/kaze_client.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kaze_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthieu Ciappara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -91,7 +91,9 @@ files:
|
|
91
91
|
- lib/kaze_client/json_utils.rb
|
92
92
|
- lib/kaze_client/request/request.rb
|
93
93
|
- lib/kaze_client/request/requests/assign_performer_request.rb
|
94
|
+
- lib/kaze_client/request/requests/cancel_job_request.rb
|
94
95
|
- lib/kaze_client/request/requests/create_job_request.rb
|
96
|
+
- lib/kaze_client/request/requests/job_document_request.rb
|
95
97
|
- lib/kaze_client/request/requests/job_request.rb
|
96
98
|
- lib/kaze_client/request/requests/job_workflow_request.rb
|
97
99
|
- lib/kaze_client/request/requests/job_workflows_request.rb
|
@@ -100,6 +102,8 @@ files:
|
|
100
102
|
- lib/kaze_client/request/requests/partners_request.rb
|
101
103
|
- lib/kaze_client/request/requests/profile_request.rb
|
102
104
|
- lib/kaze_client/request/requests/update_template_request.rb
|
105
|
+
- lib/kaze_client/request/requests/upload_image_request.rb
|
106
|
+
- lib/kaze_client/request/requests/users_request.rb
|
103
107
|
- lib/kaze_client/request/requests/utils/authentified_request.rb
|
104
108
|
- lib/kaze_client/request/requests/utils/final_request.rb
|
105
109
|
- lib/kaze_client/request/requests/utils/list_request.rb
|