kaze_client 0.2.0 → 0.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/CHANGELOG.md +4 -0
- data/Gemfile.lock +5 -1
- data/kaze_client.gemspec +1 -0
- data/lib/kaze_client/json_utils.rb +36 -0
- data/lib/kaze_client/response.rb +43 -0
- data/lib/kaze_client/version.rb +1 -1
- data/lib/kaze_client.rb +3 -1
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd31be1e3cb6ccd738c9646f50ad6096961f4b77f893373f38481f747a2c5442
|
4
|
+
data.tar.gz: 7f2081157ac8778d108e4629524e228ad67aaeabb38ad977b7eb362476d0e996
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96c9f307c9d54f2d446d82e10f1ed795223a2679c3dc60dcc7dcfd1f3609bf90b78042552e34560fe2ef292ea35ec2f93a8dc744f12ba05dac7c4a76316417f7
|
7
|
+
data.tar.gz: 5645d82b34831f41eacd354e69a573a7e566c488dd6686e9b552e704953319c4733715bbe34e13efd9007af1e75ad122b9e6c33d5b3c923d312b4d37b8d17fc0
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kaze_client (0.
|
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
@@ -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
|
data/lib/kaze_client/response.rb
CHANGED
@@ -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
|
data/lib/kaze_client/version.rb
CHANGED
data/lib/kaze_client.rb
CHANGED
@@ -4,13 +4,15 @@
|
|
4
4
|
require 'activesupport/blank'
|
5
5
|
require 'activesupport/camelize'
|
6
6
|
|
7
|
-
# Require
|
7
|
+
# Require third-part libraries
|
8
8
|
require 'httparty'
|
9
|
+
require 'jsonpath'
|
9
10
|
|
10
11
|
# Require the version number
|
11
12
|
require_relative 'kaze_client/version'
|
12
13
|
|
13
14
|
# Require the different parts of the gem
|
15
|
+
require_relative 'kaze_client/json_utils'
|
14
16
|
require_relative 'kaze_client/errors'
|
15
17
|
require_relative 'kaze_client/requests'
|
16
18
|
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.
|
4
|
+
version: 0.2.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-06-
|
11
|
+
date: 2022-06-17 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,6 +88,7 @@ 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
|
73
94
|
- lib/kaze_client/request/requests/create_job_request.rb
|