simplyq 0.8.3 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/lib/simplyq/client.rb +14 -14
- data/lib/simplyq/configuration.rb +24 -25
- data/lib/simplyq/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e296a474be7441e712a63199525f127f6446c2e582ce68ec99ea9e54e40b3ef4
|
4
|
+
data.tar.gz: f94decb3fd372fd2946937c7894a154536c85de340c3b0cd0e50dc1b0f6732b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9af3ed40c1ee1307f2046c22bc333a94033be9c58ccb8c5ad8e19b164516cd140c3bf685863e3b73721b6e24b8c4e520ff717bb5f4eb37c91e14aae23deed2f
|
7
|
+
data.tar.gz: b1033a970943c68da1de0e3e43d666283c8f9cb4353f60b75f9d61959b948f7257b34f3454c8e1f4d4d1049b62d52cada8bfd9acb03ca13da65ffbf015b480fe
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,13 @@ This project uses [Semantic Versioning 2.0.0](http://semver.org/).
|
|
4
4
|
|
5
5
|
## main
|
6
6
|
|
7
|
-
## 0.
|
7
|
+
## 0.10.0 - 2023-05-05
|
8
|
+
|
9
|
+
ENHANCEMENTS:
|
10
|
+
|
11
|
+
- Support automatic selection of API endpoint based on api key [PR #52](https://github.com/simplyqio/apis/pull/59)
|
12
|
+
|
13
|
+
## 0.9.0 - 2023-04-20
|
8
14
|
|
9
15
|
ENHANCEMENTS:
|
10
16
|
|
data/lib/simplyq/client.rb
CHANGED
@@ -55,11 +55,11 @@ module Simplyq
|
|
55
55
|
"Unexpected error communicating when trying to connect to " \
|
56
56
|
"SimplyQ (%s). You may be seeing this message because your DNS is not " \
|
57
57
|
"working or you don't have an internet connection. To check, try " \
|
58
|
-
"running `host api.simplyq.
|
58
|
+
"running `host us.api.simplyq.io` from the command line."
|
59
59
|
ERROR_MESSAGE_SSL =
|
60
60
|
"Could not establish a secure connection to SimplyQ (%s), you " \
|
61
61
|
"may need to upgrade your OpenSSL version. To check, try running " \
|
62
|
-
"`openssl s_client -connect api.simplyq.
|
62
|
+
"`openssl s_client -connect us.api.simplyq.io:443` from the command " \
|
63
63
|
"line."
|
64
64
|
|
65
65
|
ERROR_MESSAGE_TIMEOUT_SUFFIX =
|
@@ -108,12 +108,12 @@ module Simplyq
|
|
108
108
|
config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n" if config.debugging
|
109
109
|
|
110
110
|
unless response.success?
|
111
|
-
if response.status.zero?
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
111
|
+
raise ApiError.new(response.reason_phrase, http_status: 0) if response.status.zero?
|
112
|
+
|
113
|
+
# Errors from libcurl will be made visible here
|
114
|
+
|
115
|
+
raise specific_http_error(response, get_http_error_data(response).merge(params: opts[:query_params]))
|
116
|
+
|
117
117
|
end
|
118
118
|
rescue *NETWORK_ERROR_MESSAGES_MAP.keys => e
|
119
119
|
handle_network_error(e)
|
@@ -292,12 +292,12 @@ module Simplyq
|
|
292
292
|
end
|
293
293
|
|
294
294
|
def basic_auth(conn)
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
295
|
+
return unless config.username && config.password
|
296
|
+
|
297
|
+
if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new("2.0")
|
298
|
+
conn.request(:authorization, :basic, config.username, config.password)
|
299
|
+
else
|
300
|
+
conn.request(:basic_auth, config.username, config.password)
|
301
301
|
end
|
302
302
|
end
|
303
303
|
end
|
@@ -4,8 +4,13 @@ require "logger"
|
|
4
4
|
|
5
5
|
module Simplyq
|
6
6
|
class Configuration
|
7
|
+
REGIONAL_ENDPOINTS = {
|
8
|
+
"us" => "https://us.api.simplyq.io",
|
9
|
+
"eu" => "https://eu.api.simplyq.io"
|
10
|
+
}.freeze
|
11
|
+
|
7
12
|
# Defines API keys used with API Key authentications.
|
8
|
-
|
13
|
+
attr_reader :api_key
|
9
14
|
|
10
15
|
# Defines the api version
|
11
16
|
attr_accessor :api_version
|
@@ -67,13 +72,14 @@ module Simplyq
|
|
67
72
|
|
68
73
|
attr_accessor :timeout
|
69
74
|
|
70
|
-
|
75
|
+
attr_writer :base_url
|
71
76
|
|
72
77
|
attr_accessor :debugging
|
73
78
|
|
74
79
|
attr_reader :open_timeout
|
75
80
|
attr_reader :read_timeout
|
76
81
|
attr_reader :write_timeout
|
82
|
+
attr_reader :region
|
77
83
|
|
78
84
|
def self.setup
|
79
85
|
new.tap do |instance|
|
@@ -89,7 +95,6 @@ module Simplyq
|
|
89
95
|
|
90
96
|
@client_side_validation = true
|
91
97
|
|
92
|
-
@base_url = "https://api.simplyq.io"
|
93
98
|
@middlewares = Hash.new { |h, k| h[k] = [] }
|
94
99
|
@logger = defined?(Rails) ? Rails.logger : Logger.new($stdout)
|
95
100
|
|
@@ -101,6 +106,12 @@ module Simplyq
|
|
101
106
|
Configuration.new
|
102
107
|
end
|
103
108
|
|
109
|
+
def api_key=(api_key)
|
110
|
+
@api_key = api_key
|
111
|
+
|
112
|
+
@region = "us" unless REGIONAL_ENDPOINTS.keys.include?(@region = api_key.split("_").first)
|
113
|
+
end
|
114
|
+
|
104
115
|
# Gets Basic Auth token string
|
105
116
|
def basic_auth_token
|
106
117
|
"Basic #{["#{username}:#{password}"].pack("m").delete("\r\n")}"
|
@@ -110,22 +121,10 @@ module Simplyq
|
|
110
121
|
"Bearer #{@api_key}"
|
111
122
|
end
|
112
123
|
|
113
|
-
#
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
# @base_path = "" if @base_path == "/"
|
118
|
-
# end
|
119
|
-
|
120
|
-
# TODO: Remove
|
121
|
-
# Returns base URL for specified operation based on server settings
|
122
|
-
# def base_url(operation = nil)
|
123
|
-
# index = server_operation_index.fetch(operation, server_index)
|
124
|
-
# return "#{scheme}://#{[host, base_path].join("/").gsub(%r{/+}, "/")}".sub(%r{/+\z}, "") if index.nil?
|
125
|
-
|
126
|
-
# server_url(index, server_operation_variables.fetch(operation, server_variables),
|
127
|
-
# operation_server_settings[operation])
|
128
|
-
# end
|
124
|
+
# Returns base URL for specified operation based on api key
|
125
|
+
def base_url
|
126
|
+
@base_url || REGIONAL_ENDPOINTS[region]
|
127
|
+
end
|
129
128
|
|
130
129
|
# Adds middleware to the stack
|
131
130
|
def use(*middleware)
|
@@ -155,8 +154,8 @@ module Simplyq
|
|
155
154
|
# @see https://github.com/lostisland/faraday/blob/v2.3.0/lib/faraday/rack_builder.rb#L92-L143
|
156
155
|
def set_faraday_middleware(operation, key, *args, &block)
|
157
156
|
unless %i[request response use insert insert_before insert_after swap delete].include?(operation)
|
158
|
-
raise ArgumentError, "Invalid faraday middleware operation #{operation}. Must be" \
|
159
|
-
"
|
157
|
+
raise ArgumentError, "Invalid faraday middleware operation #{operation}. Must be " \
|
158
|
+
":request, :response, :use, :insert, :insert_before, :insert_after, :swap or :delete."
|
160
159
|
end
|
161
160
|
|
162
161
|
@middlewares[operation] << [key, args, block]
|
@@ -175,10 +174,10 @@ module Simplyq
|
|
175
174
|
end
|
176
175
|
end
|
177
176
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
177
|
+
return unless @middlewares.key?(:delete)
|
178
|
+
|
179
|
+
@middlewares[:delete].each do |key, _args, _block|
|
180
|
+
connection.builder.delete(key)
|
182
181
|
end
|
183
182
|
end
|
184
183
|
end
|
data/lib/simplyq/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplyq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- simplyq-dxtimer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|