kaze_client 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff98889c7d39f15fc54339f9751d5197b15d3c5ed8af54375382858cf76a431b
4
- data.tar.gz: 8484f58d8443003290a8a165c640c936705ffb4c2b7a51188fa9b8486d6e672c
3
+ metadata.gz: f04fc270f92f58f489ff092c78adb05ec7d8d241277d2294e1d7d88ddd47e5ef
4
+ data.tar.gz: 69a336ea1b82c2a97c6a079a70220a625dfd48da3a3223a637e8c3d4a1e3bde3
5
5
  SHA512:
6
- metadata.gz: e0197299afa26f1a0a773f60e28f77c5d49b8a49930149f80e07cf7762311bdf7dd5c496df45e72c52d163b8e194ab57e7e94b97835449798db3f47f4a34e3bb
7
- data.tar.gz: 76488d384368b10038eb5e126c846c29f6bac94d318f899528b4c8d9b001e2c637d9775b882f40dfaa33d5e06884477e0801d3fb24eb8fbadb0e3f1b5423a2bb
6
+ metadata.gz: 44e207d6ccb69a208c5273d63e62615d113c0a8b0cf2bcd5020e5b977312ca79125740e29746e2375b18f32c5cdbfe0c70289e3c261e0f5b64c3fefcbd070468
7
+ data.tar.gz: bb1088a6628adca37f824660306ea5d4053f86df96f453fea12b02893f37c53e229fb3f7de1d0698cc15fd17d0a8ec4788037327315fb4c599e38462b6d874b6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## [0.3.0] - 2022-09-28
2
+
3
+ - Add new requests:
4
+ - Cancel job
5
+ - Get job document
6
+ - List users
7
+ - Upload image
8
+
9
+ ## [0.2.1] - 2022-06-17
10
+
11
+ - Add methods and utilities to get and set data in the response.
12
+
1
13
  ## [0.2.0] - 2022-06-01
2
14
 
3
15
  - Allow to set the authentication token on the client skipping login step.
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kaze_client (0.1.1p0)
4
+ kaze_client (0.2.0)
5
5
  httparty (~> 0.18, >= 0.18.1)
6
+ jsonpath (~> 1.1, >= 1.1.2)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -18,9 +19,12 @@ GEM
18
19
  io-console (0.5.11)
19
20
  irb (1.4.1)
20
21
  reline (>= 0.3.0)
22
+ jsonpath (1.1.2)
23
+ multi_json
21
24
  mime-types (3.4.1)
22
25
  mime-types-data (~> 3.2015)
23
26
  mime-types-data (3.2022.0105)
27
+ multi_json (1.15.0)
24
28
  multi_xml (0.6.0)
25
29
  parallel (1.22.1)
26
30
  parser (3.1.2.0)
data/kaze_client.gemspec CHANGED
@@ -32,5 +32,6 @@ Gem::Specification.new do |spec|
32
32
  spec.require_paths = ['lib']
33
33
 
34
34
  spec.add_runtime_dependency 'httparty', '~> 0.18', '>= 0.18.1'
35
+ spec.add_runtime_dependency 'jsonpath', '~> 1.1', '>= 1.1.2'
35
36
  # spec.metadata['rubygems_mfa_required'] = 'true'
36
37
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KazeClient
4
+ # @author ciappa_m@modulotech.fr
5
+ # Utility methods to interact with JSON data
6
+ # @see KazeClient::Response
7
+ # @since 0.2.1
8
+ module JsonUtils
9
+ # Fetch nodes in given JSON
10
+ #
11
+ # @param json [KazeClient::Response,Hash,String] The JSON to analyze
12
+ # @param path [String] A JSONpath - https://goessner.net/articles/JsonPath/
13
+ # @return [Array] The nodes or data corresponding to the path
14
+ def self.fetch_nodes(json, path)
15
+ json = case json
16
+ when ::KazeClient::Response
17
+ json.parsed_response
18
+ when String
19
+ JSON.parse(json)
20
+ else
21
+ json
22
+ end
23
+
24
+ JsonPath.on(json, path)
25
+ end
26
+
27
+ # Fetch a node in given JSON
28
+ #
29
+ # @param json [KazeClient::Response,Hash,String] The JSON to analyze
30
+ # @param path [String] A JSONpath - https://goessner.net/articles/JsonPath/
31
+ # @return [Object,nil] The node or data corresponding to the path or nil
32
+ def self.fetch_node(json, path)
33
+ fetch_nodes(json, path).first
34
+ end
35
+ end
36
+ 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.0
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
@@ -30,5 +30,48 @@ module KazeClient
30
30
  def respond_to_missing?(method_name, include_private = false)
31
31
  %i[original_response parsed_response].include?(method_name) || super
32
32
  end
33
+
34
+ # Find the child whose id is the given one in this response
35
+ #
36
+ # @param id [String] The id of the child to find
37
+ # @return [Hash,nil] The child or nil if not found
38
+ # @see KazeClient::JsonUtils.fetch_node
39
+ def fetch_child(id)
40
+ ::KazeClient::JsonUtils.fetch_node(self, %{$..children[?(@['id'] == '#{id}')]})
41
+ end
42
+
43
+ # Find the first child with the given id and return the given field
44
+ #
45
+ # @param id [String] The id of the child to find
46
+ # @param field [String] The name of the searched field
47
+ # @return [Object,nil] The value of the field or nil if not found
48
+ # @see #fetch_child
49
+ def fetch_data_from_child(id, field: 'data')
50
+ fetch_child(id)&.[](field)
51
+ end
52
+
53
+ # Find all the widget in this response.
54
+ # Technically, it fetch all the children whose type is +widget_*+
55
+ #
56
+ # @return [Array] The list of widgets
57
+ # @see KazeClient::JsonUtils.fetch_nodes
58
+ def fetch_widgets
59
+ ::KazeClient::JsonUtils.fetch_nodes(self, %{$..children[?(@['type'] =~ /^widget_/)]})
60
+ end
61
+
62
+ # Find the first child with the given id and update value of the given field
63
+ # Does nothing when +id+ was not found.
64
+ # Add a field when +field+ is not found.
65
+ #
66
+ # @param id [String] The id of the child to find
67
+ # @param value [Object] The value to set on the field
68
+ # @param field [String] The name of the searched field
69
+ # @return [KazeClient::Response] The response itself for chaining
70
+ # @see #fetch_child
71
+ def update_data_in_child(id, value, field: 'data')
72
+ fetch_child(id)&.[]=(field.to_s, value)
73
+
74
+ self
75
+ end
33
76
  end
34
77
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KazeClient
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/kaze_client.rb CHANGED
@@ -4,13 +4,16 @@
4
4
  require 'activesupport/blank'
5
5
  require 'activesupport/camelize'
6
6
 
7
- # Require HTTParty
7
+ # Require third-party libraries
8
+ require 'pathname'
8
9
  require 'httparty'
10
+ require 'jsonpath'
9
11
 
10
12
  # Require the version number
11
13
  require_relative 'kaze_client/version'
12
14
 
13
15
  # Require the different parts of the gem
16
+ require_relative 'kaze_client/json_utils'
14
17
  require_relative 'kaze_client/errors'
15
18
  require_relative 'kaze_client/requests'
16
19
  require_relative 'kaze_client/response'
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.2.0
4
+ version: 0.3.0
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-06-01 00:00:00.000000000 Z
11
+ date: 2022-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -30,6 +30,26 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.18.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: jsonpath
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.1'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.1.2
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.1'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.1.2
33
53
  description: |
34
54
  This is the official Ruby client library for Kaze (https://www.kaze.so/) API.
35
55
 
@@ -68,9 +88,12 @@ files:
68
88
  - lib/kaze_client/error/not_found.rb
69
89
  - lib/kaze_client/error/unauthorized.rb
70
90
  - lib/kaze_client/errors.rb
91
+ - lib/kaze_client/json_utils.rb
71
92
  - lib/kaze_client/request/request.rb
72
93
  - lib/kaze_client/request/requests/assign_performer_request.rb
94
+ - lib/kaze_client/request/requests/cancel_job_request.rb
73
95
  - lib/kaze_client/request/requests/create_job_request.rb
96
+ - lib/kaze_client/request/requests/job_document_request.rb
74
97
  - lib/kaze_client/request/requests/job_request.rb
75
98
  - lib/kaze_client/request/requests/job_workflow_request.rb
76
99
  - lib/kaze_client/request/requests/job_workflows_request.rb
@@ -79,6 +102,8 @@ files:
79
102
  - lib/kaze_client/request/requests/partners_request.rb
80
103
  - lib/kaze_client/request/requests/profile_request.rb
81
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
82
107
  - lib/kaze_client/request/requests/utils/authentified_request.rb
83
108
  - lib/kaze_client/request/requests/utils/final_request.rb
84
109
  - lib/kaze_client/request/requests/utils/list_request.rb