allq_rest 1.5.1 → 2.0.0

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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +36 -97
  3. data/lib/allq_rest/client.rb +168 -0
  4. data/lib/allq_rest/configuration.rb +7 -192
  5. data/lib/allq_rest/errors.rb +17 -0
  6. data/lib/allq_rest/job.rb +10 -0
  7. data/lib/allq_rest/version.rb +2 -14
  8. data/lib/allq_rest.rb +21 -46
  9. data/swagger.yaml +706 -0
  10. metadata +32 -115
  11. data/Gemfile +0 -7
  12. data/Gemfile.lock +0 -42
  13. data/Rakefile +0 -8
  14. data/allq_rest-1.2.92.gem +0 -0
  15. data/allq_rest-1.2.93.gem +0 -0
  16. data/allq_rest-1.3.0.gem +0 -0
  17. data/allq_rest-1.4.0.gem +0 -0
  18. data/allq_rest-1.5.0.gem +0 -0
  19. data/allq_rest.gemspec +0 -28
  20. data/deploy.sh +0 -4
  21. data/docs/ActionsApi.md +0 -544
  22. data/docs/AdminApi.md +0 -98
  23. data/docs/BasicPayload.md +0 -11
  24. data/docs/BasicResponse.md +0 -8
  25. data/docs/JobRef.md +0 -8
  26. data/docs/JobResponse.md +0 -12
  27. data/docs/NewJob.md +0 -13
  28. data/docs/NewParentJob.md +0 -16
  29. data/docs/StatsInfo.md +0 -9
  30. data/docs/StatsResults.md +0 -10
  31. data/docs/StatsTube.md +0 -14
  32. data/docs/Throttle.md +0 -9
  33. data/docs/TubeRef.md +0 -8
  34. data/git_push.sh +0 -55
  35. data/lib/.DS_Store +0 -0
  36. data/lib/allq_rest/.DS_Store +0 -0
  37. data/lib/allq_rest/api/actions_api.rb +0 -763
  38. data/lib/allq_rest/api/admin_api.rb +0 -181
  39. data/lib/allq_rest/api_client.rb +0 -395
  40. data/lib/allq_rest/api_error.rb +0 -38
  41. data/lib/allq_rest/models/basic_payload.rb +0 -218
  42. data/lib/allq_rest/models/basic_response.rb +0 -188
  43. data/lib/allq_rest/models/job_ref.rb +0 -190
  44. data/lib/allq_rest/models/job_response.rb +0 -260
  45. data/lib/allq_rest/models/multiple_job_response.rb +0 -187
  46. data/lib/allq_rest/models/new_job.rb +0 -281
  47. data/lib/allq_rest/models/new_parent_job.rb +0 -302
  48. data/lib/allq_rest/models/stats_info.rb +0 -204
  49. data/lib/allq_rest/models/stats_results.rb +0 -254
  50. data/lib/allq_rest/models/stats_tube.rb +0 -306
  51. data/lib/allq_rest/models/throttle.rb +0 -209
  52. data/lib/allq_rest/models/tube_ref.rb +0 -190
  53. data/spec/.DS_Store +0 -0
  54. data/spec/api/actions_api_spec.rb +0 -600
  55. data/spec/api/admin_api_spec.rb +0 -58
  56. data/spec/api_client_spec.rb +0 -226
  57. data/spec/configuration_spec.rb +0 -42
  58. data/spec/models/basic_payload_spec.rb +0 -60
  59. data/spec/models/basic_response_spec.rb +0 -42
  60. data/spec/models/job_ref_spec.rb +0 -42
  61. data/spec/models/job_response_spec.rb +0 -66
  62. data/spec/models/new_job_spec.rb +0 -72
  63. data/spec/models/new_parent_job_spec.rb +0 -90
  64. data/spec/models/stats_info_spec.rb +0 -48
  65. data/spec/models/stats_results_spec.rb +0 -54
  66. data/spec/models/stats_tube_spec.rb +0 -78
  67. data/spec/models/throttle_spec.rb +0 -48
  68. data/spec/models/tube_ref_spec.rb +0 -42
  69. data/spec/spec_helper.rb +0 -113
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82bbdad947580e4ceaf457cf1b9ea1c32d4cf9e73ff709bea1392ad680c761b6
4
- data.tar.gz: 120732961079ccc2f9184f60d60f849fe53ac079d2d5e91a430ecdd228e34f40
3
+ metadata.gz: f237495ec29771f455f538f5fe0b82eab37abb3bf04d11695a740ac058028b49
4
+ data.tar.gz: ae9a98521bca374962d4ee51210a4bedb29ab2d06ee9f54eb88d584cb940163f
5
5
  SHA512:
6
- metadata.gz: a4c93bf763048574c9afc6eecc4ead8115b2f4f5145950ebcb5ea745e8e53c6e6b244adf18f22440d6c458734b536eab644f8071c922043747c9f7ea1660162d
7
- data.tar.gz: 0c201c4606699e2096d1dffcfccbe7f8e243aaa96da958a45c23a22dbad6773e2af8f8f6e1e23a5550644cbfdc3cb90d615810222c9d11f060d85df56eb64e3a
6
+ metadata.gz: c4917a882fcbf25bec3c3c02f0eaf694cdaaf7389ca51f6b98343f9e8b5042b470dd5e6118d26380c09243868705457bac61be74b9ec49e3fd7a43d3e0e7b381
7
+ data.tar.gz: 9a8b3763639df7770c43ff2e8ba892cd45820fd58573edeb58615684675e930895472a3b7abb0db4302f388735b6c6620a1b90c8eb53d9898c11256dac84987f
data/README.md CHANGED
@@ -1,111 +1,50 @@
1
1
  # allq_rest
2
2
 
3
- Allq - the Ruby gem for the AllQ
3
+ Ruby client for the [AllQ](swagger.yaml) job queue HTTP API. AllQ is self-hosted, so the server URL is configurable.
4
4
 
5
- No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
6
-
7
- This SDK is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
8
-
9
- - API version: 1.0
10
- - Package version: 1.0.0
11
- - Build package: io.swagger.codegen.languages.RubyClientCodegen
12
-
13
- ## Installation
14
-
15
- ### Build a gem
16
-
17
- To build the Ruby code into a gem:
18
-
19
- ```shell
20
- gem build allq_rest.gemspec
21
- ```
22
-
23
- Then either install the gem locally:
24
-
25
- ```shell
26
- gem install ./allq_rest-1.0.0.gem
27
- ```
28
- (for development, run `gem install --dev ./allq_rest-1.0.0.gem` to install the development dependencies)
29
-
30
- or publish the gem to a gem hosting service, e.g. [RubyGems](https://rubygems.org/).
31
-
32
- Finally add this to the Gemfile:
33
-
34
- gem 'allq_rest', '~> 1.0.0'
35
-
36
- ### Install from Git
37
-
38
- If the Ruby gem is hosted at a git repository: https://github.com/YOUR_GIT_USERNAME/YOUR_GIT_REPO, then add the following in the Gemfile:
39
-
40
- gem 'allq_rest', :git => 'https://github.com/YOUR_GIT_USERNAME/YOUR_GIT_REPO.git'
41
-
42
- ### Include the Ruby code directly
43
-
44
- Include the Ruby code directly using `-I` as follows:
45
-
46
- ```shell
47
- ruby -Ilib script.rb
5
+ ```ruby
6
+ gem "allq_rest"
48
7
  ```
49
8
 
50
- ## Getting Started
9
+ ## Configure
51
10
 
52
- Please follow the [installation](#installation) procedure and then run the following code:
53
11
  ```ruby
54
- # Load the gem
55
- require 'allq_rest'
56
-
57
- api_instance = Allq::ActionsApi.new
58
-
59
- job_id = "job_id_example" # String | Job ID
60
-
61
-
62
- begin
63
- #Bury
64
- result = api_instance.bury_put(job_id)
65
- p result
66
- rescue Allq::ApiError => e
67
- puts "Exception when calling ActionsApi->bury_put: #{e}"
12
+ AllqRest.configure do |c|
13
+ c.url = "http://allq.internal:8090" # default: ENV["ALLQ_URL"] or http://localhost:8090
14
+ c.timeout = 30
15
+ c.headers = { "Authorization" => "Bearer ..." } # optional
68
16
  end
69
-
17
+ client = AllqRest.client # shared client
18
+ # or an independent one:
19
+ client = AllqRest::Client.new(url: "http://other:8090")
70
20
  ```
71
21
 
72
- ## Documentation for API Endpoints
73
-
74
- All URIs are relative to *http://localhost:8090*
75
-
76
- Class | Method | HTTP request | Description
77
- ------------ | ------------- | ------------- | -------------
78
- *Allq::ActionsApi* | [**bury_put**](docs/ActionsApi.md#bury_put) | **PUT** /bury | Bury
79
- *Allq::ActionsApi* | [**job_delete**](docs/ActionsApi.md#job_delete) | **DELETE** /job | Delete
80
- *Allq::ActionsApi* | [**job_get**](docs/ActionsApi.md#job_get) | **GET** /job | Job
81
- *Allq::ActionsApi* | [**job_post**](docs/ActionsApi.md#job_post) | **POST** /job | Job
82
- *Allq::ActionsApi* | [**parent_job_post**](docs/ActionsApi.md#parent_job_post) | **POST** /parent_job | Parent Job
83
- *Allq::ActionsApi* | [**peek_get**](docs/ActionsApi.md#peek_get) | **GET** /peek | Peek
84
- *Allq::ActionsApi* | [**release_put**](docs/ActionsApi.md#release_put) | **PUT** /release | Release
85
- *Allq::ActionsApi* | [**set_children_started_put**](docs/ActionsApi.md#set_children_started_put) | **PUT** /set_children_started | Set Children Started
86
- *Allq::ActionsApi* | [**throttle_post**](docs/ActionsApi.md#throttle_post) | **POST** /throttle | Throttle
87
- *Allq::ActionsApi* | [**touch_put**](docs/ActionsApi.md#touch_put) | **PUT** /touch | Touch
88
- *Allq::ActionsApi* | [**tube_delete**](docs/ActionsApi.md#tube_delete) | **DELETE** /tube | Clear Tube
89
- *Allq::AdminApi* | [**stats_get**](docs/AdminApi.md#stats_get) | **GET** /stats | Stats
90
- *Allq::AdminApi* | [**update_servers_put**](docs/AdminApi.md#update_servers_put) | **PUT** /update_servers | Reset Server Urls
91
-
92
-
93
- ## Documentation for Models
94
-
95
- - [Allq::BasicPayload](docs/BasicPayload.md)
96
- - [Allq::BasicResponse](docs/BasicResponse.md)
97
- - [Allq::JobRef](docs/JobRef.md)
98
- - [Allq::JobResponse](docs/JobResponse.md)
99
- - [Allq::NewJob](docs/NewJob.md)
100
- - [Allq::NewParentJob](docs/NewParentJob.md)
101
- - [Allq::StatsInfo](docs/StatsInfo.md)
102
- - [Allq::StatsResults](docs/StatsResults.md)
103
- - [Allq::StatsTube](docs/StatsTube.md)
104
- - [Allq::Throttle](docs/Throttle.md)
105
- - [Allq::TubeRef](docs/TubeRef.md)
22
+ ## Usage
106
23
 
24
+ ```ruby
25
+ id = client.put_job(tube: "emails", body: { to: "a@b.c" }.to_json, ttl: 600, priority: 3)
26
+ job = client.get_job("emails") # AllqRest::Job or nil
27
+ client.touch(job.id) # extend the reservation
28
+ client.release(job.id, delay: 30) # put back
29
+ client.bury(job.id)
30
+ client.delete_job(job.id) # finished
31
+
32
+ client.get_jobs("emails", count: 10, delete: true)
33
+ client.peek("emails") # ready (default)
34
+ client.peek("emails", buried: true) # or reserved: true / parent: true (only one)
35
+
36
+ parent = client.put_parent_job(tube: "reports", body: "merge", limit: 3)
37
+ client.put_job(tube: "reports", body: "part", parent_id: parent)
38
+ client.set_children_started(parent) # if the child count wasn't known up front
39
+
40
+ client.pause("emails"); client.resume("emails")
41
+ client.throttle("emails", tps: 50)
42
+ client.kick("emails"); client.clear_tube("emails")
43
+ client.stats; client.drain(server_id); client.update_servers(%w[http://a:8090 http://b:8090])
44
+ ```
107
45
 
108
- ## Documentation for Authorization
46
+ Errors: `AllqRest::ConnectionError` (unreachable/timeout), `AllqRest::ApiError` (non-2xx or error in the response payload; has `#status`, `#body`).
109
47
 
110
- All endpoints do not require authorization.
48
+ ## Development
111
49
 
50
+ `bundle install && bundle exec rake`
@@ -0,0 +1,168 @@
1
+ require "faraday"
2
+ require "json"
3
+
4
+ module AllqRest
5
+ class Client
6
+ attr_reader :url
7
+
8
+ # @param url [String] base URL of the AllQ server (default: AllqRest.config.url / ENV["ALLQ_URL"])
9
+ # @param adapter [Symbol, Array] optional Faraday adapter (used by tests)
10
+ def initialize(url: nil, timeout: nil, open_timeout: nil, headers: nil, adapter: nil, &block)
11
+ cfg = AllqRest.config
12
+ @url = (url || cfg.url).to_s.chomp("/")
13
+ @conn = Faraday.new(url: @url) do |f|
14
+ f.headers.update(cfg.headers).update(headers || {})
15
+ f.headers["Accept"] = "application/json"
16
+ f.options.timeout = timeout || cfg.timeout
17
+ f.options.open_timeout = open_timeout || cfg.open_timeout
18
+ block&.call(f)
19
+ adapter ? f.adapter(*adapter) : f.adapter(Faraday.default_adapter)
20
+ end
21
+ end
22
+
23
+ # ---- Jobs -------------------------------------------------------------
24
+
25
+ # Put a job into a tube. Returns the new job id (String).
26
+ def put_job(body:, tube: "default", ttl: 1200, delay: 0, priority: 5, parent_id: nil, shard_key: nil)
27
+ payload = { tube: tube, body: body.to_s, ttl: ttl, delay: delay, priority: priority,
28
+ parent_id: parent_id, shard_key: shard_key }.compact
29
+ request(:post, "/job", body: payload)["job_id"]
30
+ end
31
+
32
+ # Get the next job from a tube. Returns AllqRest::Job or nil if the tube is empty.
33
+ # With delete: true the job is removed as it is fetched.
34
+ def get_job(tube, delete: false)
35
+ Job.from_hash(request(:get, "/job", query: { tube: tube, delete: delete ? "true" : nil }))
36
+ end
37
+
38
+ # Get up to `count` jobs. Returns an Array of AllqRest::Job.
39
+ def get_jobs(tube, count:, delete: false)
40
+ res = request(:get, "/multiple_job",
41
+ query: { tube: tube, count: count, delete: delete ? "true" : nil })
42
+ Array(res["jobs"]).map { |j| Job.from_hash(j) }.compact
43
+ end
44
+
45
+ # Peek at a job without reserving it. Returns AllqRest::Job or nil.
46
+ # Looks in ready jobs by default; pass at most one of buried:, reserved:
47
+ # or parent: (true) to look in that set instead.
48
+ def peek(tube, buried: false, reserved: false, parent: false, offset: 0)
49
+ if [buried, reserved, parent].count { |f| f } > 1
50
+ raise ArgumentError, "peek accepts only one of buried:, reserved:, parent:"
51
+ end
52
+ query = { tube: tube, offset: offset.to_s,
53
+ buried: ("true" if buried), reserved: ("true" if reserved), parent: ("true" if parent) }
54
+ Job.from_hash(request(:get, "/peek", query: query))
55
+ end
56
+
57
+ # Mark a job finished. Pass tube: to delete a job that is still "ready".
58
+ def delete_job(job_id, tube: nil)
59
+ basic(:delete, "/job", job_id: job_id, tube: tube)
60
+ end
61
+
62
+ def release(job_id, delay: nil)
63
+ basic(:put, "/release", job_id: job_id, delay: delay)
64
+ end
65
+
66
+ def touch(job_id)
67
+ basic(:put, "/touch", job_id: job_id)
68
+ end
69
+
70
+ def bury(job_id)
71
+ basic(:put, "/bury", job_id: job_id)
72
+ end
73
+
74
+ # ---- Parent jobs ------------------------------------------------------
75
+
76
+ # Create a parent job (a job that runs once its children are done).
77
+ # Accepts everything put_job does, plus timeout:, run_on_timeout:, limit: (number of children).
78
+ # Returns the new job id.
79
+ def put_parent_job(body:, tube: "default", ttl: 1200, delay: 0, priority: 5, parent_id: nil,
80
+ shard_key: nil, timeout: nil, run_on_timeout: nil, limit: nil)
81
+ payload = { tube: tube, body: body.to_s, ttl: ttl, delay: delay, priority: priority,
82
+ parent_id: parent_id, shard_key: shard_key, timeout: timeout,
83
+ run_on_timeout: run_on_timeout, limit: limit }.compact
84
+ request(:post, "/parent_job", body: payload)["job_id"]
85
+ end
86
+
87
+ # Used when the number of children wasn't known up front.
88
+ def set_children_started(job_id, force_now: false)
89
+ basic(:put, "/set_children_started", job_id: job_id, force_now: force_now ? "true" : nil)
90
+ end
91
+
92
+ # ---- Tubes ------------------------------------------------------------
93
+
94
+ # Kick buried jobs in a tube back to ready.
95
+ def kick(tube)
96
+ basic(:put, "/kick", tube: tube)
97
+ end
98
+
99
+ # Delete all contents of a tube.
100
+ def clear_tube(tube)
101
+ basic(:delete, "/tube", tube: tube)
102
+ end
103
+
104
+ # Pause (stopped: true) or resume (stopped: false) a tube. Returns the tube name.
105
+ def pause(tube, stopped: true)
106
+ request(:put, "/pause", query: { tube: tube }, body: { tube: tube, stopped: stopped })["tube"]
107
+ end
108
+
109
+ def resume(tube)
110
+ pause(tube, stopped: false)
111
+ end
112
+
113
+ # Limit a tube to `tps` transactions per second. Returns the tube name.
114
+ def throttle(tube, tps:)
115
+ request(:post, "/throttle", body: { tube: tube, tps: tps })["tube"]
116
+ end
117
+
118
+ # ---- Admin ------------------------------------------------------------
119
+
120
+ # Per-server stats: Array of hashes (server_name, stats, action_count, job_put, job_get).
121
+ def stats
122
+ request(:get, "/stats")
123
+ end
124
+
125
+ def drain(server_id)
126
+ basic(:put, "/drain", server_id: server_id)
127
+ end
128
+
129
+ # urls: Array or comma separated String
130
+ def update_servers(urls)
131
+ basic(:put, "/update_servers", server_urls: Array(urls).join(","))
132
+ end
133
+
134
+ private
135
+
136
+ # Calls an endpoint returning BasicResponse and raises if the payload carries an error.
137
+ def basic(method, path, params)
138
+ res = request(method, path, query: params)
139
+ payload = res.is_a?(Hash) ? res["response"] : nil
140
+ if payload.is_a?(Hash) && payload["error"] && !payload["error"].to_s.empty?
141
+ raise ApiError.new(payload["error"].to_s, body: res)
142
+ end
143
+ payload || res
144
+ end
145
+
146
+ def request(method, path, query: nil, body: nil)
147
+ query = query&.reject { |_, v| v.nil? }
148
+ resp = @conn.run_request(method, path, body && JSON.generate(body),
149
+ body ? { "Content-Type" => "application/json" } : nil) do |req|
150
+ req.params.update(query) if query && !query.empty?
151
+ end
152
+ parse(resp)
153
+ rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
154
+ raise ConnectionError, "Could not reach AllQ at #{@url}: #{e.message}"
155
+ end
156
+
157
+ def parse(resp)
158
+ data = resp.body.to_s.strip.empty? ? {} : JSON.parse(resp.body)
159
+ unless resp.success?
160
+ msg = data.is_a?(Hash) && (data["error"] || data["message"]) || "HTTP #{resp.status}"
161
+ raise ApiError.new(msg.to_s, status: resp.status, body: data)
162
+ end
163
+ data
164
+ rescue JSON::ParserError
165
+ raise ApiError.new("Invalid JSON from server (HTTP #{resp.status})", status: resp.status, body: resp.body)
166
+ end
167
+ end
168
+ end
@@ -1,199 +1,14 @@
1
- =begin
2
- #AllQ
3
-
4
- #No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
5
-
6
- OpenAPI spec version: 1.0
7
-
8
- Generated by: https://github.com/swagger-api/swagger-codegen.git
9
- Swagger Codegen version: 2.4.2
10
-
11
- =end
12
-
13
- module Allq
1
+ module AllqRest
14
2
  class Configuration
15
- # Defines url scheme
16
- attr_accessor :scheme
17
-
18
- # Defines url host
19
- attr_accessor :host
20
-
21
- # Defines url base path
22
- attr_accessor :base_path
23
-
24
- # Defines API keys used with API Key authentications.
25
- #
26
- # @return [Hash] key: parameter name, value: parameter value (API key)
27
- #
28
- # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
29
- # config.api_key['api_key'] = 'xxx'
30
- attr_accessor :api_key
31
-
32
- # Defines API key prefixes used with API Key authentications.
33
- #
34
- # @return [Hash] key: parameter name, value: API key prefix
35
- #
36
- # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
37
- # config.api_key_prefix['api_key'] = 'Token'
38
- attr_accessor :api_key_prefix
39
-
40
- # Defines the username used with HTTP basic authentication.
41
- #
42
- # @return [String]
43
- attr_accessor :username
44
-
45
- # Defines the password used with HTTP basic authentication.
46
- #
47
- # @return [String]
48
- attr_accessor :password
49
-
50
- # Defines the access token (Bearer) used with OAuth2.
51
- attr_accessor :access_token
52
-
53
- # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
54
- # details will be logged with `logger.debug` (see the `logger` attribute).
55
- # Default to false.
56
- #
57
- # @return [true, false]
58
- attr_accessor :debugging
59
-
60
- # Defines the logger used for debugging.
61
- # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
62
- #
63
- # @return [#debug]
64
- attr_accessor :logger
65
-
66
- # Defines the temporary folder to store downloaded files
67
- # (for API endpoints that have file response).
68
- # Default to use `Tempfile`.
69
- #
70
- # @return [String]
71
- attr_accessor :temp_folder_path
72
-
73
- # The time limit for HTTP request in seconds.
74
- # Default to 0 (never times out).
75
- attr_accessor :timeout
76
-
77
- # Set this to false to skip client side validation in the operation.
78
- # Default to true.
79
- # @return [true, false]
80
- attr_accessor :client_side_validation
81
-
82
- ### TLS/SSL setting
83
- # Set this to false to skip verifying SSL certificate when calling API from https server.
84
- # Default to true.
85
- #
86
- # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
87
- #
88
- # @return [true, false]
89
- attr_accessor :verify_ssl
90
-
91
- ### TLS/SSL setting
92
- # Set this to false to skip verifying SSL host name
93
- # Default to true.
94
- #
95
- # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
96
- #
97
- # @return [true, false]
98
- attr_accessor :verify_ssl_host
99
-
100
- ### TLS/SSL setting
101
- # Set this to customize the certificate file to verify the peer.
102
- #
103
- # @return [String] the path to the certificate file
104
- #
105
- # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
106
- # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
107
- attr_accessor :ssl_ca_cert
108
-
109
- ### TLS/SSL setting
110
- # Client certificate file (for client certificate)
111
- attr_accessor :cert_file
3
+ DEFAULT_URL = "http://localhost:8090".freeze
112
4
 
113
- ### TLS/SSL setting
114
- # Client private key file (for client certificate)
115
- attr_accessor :key_file
116
-
117
- # Set this to customize parameters encoding of array parameter with multi collectionFormat.
118
- # Default to nil.
119
- #
120
- # @see The params_encoding option of Ethon. Related source code:
121
- # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
122
- attr_accessor :params_encoding
123
-
124
- attr_accessor :inject_format
125
-
126
- attr_accessor :force_ending_format
5
+ attr_accessor :url, :timeout, :open_timeout, :headers
127
6
 
128
7
  def initialize
129
- @scheme = 'http'
130
- @host = 'localhost:8090'
131
- @base_path = '/'
132
- @api_key = {}
133
- @api_key_prefix = {}
134
- @timeout = 0
135
- @client_side_validation = true
136
- @verify_ssl = true
137
- @verify_ssl_host = true
138
- @params_encoding = nil
139
- @cert_file = nil
140
- @key_file = nil
141
- @debugging = false
142
- @inject_format = false
143
- @force_ending_format = false
144
- @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
145
- yield(self) if block_given?
146
- end
147
-
148
- # The default Configuration object.
149
- def self.default
150
- @@default ||= Configuration.new
151
- end
152
-
153
- def configure
154
- yield(self) if block_given?
155
- end
156
-
157
- def scheme=(scheme)
158
- # remove :// from scheme
159
- @scheme = scheme.sub(/:\/\//, '')
160
- end
161
-
162
- def host=(host)
163
- # remove http(s):// and anything after a slash
164
- @host = host.sub(/https?:\/\//, '').split('/').first
165
- end
166
-
167
- def base_path=(base_path)
168
- # Add leading and trailing slashes to base_path
169
- @base_path = "/#{base_path}".gsub(/\/+/, '/')
170
- @base_path = '' if @base_path == '/'
171
- end
172
-
173
- def base_url
174
- url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
175
- url
176
- end
177
-
178
- # Gets API key (with prefix if set).
179
- # @param [String] param_name the parameter name of API key auth
180
- def api_key_with_prefix(param_name)
181
- if @api_key_prefix[param_name]
182
- "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
183
- else
184
- @api_key[param_name]
185
- end
186
- end
187
-
188
- # Gets Basic Auth token string
189
- def basic_auth_token
190
- 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
191
- end
192
-
193
- # Returns Auth Settings hash for api client.
194
- def auth_settings
195
- {
196
- }
8
+ @url = ENV.fetch("ALLQ_URL", DEFAULT_URL)
9
+ @timeout = 30
10
+ @open_timeout = 5
11
+ @headers = {}
197
12
  end
198
13
  end
199
14
  end
@@ -0,0 +1,17 @@
1
+ module AllqRest
2
+ class Error < StandardError; end
3
+
4
+ # Could not reach the server (connection refused, timeout, ...).
5
+ class ConnectionError < Error; end
6
+
7
+ # Server answered with a non-2xx status, or a 2xx whose payload carried an error.
8
+ class ApiError < Error
9
+ attr_reader :status, :body
10
+
11
+ def initialize(message, status: nil, body: nil)
12
+ super(message)
13
+ @status = status
14
+ @body = body
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ module AllqRest
2
+ # A job returned from the queue (JobResponse in the swagger definition).
3
+ Job = Struct.new(:id, :body, :tube, :expireds, :releases, :special, keyword_init: true) do
4
+ def self.from_hash(h)
5
+ return nil if h.nil? || h.empty?
6
+ new(id: h["id"], body: h["body"], tube: h["tube"],
7
+ expireds: h["expireds"], releases: h["releases"], special: h["special"])
8
+ end
9
+ end
10
+ end
@@ -1,15 +1,3 @@
1
- =begin
2
- #AllQ
3
-
4
- #No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
5
-
6
- OpenAPI spec version: 1.0
7
-
8
- Generated by: https://github.com/swagger-api/swagger-codegen.git
9
- Swagger Codegen version: 2.4.2
10
-
11
- =end
12
-
13
- module Allq
14
- VERSION = '1.5.1'
1
+ module AllqRest
2
+ VERSION = "2.0.0"
15
3
  end
data/lib/allq_rest.rb CHANGED
@@ -1,53 +1,28 @@
1
- =begin
2
- #AllQ
1
+ require_relative "allq_rest/version"
2
+ require_relative "allq_rest/errors"
3
+ require_relative "allq_rest/configuration"
4
+ require_relative "allq_rest/job"
5
+ require_relative "allq_rest/client"
3
6
 
4
- #No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
5
-
6
- OpenAPI spec version: 1.0
7
-
8
- Generated by: https://github.com/swagger-api/swagger-codegen.git
9
- Swagger Codegen version: 2.4.2
10
-
11
- =end
12
-
13
- # Common files
14
- require 'allq_rest/api_client'
15
- require 'allq_rest/api_error'
16
- require 'allq_rest/version'
17
- require 'allq_rest/configuration'
7
+ module AllqRest
8
+ class << self
9
+ def config
10
+ @config ||= Configuration.new
11
+ end
18
12
 
19
- # Models
20
- require 'allq_rest/models/basic_payload'
21
- require 'allq_rest/models/basic_response'
22
- require 'allq_rest/models/job_ref'
23
- require 'allq_rest/models/job_response'
24
- require 'allq_rest/models/multiple_job_response'
25
- require 'allq_rest/models/new_job'
26
- require 'allq_rest/models/new_parent_job'
27
- require 'allq_rest/models/stats_info'
28
- require 'allq_rest/models/stats_results'
29
- require 'allq_rest/models/stats_tube'
30
- require 'allq_rest/models/throttle'
31
- require 'allq_rest/models/tube_ref'
13
+ # AllqRest.configure { |c| c.url = "http://allq.internal:8090" }
14
+ def configure
15
+ yield config
16
+ end
32
17
 
33
- # APIs
34
- require 'allq_rest/api/actions_api'
35
- require 'allq_rest/api/admin_api'
18
+ # Shared client built from the global configuration.
19
+ def client
20
+ @client ||= Client.new
21
+ end
36
22
 
37
- module Allq
38
- class << self
39
- # Customize default settings for the SDK using block.
40
- # Allq.configure do |config|
41
- # config.username = "xxx"
42
- # config.password = "xxx"
43
- # end
44
- # If no block given, return the default Configuration object.
45
- def configure
46
- if block_given?
47
- yield(Configuration.default)
48
- else
49
- Configuration.default
50
- end
23
+ def reset!
24
+ @config = nil
25
+ @client = nil
51
26
  end
52
27
  end
53
28
  end