kaze_client 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +18 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.rubocop.yml +104 -0
- data/CHANGELOG.md +11 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +63 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/kaze_client.gemspec +35 -0
- data/lib/activesupport/blank.rb +155 -0
- data/lib/activesupport/camelize.rb +32 -0
- data/lib/kaze_client/client.rb +99 -0
- data/lib/kaze_client/error/disabled_account.rb +13 -0
- data/lib/kaze_client/error/forbidden.rb +13 -0
- data/lib/kaze_client/error/generic.rb +29 -0
- data/lib/kaze_client/error/internal_server_error.rb +13 -0
- data/lib/kaze_client/error/invalid_credentials.rb +13 -0
- data/lib/kaze_client/error/no_endpoint.rb +19 -0
- data/lib/kaze_client/error/no_private_token.rb +13 -0
- data/lib/kaze_client/error/not_found.rb +13 -0
- data/lib/kaze_client/error/unauthorized.rb +13 -0
- data/lib/kaze_client/errors.rb +12 -0
- data/lib/kaze_client/request/request.rb +113 -0
- data/lib/kaze_client/request/requests/assign_performer_request.rb +23 -0
- data/lib/kaze_client/request/requests/companies_request.rb +19 -0
- data/lib/kaze_client/request/requests/create_job_request.rb +32 -0
- data/lib/kaze_client/request/requests/job_request.rb +17 -0
- data/lib/kaze_client/request/requests/job_workflow_request.rb +25 -0
- data/lib/kaze_client/request/requests/job_workflows_request.rb +19 -0
- data/lib/kaze_client/request/requests/jobs_request.rb +18 -0
- data/lib/kaze_client/request/requests/login_request.rb +28 -0
- data/lib/kaze_client/request/requests/profile_request.rb +17 -0
- data/lib/kaze_client/request/requests/update_template_request.rb +19 -0
- data/lib/kaze_client/request/requests/utils/authentified_request.rb +25 -0
- data/lib/kaze_client/request/requests/utils/final_request.rb +13 -0
- data/lib/kaze_client/request/requests/utils/list_request.rb +120 -0
- data/lib/kaze_client/requests.rb +23 -0
- data/lib/kaze_client/response.rb +34 -0
- data/lib/kaze_client/version.rb +5 -0
- data/lib/kaze_client.rb +17 -0
- metadata +114 -0
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
# @author ciappa_m@modulotech.fr
|
5
|
+
# Execute a KazeClient::Request, stores the server's base URL, the request and the response.
|
6
|
+
# @see KazeClient::Request
|
7
|
+
# @see KazeClient::Response
|
8
|
+
# @since 0.1.0
|
9
|
+
class Client
|
10
|
+
# @return [String] The server's base URL (e.g. https://app.kaze.so)
|
11
|
+
attr_reader :base_url
|
12
|
+
# @return [String,nil] The last authentication token
|
13
|
+
# @see KazeClient::Client#login
|
14
|
+
attr_reader :token
|
15
|
+
|
16
|
+
# @param base_url [String] The server's base URL (e.g. https://app.kaze.som)
|
17
|
+
def initialize(base_url)
|
18
|
+
@base_url = base_url
|
19
|
+
@token = nil
|
20
|
+
@login = nil
|
21
|
+
@password = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
# Execute a request
|
25
|
+
#
|
26
|
+
# If the request needs authentication (meaning it includes KazeClient::Utils::AuthentifiedRequest)
|
27
|
+
# it sets the authentication token.
|
28
|
+
#
|
29
|
+
# @see KazeClient::Client#login
|
30
|
+
# @param request [KazeClient::Request] The request to execute
|
31
|
+
# @return [KazeClient::Response] The response from the server
|
32
|
+
# @raise [KazeClient::Error::NoEndpoint] if the base URL is blank
|
33
|
+
# @raise [KazeClient::Error::Generic] if the response is not a success: not a 2xx HTTP status
|
34
|
+
def execute(request)
|
35
|
+
if request.is_a?(Utils::AuthentifiedRequest) && request.token.nil?
|
36
|
+
login if @token.nil?
|
37
|
+
|
38
|
+
request.with_token(@token)
|
39
|
+
end
|
40
|
+
|
41
|
+
do_execute(request)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Stores the given login and password, stores the token received from authentication.
|
45
|
+
#
|
46
|
+
# @param login [String] The user login.
|
47
|
+
# @param password [String] The user password.
|
48
|
+
# @return [KazeClient::Response] The response from the server
|
49
|
+
# @raise [KazeClient::Error::NoEndpoint] if the base URL is blank
|
50
|
+
# @raise [KazeClient::Error::Generic] if the response is not a success: not a 2xx HTTP status
|
51
|
+
# @see KazeClient::Client#do_execute
|
52
|
+
def login(login = @login, password = @password)
|
53
|
+
# Impossible to login using nil login or password.
|
54
|
+
# The first call to #login must be given a login and a password.
|
55
|
+
raise KazeClient::Error::InvalidCredentials, "Please set login and password" if login.nil? || password.nil?
|
56
|
+
|
57
|
+
request = KazeClient::LoginRequest.new(login: login, password: password)
|
58
|
+
|
59
|
+
response = do_execute(request)
|
60
|
+
|
61
|
+
# Store the token for next request and the login/password for next call
|
62
|
+
@token = response["token"]
|
63
|
+
@login = login
|
64
|
+
@password = password
|
65
|
+
|
66
|
+
response
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
# @param request [KazeClient::Request] The request which was executed
|
72
|
+
# @return [true] if the response is a success: 2xx HTTP status
|
73
|
+
# @raise [KazeClient::Error::Generic] if the response is not a success: not a 2xx HTTP status
|
74
|
+
def handle_errors(request)
|
75
|
+
return true if @response.success?
|
76
|
+
|
77
|
+
raise request.error_for(@response)
|
78
|
+
end
|
79
|
+
|
80
|
+
# @param request [KazeClient::Request] The request to execute
|
81
|
+
# @return [KazeClient::Response] The response from the server
|
82
|
+
# @raise [KazeClient::Error::NoEndpoint] if the base URL is blank
|
83
|
+
# @raise [KazeClient::Error::Generic] if the response is not a success: not a 2xx HTTP status
|
84
|
+
def do_execute(request)
|
85
|
+
raise Error::NoEndpoint, @base_url if @base_url.blank?
|
86
|
+
|
87
|
+
@request = request
|
88
|
+
|
89
|
+
request_url = "#{@base_url}/#{request.url}"
|
90
|
+
@response = HTTParty.send(request.method, request_url, **@request.parameters)
|
91
|
+
|
92
|
+
# This will raise if the response is not a success: not a 2xx HTTP status
|
93
|
+
handle_errors(request)
|
94
|
+
|
95
|
+
# Build the response object from the HTTParty response
|
96
|
+
Response.new(@response)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
module Error
|
5
|
+
# @author ciappa_m@modulotech.fr
|
6
|
+
# 403 error sent by Kaze server when trying to log in with a disabled account
|
7
|
+
class DisabledAccount < Forbidden
|
8
|
+
def initialize(msg = "User account was disabled by administrator")
|
9
|
+
super(msg)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
module Error
|
5
|
+
# @author ciappa_m@modulotech.fr
|
6
|
+
# Generic 403 error sent by Kaze server
|
7
|
+
class Forbidden < Generic
|
8
|
+
def initialize(msg = "403 Forbidden")
|
9
|
+
super(status: :forbidden, message: msg)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
# @since 0.1.0
|
5
|
+
module Error
|
6
|
+
# @author ciappa_m@modulotech.fr
|
7
|
+
# Generic error raised when Kaze server send an unknown error. By default, it is considered
|
8
|
+
# to be an internal server error.
|
9
|
+
class Generic < RuntimeError
|
10
|
+
# @return [Symbol] The HTTP status sent by the server
|
11
|
+
attr_reader :status
|
12
|
+
|
13
|
+
# @return [String] if the server sent a custom error code
|
14
|
+
# @return [Symbol] if the server sent no code, it is the HTTP status sent by the server
|
15
|
+
attr_reader :error
|
16
|
+
|
17
|
+
# The default error message
|
18
|
+
DEFAULT_MESSAGE = "An unknown error occured"
|
19
|
+
|
20
|
+
def initialize(status: :internal_server_error, error: nil,
|
21
|
+
message: DEFAULT_MESSAGE)
|
22
|
+
super(message || DEFAULT_MESSAGE)
|
23
|
+
|
24
|
+
@status = status || :internal_server_error
|
25
|
+
@error = error || @status
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
module Error
|
5
|
+
# @author ciappa_m@modulotech.fr
|
6
|
+
# Generic 500 error sent by Kaze server
|
7
|
+
class InternalServerError < Generic
|
8
|
+
def initialize(msg = "An unknown error occured")
|
9
|
+
super(message: msg)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
module Error
|
5
|
+
# @author ciappa_m@modulotech.fr
|
6
|
+
# 401 error sent by Kaze server when trying to log in with invalid credentials
|
7
|
+
class InvalidCredentials < Unauthorized
|
8
|
+
def initialize(msg = "Invalid Login or Password")
|
9
|
+
super(msg)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
module Error
|
5
|
+
# @author ciappa_m@modulotech.fr
|
6
|
+
# An error raised when the base URL given to the +KazeClient::Client+ is nil
|
7
|
+
# @see KazeClient::Client
|
8
|
+
class NoEndpoint < Generic
|
9
|
+
# @return the given base URL
|
10
|
+
attr_reader :base_url
|
11
|
+
|
12
|
+
def initialize(base_url)
|
13
|
+
super(status: nil, message: "Invalid base url +#{base_url}+", error: nil)
|
14
|
+
|
15
|
+
@base_url = base_url
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
module Error
|
5
|
+
# @author ciappa_m@modulotech.fr
|
6
|
+
# 403 error sent by Kaze server when trying to log in and user has no token
|
7
|
+
class NoPrivateToken < Forbidden
|
8
|
+
def initialize(msg = "User has no private token assigned")
|
9
|
+
super(msg)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
module Error
|
5
|
+
# @author ciappa_m@modulotech.fr
|
6
|
+
# 404 error sent by Kaze server
|
7
|
+
class NotFound < Generic
|
8
|
+
def initialize(msg = "404 Not Found")
|
9
|
+
super(status: :not_found, message: msg)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
module Error
|
5
|
+
# @author ciappa_m@modulotech.fr
|
6
|
+
# Generic 401 error sent by Kaze server
|
7
|
+
class Unauthorized < Generic
|
8
|
+
def initialize(msg = "401 Unauthorized")
|
9
|
+
super(status: :unauthorized, message: msg)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Require the error classes
|
4
|
+
require_relative "error/generic"
|
5
|
+
require_relative "error/unauthorized"
|
6
|
+
require_relative "error/forbidden"
|
7
|
+
require_relative "error/not_found"
|
8
|
+
require_relative "error/internal_server_error"
|
9
|
+
require_relative "error/disabled_account"
|
10
|
+
require_relative "error/invalid_credentials"
|
11
|
+
require_relative "error/no_endpoint"
|
12
|
+
require_relative "error/no_private_token"
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
# @author ciappa_m@modulotech.fr
|
5
|
+
# Represents request to a Kaze API
|
6
|
+
# @see KazeClient::Client
|
7
|
+
# @see KazeClient::Response
|
8
|
+
# @since 0.1.0
|
9
|
+
class Request
|
10
|
+
# Those headers are added on all requests by default
|
11
|
+
DEFAULT_HEADERS = {
|
12
|
+
"Content-Type" => "application/json",
|
13
|
+
"Accept" => "application/json"
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
# @return [String, Symbol] The HTTP verb to use for the request
|
17
|
+
# @example Common HTTP verbs
|
18
|
+
# [:get, :post, :put, :patch, :delete]
|
19
|
+
attr_reader :method
|
20
|
+
|
21
|
+
# @return [String] The API endpoint
|
22
|
+
# @example To get the list of companies
|
23
|
+
# '/api/companies'
|
24
|
+
attr_reader :url
|
25
|
+
|
26
|
+
# @return [nil, Hash] The query parameters for the request
|
27
|
+
# @example Page parameters from KazeClient::Utils::ListRequest
|
28
|
+
# { page: 1, per_page: 20 }
|
29
|
+
attr_accessor :query
|
30
|
+
|
31
|
+
# @return [nil, Hash, String] The body for the request
|
32
|
+
# @example Login data from KazeClient::LoginRequest
|
33
|
+
# { user: { login: 'test', password: 'test' } }
|
34
|
+
# "{\"user\":{\"login\":\"test\",\"password\":\"test\"}}"
|
35
|
+
attr_accessor :body
|
36
|
+
|
37
|
+
# @return [nil, Hash] The headers for the request
|
38
|
+
# @example Default headers from any KazeClient::Request
|
39
|
+
# { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
|
40
|
+
attr_accessor :headers
|
41
|
+
|
42
|
+
# @param method [Symbol] The HTTP verb to use for the request (e.g. :get)
|
43
|
+
# @param url [String] The API endpoint (e.g. /jobs)
|
44
|
+
def initialize(method, url)
|
45
|
+
@method = method
|
46
|
+
@url = url
|
47
|
+
@query = nil
|
48
|
+
@body = nil
|
49
|
+
@headers = {}
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [Hash] The arguments to give to the HTTParty call
|
53
|
+
# @example For instance, when +@body+ is blank
|
54
|
+
# {
|
55
|
+
# query: { page: 1, per_page: 20 },
|
56
|
+
# headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
|
57
|
+
# }
|
58
|
+
def parameters
|
59
|
+
{
|
60
|
+
query: make_query, body: make_body, headers: make_headers
|
61
|
+
}.reject { |_k, v| v.blank? }
|
62
|
+
end
|
63
|
+
|
64
|
+
# @param response [HTTParty::Response] The response object from HTTParty call
|
65
|
+
# @return [KazeClient::Error::Generic] The adequate error object according to the given response
|
66
|
+
def error_for(response)
|
67
|
+
# Not found is handled in a specific way since there is no message key and the error has a
|
68
|
+
# specific format
|
69
|
+
return KazeClient::Error::NotFound.new if response.code == 404
|
70
|
+
|
71
|
+
# Return the adequate error class for the error code in the response
|
72
|
+
"KazeClient::Error::#{response.parsed_response["error"].camelize}"
|
73
|
+
.constantize.new(response.parsed_response["message"])
|
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"])
|
80
|
+
end
|
81
|
+
|
82
|
+
protected
|
83
|
+
|
84
|
+
# @return [Hash] The headers for the request
|
85
|
+
# If +@headers+ is blank or is not a Hash, it returns the +DEFAULT_HEADERS+. Else it merges
|
86
|
+
# the +DEFAULT_HEADERS+ with +@headers+ allowing +@headers+ to override +DEFAULT_HEADERS+.
|
87
|
+
def make_headers
|
88
|
+
return DEFAULT_HEADERS if @headers.blank? || !@headers.is_a?(Hash)
|
89
|
+
|
90
|
+
DEFAULT_HEADERS.merge(@headers)
|
91
|
+
end
|
92
|
+
|
93
|
+
# @return [nil, String] The body for the request
|
94
|
+
# +String+ will be sent as-is while +Hash+ will be transformed to a JSON string.
|
95
|
+
def make_body
|
96
|
+
return nil if @body.blank?
|
97
|
+
|
98
|
+
case @body
|
99
|
+
when String
|
100
|
+
@body
|
101
|
+
when Hash
|
102
|
+
@body.to_json
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# @return [nil, Hash] The query parameters for the request
|
107
|
+
def make_query
|
108
|
+
return nil if @query.blank?
|
109
|
+
|
110
|
+
@query
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
# @author ciappa_m@modulotech.fr
|
5
|
+
# Assign a performer to the given job.
|
6
|
+
# @see KazeClient::Request
|
7
|
+
# @see KazeClient::Utils::FinalRequest
|
8
|
+
# @see KazeClient::Utils::AuthentifiedRequest
|
9
|
+
# @since 0.1.0
|
10
|
+
class AssignPerformerRequest < Utils::FinalRequest
|
11
|
+
include Utils::AuthentifiedRequest
|
12
|
+
|
13
|
+
def initialize(id, performer_user_id)
|
14
|
+
super(:post, "api/jobs/#{id}/performers")
|
15
|
+
|
16
|
+
@body = {
|
17
|
+
job: {
|
18
|
+
performer_user_id: performer_user_id.to_s
|
19
|
+
}
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
# @author ciappa_m@modulotech.fr
|
5
|
+
# Request the list of companies.
|
6
|
+
# @see KazeClient::Request
|
7
|
+
# @see KazeClient::Utils::FinalRequest
|
8
|
+
# @see KazeClient::Utils::AuthentifiedRequest
|
9
|
+
# @see KazeClient::Utils::ListRequest
|
10
|
+
# @since 0.1.0
|
11
|
+
class CompaniesRequest < Utils::FinalRequest
|
12
|
+
include Utils::AuthentifiedRequest
|
13
|
+
include Utils::ListRequest
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
super(:get, "api/companies")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
# @author ciappa_m@modulotech.fr
|
5
|
+
# Create a job from the current user to the target company.
|
6
|
+
# @see KazeClient::Request
|
7
|
+
# @see KazeClient::Utils::FinalRequest
|
8
|
+
# @see KazeClient::Utils::AuthentifiedRequest
|
9
|
+
# @since 0.1.0
|
10
|
+
class CreateJobRequest < Utils::FinalRequest
|
11
|
+
include Utils::AuthentifiedRequest
|
12
|
+
|
13
|
+
# @return [String] The id of the target company.
|
14
|
+
attr_reader :target_id
|
15
|
+
|
16
|
+
# @return [Hash] The workflow used to create the job.
|
17
|
+
attr_reader :workflow
|
18
|
+
|
19
|
+
# @param target_id [String] The id of the target company.
|
20
|
+
# @param workflow [Hash] The workflow to use to create the job.
|
21
|
+
def initialize(target_id, workflow)
|
22
|
+
super(:post, "api/jobs")
|
23
|
+
|
24
|
+
@target_id = target_id
|
25
|
+
@workflow = workflow
|
26
|
+
@body = {
|
27
|
+
target_id: @target_id,
|
28
|
+
workflow: @workflow
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
# @author ciappa_m@modulotech.fr
|
5
|
+
# Fetch the details for the given job id.
|
6
|
+
# @see KazeClient::Request
|
7
|
+
# @see KazeClient::Utils::FinalRequest
|
8
|
+
# @see KazeClient::Utils::AuthentifiedRequest
|
9
|
+
# @since 0.1.0
|
10
|
+
class JobRequest < Utils::FinalRequest
|
11
|
+
include Utils::AuthentifiedRequest
|
12
|
+
|
13
|
+
def initialize(id)
|
14
|
+
super(:get, "api/jobs/#{id}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
# @author ciappa_m@modulotech.fr
|
5
|
+
# Request the details about a specific workflow.
|
6
|
+
# @see KazeClient::Request
|
7
|
+
# @see KazeClient::Utils::FinalRequest
|
8
|
+
# @see KazeClient::Utils::AuthentifiedRequest
|
9
|
+
# @since 0.1.0
|
10
|
+
class JobWorkflowRequest < Utils::FinalRequest
|
11
|
+
include Utils::AuthentifiedRequest
|
12
|
+
|
13
|
+
# @return [String] The id of the workflow to request
|
14
|
+
attr_reader :id
|
15
|
+
|
16
|
+
# @param id [String] Set the id of the workflow to request
|
17
|
+
def initialize(id)
|
18
|
+
super(:get, "api/job_workflows/#{id}")
|
19
|
+
|
20
|
+
@id = id
|
21
|
+
@query = {}
|
22
|
+
@filters = {}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
# @author ciappa_m@modulotech.fr
|
5
|
+
# Request the list of job workflows for the current user.
|
6
|
+
# @see KazeClient::Request
|
7
|
+
# @see KazeClient::Utils::FinalRequest
|
8
|
+
# @see KazeClient::Utils::AuthentifiedRequest
|
9
|
+
# @see KazeClient::Utils::ListRequest
|
10
|
+
# @since 0.1.0
|
11
|
+
class JobWorkflowsRequest < Utils::FinalRequest
|
12
|
+
include Utils::AuthentifiedRequest
|
13
|
+
include Utils::ListRequest
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
super(:get, "api/job_workflows")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
# @author ciappa_m@modulotech.fr
|
5
|
+
# List the jobs assigned to the current user's company.
|
6
|
+
# @see KazeClient::Request
|
7
|
+
# @see KazeClient::Utils::FinalRequest
|
8
|
+
# @see KazeClient::Utils::AuthentifiedRequest
|
9
|
+
# @since 0.1.0
|
10
|
+
class JobsRequest < Utils::FinalRequest
|
11
|
+
include Utils::AuthentifiedRequest
|
12
|
+
include Utils::ListRequest
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
super(:get, "api/jobs")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
# @author ciappa_m@modulotech.fr
|
5
|
+
# Authenticate a user on the server.
|
6
|
+
# @see KazeClient::Request
|
7
|
+
# @see KazeClient::Utils::FinalRequest
|
8
|
+
# @since 0.1.0
|
9
|
+
class LoginRequest < Utils::FinalRequest
|
10
|
+
# @return [String] The user login.
|
11
|
+
attr_reader :login
|
12
|
+
|
13
|
+
# @param login [String] The user login.
|
14
|
+
# @param password [String] The user password.
|
15
|
+
def initialize(login:, password:)
|
16
|
+
super(:post, "api/login")
|
17
|
+
|
18
|
+
@login = login
|
19
|
+
@password = password
|
20
|
+
@body = {
|
21
|
+
user: {
|
22
|
+
login: @login,
|
23
|
+
password: @password
|
24
|
+
}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
# @author ciappa_m@modulotech.fr
|
5
|
+
# Request data about the current user.
|
6
|
+
# @see KazeClient::Request
|
7
|
+
# @see KazeClient::Utils::FinalRequest
|
8
|
+
# @see KazeClient::Utils::AuthentifiedRequest
|
9
|
+
# @since 0.1.0
|
10
|
+
class ProfileRequest < Utils::FinalRequest
|
11
|
+
include Utils::AuthentifiedRequest
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
super(:get, "api/profile")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
# @author ciappa_m@modulotech.fr
|
5
|
+
# Update data of the given template on the given job.
|
6
|
+
# @see KazeClient::Request
|
7
|
+
# @see KazeClient::Utils::FinalRequest
|
8
|
+
# @see KazeClient::Utils::AuthentifiedRequest
|
9
|
+
# @since 0.1.0
|
10
|
+
class UpdateTemplateRequest < Utils::FinalRequest
|
11
|
+
include Utils::AuthentifiedRequest
|
12
|
+
|
13
|
+
def initialize(id, template_id, body)
|
14
|
+
super(:put, "api/performer/jobs/#{id}/templates/#{template_id}")
|
15
|
+
|
16
|
+
@body = body
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
# @since 0.1.0
|
5
|
+
module Utils
|
6
|
+
# @author ciappa_m@modulotech.fr
|
7
|
+
# Included by the request where an authentication token is required.
|
8
|
+
# @see KazeClient::Request
|
9
|
+
module AuthentifiedRequest
|
10
|
+
# @return [String] The authentication token
|
11
|
+
attr_reader :token
|
12
|
+
|
13
|
+
# Store the given authentication token and use it to set the +Authorization+ header of the
|
14
|
+
# request.
|
15
|
+
# @param token [String] The authentication token
|
16
|
+
# @return [KazeClient::Utils::AuthentifiedRequest] self (to chain methods)
|
17
|
+
def with_token(token)
|
18
|
+
@token = token
|
19
|
+
@headers["Authorization"] = token
|
20
|
+
|
21
|
+
self
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KazeClient
|
4
|
+
module Utils
|
5
|
+
# @author ciappa_m@modulotech.fr
|
6
|
+
# Set the request as final, disabling the edition of query parameters, headers and request body.
|
7
|
+
# @see KazeClient::Request
|
8
|
+
class FinalRequest < Request
|
9
|
+
# Remove write access inherited from Request
|
10
|
+
undef_method :query=, :body=, :headers=
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|