kaze_client 0.1.1p0 → 0.2.1

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: 687ef335a59eb5c25b4efece8a9e74f49a12a465b4018512c01246d2753fd218
4
- data.tar.gz: 45905959e188ba363b09fa69bd96839e3b31057fac1704ede9c9a9fa3bbb020d
3
+ metadata.gz: fd31be1e3cb6ccd738c9646f50ad6096961f4b77f893373f38481f747a2c5442
4
+ data.tar.gz: 7f2081157ac8778d108e4629524e228ad67aaeabb38ad977b7eb362476d0e996
5
5
  SHA512:
6
- metadata.gz: 0eddfc2630c7ebd3aab7b17403662dd8922dc7f6a36488ac62b450d5246311763a2a4c0942e7618be16084267d2f64e0493fa17148c3b0c134d66f018f4d8536
7
- data.tar.gz: 15c60ae8c4b65d96a63f1438c9dd7560d9f5e449a39780ad4040556973f2c185a6ec69980ae257e8a1cf6da5dfda1990a0c293398d7aca662defebbee2e4f77c
6
+ metadata.gz: 96c9f307c9d54f2d446d82e10f1ed795223a2679c3dc60dcc7dcfd1f3609bf90b78042552e34560fe2ef292ea35ec2f93a8dc744f12ba05dac7c4a76316417f7
7
+ data.tar.gz: 5645d82b34831f41eacd354e69a573a7e566c488dd6686e9b552e704953319c4733715bbe34e13efd9007af1e75ad122b9e6c33d5b3c923d312b4d37b8d17fc0
data/CHANGELOG.md CHANGED
@@ -1,4 +1,12 @@
1
- ## [0.1.1p1] - 2022-05-31
1
+ ## [0.2.1] - 2022-06-17
2
+
3
+ - Add methods and utilities to get and set data in the response.
4
+
5
+ ## [0.2.0] - 2022-06-01
6
+
7
+ - Allow to set the authentication token on the client skipping login step.
8
+
9
+ ## [0.1.1p0] - 2022-05-31
2
10
 
3
11
  - Replace KazeClient::CompaniesRequest (/api/companies) with KazeClient::PartnersRequest (/api/partners).
4
12
  - Upgrade rubocop.
data/Gemfile CHANGED
@@ -9,4 +9,10 @@ gem 'rake', '~> 13.0'
9
9
 
10
10
  gem 'rspec', '~> 3.0'
11
11
 
12
- gem 'rubocop', '~> 1.7'
12
+ gem 'rubocop', '~> 1.30'
13
+
14
+ gem 'rubocop-rake', '~> 0.6.0'
15
+
16
+ gem 'rubocop-rspec', '~> 2.11.1'
17
+
18
+ gem 'debug', '~> 1.5'
data/Gemfile.lock CHANGED
@@ -1,20 +1,30 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kaze_client (0.1.1)
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/
9
10
  specs:
10
11
  ast (2.4.2)
12
+ debug (1.5.0)
13
+ irb (>= 1.3.6)
14
+ reline (>= 0.2.7)
11
15
  diff-lcs (1.4.4)
12
16
  httparty (0.20.0)
13
17
  mime-types (~> 3.0)
14
18
  multi_xml (>= 0.5.2)
19
+ io-console (0.5.11)
20
+ irb (1.4.1)
21
+ reline (>= 0.3.0)
22
+ jsonpath (1.1.2)
23
+ multi_json
15
24
  mime-types (3.4.1)
16
25
  mime-types-data (~> 3.2015)
17
26
  mime-types-data (3.2022.0105)
27
+ multi_json (1.15.0)
18
28
  multi_xml (0.6.0)
19
29
  parallel (1.22.1)
20
30
  parser (3.1.2.0)
@@ -22,6 +32,8 @@ GEM
22
32
  rainbow (3.1.1)
23
33
  rake (13.0.3)
24
34
  regexp_parser (2.5.0)
35
+ reline (0.3.1)
36
+ io-console (~> 0.5)
25
37
  rexml (3.2.5)
26
38
  rspec (3.10.0)
27
39
  rspec-core (~> 3.10.0)
@@ -47,6 +59,10 @@ GEM
47
59
  unicode-display_width (>= 1.4.0, < 3.0)
48
60
  rubocop-ast (1.18.0)
49
61
  parser (>= 3.1.1.0)
62
+ rubocop-rake (0.6.0)
63
+ rubocop (~> 1.0)
64
+ rubocop-rspec (2.11.1)
65
+ rubocop (~> 1.19)
50
66
  ruby-progressbar (1.11.0)
51
67
  unicode-display_width (2.1.0)
52
68
 
@@ -55,10 +71,13 @@ PLATFORMS
55
71
  x86_64-darwin-20
56
72
 
57
73
  DEPENDENCIES
74
+ debug (~> 1.5)
58
75
  kaze_client!
59
76
  rake (~> 13.0)
60
77
  rspec (~> 3.0)
61
- rubocop (~> 1.7)
78
+ rubocop (~> 1.30)
79
+ rubocop-rake (~> 0.6.0)
80
+ rubocop-rspec (~> 2.11.1)
62
81
 
63
82
  BUNDLED WITH
64
83
  2.2.15
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
@@ -14,9 +14,10 @@ module KazeClient
14
14
  attr_reader :token
15
15
 
16
16
  # @param base_url [String] The server's base URL (e.g. https://app.kaze.so)
17
- def initialize(base_url)
17
+ # @param token [String] The authentication token
18
+ def initialize(base_url, token: nil)
18
19
  @base_url = base_url
19
- @token = nil
20
+ @token = token
20
21
  @login = nil
21
22
  @password = nil
22
23
  end
@@ -66,6 +67,16 @@ module KazeClient
66
67
  response
67
68
  end
68
69
 
70
+ # Set the authentication token
71
+ #
72
+ # @param token [String] The new authentication token
73
+ # @return [KazeClient::Client] The client after assigning the new token
74
+ def with_token(token)
75
+ @token = token
76
+
77
+ self
78
+ end
79
+
69
80
  private
70
81
 
71
82
  # @param request [KazeClient::Request] The request which was executed
@@ -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
@@ -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.1.1p0'
4
+ VERSION = '0.2.1'
5
5
  end
data/lib/kaze_client.rb CHANGED
@@ -4,13 +4,15 @@
4
4
  require 'activesupport/blank'
5
5
  require 'activesupport/camelize'
6
6
 
7
- # Require HTTParty
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.1.1p0
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-05-31 00:00:00.000000000 Z
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
@@ -103,9 +124,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
124
  version: 2.6.0
104
125
  required_rubygems_version: !ruby/object:Gem::Requirement
105
126
  requirements:
106
- - - ">"
127
+ - - ">="
107
128
  - !ruby/object:Gem::Version
108
- version: 1.3.1
129
+ version: '0'
109
130
  requirements: []
110
131
  rubygems_version: 3.0.3.1
111
132
  signing_key: