internetdata 2.7.0 → 2.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e82fb5eb7859d275fc2afd049004a7c81bb1011414d233f48e2be9a76743e82e
4
- data.tar.gz: 164f190384cc89c588b20ab86702db0d3d5f563c2c7dc8b2c764b5783eda56d3
3
+ metadata.gz: 0d5119e3e00cca75d9bfed96e29ea5e4e4b3f442c02af34ce83488dbd77dda7f
4
+ data.tar.gz: df7252680ed2fc7cd21e8b0dc04971ec09dd64f3c2685bf01bbb38be67e2afa7
5
5
  SHA512:
6
- metadata.gz: 5ce2ae19a89030b3d6a84556b23a747369540dc9d2c9d036f34f278fbe4495a18c7011a88fb73b8b693ff852a73fbe01d3d12bb3f24887558e238634eb2ea36a
7
- data.tar.gz: cdb7fdd1bb252a72b7a6e1b7ff01407c579813451c20f47b094b03afe46baddf631d83fc16bd2b7cb3898f1538c31f37bb8bbcb127d30e176d2e3ea03803e1c5
6
+ metadata.gz: 3802406b345983d01c71f1cb772373ab612756dc775fa75ac5700d536ef667f4804aa88e87a1232c883a10a14f6bc793b4da1d1d4b6dbaff04eb272404dfcd1d
7
+ data.tar.gz: '0805d1cdbde1207112c95a6da3d4068d84375a81d17f967acaacb3fbc41361a0ae87891392658aedd8e840e72345172932c10d3f114d13446cb444b0d899d5f6'
data/README.md CHANGED
@@ -154,6 +154,17 @@ token = client.oauth.exchange_authorization_code('your-client-id', code, pkce.ve
154
154
 
155
155
  Check that `state` came back as you sent it before you exchange `code`, which works once. The client ID can also be the https URL of a client metadata document your app serves, and such an app is never handed a key, so `token.apikey` stays `nil`.
156
156
 
157
+ ### Register a client
158
+
159
+ An app with no client ID, and no client metadata document to use as one, registers itself, then signs in with the `client_id` it gets back as the client ID for `authorization_url` and `exchange_authorization_code`:
160
+
161
+ ```ruby
162
+ client = InternetData::Client.new
163
+ registration = client.oauth.register(['http://127.0.0.1:8765/callback'], client_name: 'Your App')
164
+ ```
165
+
166
+ Each redirect URI must be https on a public host name, or http on a loopback address, which then matches any port. Nothing is kept until a person approves the client, so an app with no client ID saved can simply register again.
167
+
157
168
  ## Other Libraries
158
169
 
159
170
  There are official InternetData client libraries available for many languages including PHP, Python, Go, Java, and Ruby. See our GitHub at https://github.com/internetdata for more.
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -0,0 +1,306 @@
1
+ =begin
2
+ #InternetData API
3
+
4
+ #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
+
6
+ The version of the OpenAPI document: 2026.10.18
7
+ Contact: support@internetdata.io
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.25.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module InternetData
17
+ class ClientRegistration < ApiModelBase
18
+ attr_accessor :client_id
19
+
20
+ # Unix seconds. 64-bit, since 32 bits run out on 2038-01-19.
21
+ attr_accessor :client_id_issued_at
22
+
23
+ # As the person will see it.
24
+ attr_accessor :client_name
25
+
26
+ attr_accessor :redirect_uris
27
+
28
+ # `authorization_code` and `refresh_token`.
29
+ attr_accessor :grant_types
30
+
31
+ attr_accessor :response_types
32
+
33
+ # Always `none`.
34
+ attr_accessor :token_endpoint_auth_method
35
+
36
+ # The most this client may be granted: `apikeys.use`.
37
+ attr_accessor :scope
38
+
39
+ # Attribute mapping from ruby-style variable name to JSON key.
40
+ def self.attribute_map
41
+ {
42
+ :'client_id' => :'client_id',
43
+ :'client_id_issued_at' => :'client_id_issued_at',
44
+ :'client_name' => :'client_name',
45
+ :'redirect_uris' => :'redirect_uris',
46
+ :'grant_types' => :'grant_types',
47
+ :'response_types' => :'response_types',
48
+ :'token_endpoint_auth_method' => :'token_endpoint_auth_method',
49
+ :'scope' => :'scope'
50
+ }
51
+ end
52
+
53
+ # Returns attribute mapping this model knows about
54
+ def self.acceptable_attribute_map
55
+ attribute_map
56
+ end
57
+
58
+ # Returns all the JSON keys this model knows about
59
+ def self.acceptable_attributes
60
+ acceptable_attribute_map.values
61
+ end
62
+
63
+ # Attribute type mapping.
64
+ def self.openapi_types
65
+ {
66
+ :'client_id' => :'String',
67
+ :'client_id_issued_at' => :'Integer',
68
+ :'client_name' => :'String',
69
+ :'redirect_uris' => :'Array<String>',
70
+ :'grant_types' => :'Array<String>',
71
+ :'response_types' => :'Array<String>',
72
+ :'token_endpoint_auth_method' => :'String',
73
+ :'scope' => :'String'
74
+ }
75
+ end
76
+
77
+ # List of attributes with nullable: true
78
+ def self.openapi_nullable
79
+ Set.new([
80
+ ])
81
+ end
82
+
83
+ # Initializes the object
84
+ # @param [Hash] attributes Model attributes in the form of hash
85
+ def initialize(attributes = {})
86
+ if (!attributes.is_a?(Hash))
87
+ fail ArgumentError, "The input argument (attributes) must be a hash in `InternetData::ClientRegistration` initialize method"
88
+ end
89
+
90
+ # check to see if the attribute exists and convert string to symbol for hash key
91
+ acceptable_attribute_map = self.class.acceptable_attribute_map
92
+ attributes = attributes.each_with_object({}) { |(k, v), h|
93
+ if (!acceptable_attribute_map.key?(k.to_sym))
94
+ fail ArgumentError, "`#{k}` is not a valid attribute in `InternetData::ClientRegistration`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
95
+ end
96
+ h[k.to_sym] = v
97
+ }
98
+
99
+ if attributes.key?(:'client_id')
100
+ self.client_id = attributes[:'client_id']
101
+ else
102
+ self.client_id = nil
103
+ end
104
+
105
+ if attributes.key?(:'client_id_issued_at')
106
+ self.client_id_issued_at = attributes[:'client_id_issued_at']
107
+ else
108
+ self.client_id_issued_at = nil
109
+ end
110
+
111
+ if attributes.key?(:'client_name')
112
+ self.client_name = attributes[:'client_name']
113
+ else
114
+ self.client_name = nil
115
+ end
116
+
117
+ if attributes.key?(:'redirect_uris')
118
+ if (value = attributes[:'redirect_uris']).is_a?(Array)
119
+ self.redirect_uris = value
120
+ end
121
+ else
122
+ self.redirect_uris = nil
123
+ end
124
+
125
+ if attributes.key?(:'grant_types')
126
+ if (value = attributes[:'grant_types']).is_a?(Array)
127
+ self.grant_types = value
128
+ end
129
+ end
130
+
131
+ if attributes.key?(:'response_types')
132
+ if (value = attributes[:'response_types']).is_a?(Array)
133
+ self.response_types = value
134
+ end
135
+ end
136
+
137
+ if attributes.key?(:'token_endpoint_auth_method')
138
+ self.token_endpoint_auth_method = attributes[:'token_endpoint_auth_method']
139
+ else
140
+ self.token_endpoint_auth_method = nil
141
+ end
142
+
143
+ if attributes.key?(:'scope')
144
+ self.scope = attributes[:'scope']
145
+ end
146
+ end
147
+
148
+ # Show invalid properties with the reasons. Usually used together with valid?
149
+ # @return Array for valid properties with the reasons
150
+ def list_invalid_properties
151
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
152
+ invalid_properties = Array.new
153
+ if @client_id.nil?
154
+ invalid_properties.push('invalid value for "client_id", client_id cannot be nil.')
155
+ end
156
+
157
+ if @client_id_issued_at.nil?
158
+ invalid_properties.push('invalid value for "client_id_issued_at", client_id_issued_at cannot be nil.')
159
+ end
160
+
161
+ if @client_name.nil?
162
+ invalid_properties.push('invalid value for "client_name", client_name cannot be nil.')
163
+ end
164
+
165
+ if @redirect_uris.nil?
166
+ invalid_properties.push('invalid value for "redirect_uris", redirect_uris cannot be nil.')
167
+ end
168
+
169
+ if @token_endpoint_auth_method.nil?
170
+ invalid_properties.push('invalid value for "token_endpoint_auth_method", token_endpoint_auth_method cannot be nil.')
171
+ end
172
+
173
+ invalid_properties
174
+ end
175
+
176
+ # Check to see if the all the properties in the model are valid
177
+ # @return true if the model is valid
178
+ def valid?
179
+ warn '[DEPRECATED] the `valid?` method is obsolete'
180
+ return false if @client_id.nil?
181
+ return false if @client_id_issued_at.nil?
182
+ return false if @client_name.nil?
183
+ return false if @redirect_uris.nil?
184
+ return false if @token_endpoint_auth_method.nil?
185
+ true
186
+ end
187
+
188
+ # Custom attribute writer method with validation
189
+ # @param [Object] client_id Value to be assigned
190
+ def client_id=(client_id)
191
+ if client_id.nil?
192
+ fail ArgumentError, 'client_id cannot be nil'
193
+ end
194
+
195
+ @client_id = client_id
196
+ end
197
+
198
+ # Custom attribute writer method with validation
199
+ # @param [Object] client_id_issued_at Value to be assigned
200
+ def client_id_issued_at=(client_id_issued_at)
201
+ if client_id_issued_at.nil?
202
+ fail ArgumentError, 'client_id_issued_at cannot be nil'
203
+ end
204
+
205
+ @client_id_issued_at = client_id_issued_at
206
+ end
207
+
208
+ # Custom attribute writer method with validation
209
+ # @param [Object] client_name Value to be assigned
210
+ def client_name=(client_name)
211
+ if client_name.nil?
212
+ fail ArgumentError, 'client_name cannot be nil'
213
+ end
214
+
215
+ @client_name = client_name
216
+ end
217
+
218
+ # Custom attribute writer method with validation
219
+ # @param [Object] redirect_uris Value to be assigned
220
+ def redirect_uris=(redirect_uris)
221
+ if redirect_uris.nil?
222
+ fail ArgumentError, 'redirect_uris cannot be nil'
223
+ end
224
+
225
+ @redirect_uris = redirect_uris
226
+ end
227
+
228
+ # Custom attribute writer method with validation
229
+ # @param [Object] token_endpoint_auth_method Value to be assigned
230
+ def token_endpoint_auth_method=(token_endpoint_auth_method)
231
+ if token_endpoint_auth_method.nil?
232
+ fail ArgumentError, 'token_endpoint_auth_method cannot be nil'
233
+ end
234
+
235
+ @token_endpoint_auth_method = token_endpoint_auth_method
236
+ end
237
+
238
+ # Checks equality by comparing each attribute.
239
+ # @param [Object] Object to be compared
240
+ def ==(o)
241
+ return true if self.equal?(o)
242
+ self.class == o.class &&
243
+ client_id == o.client_id &&
244
+ client_id_issued_at == o.client_id_issued_at &&
245
+ client_name == o.client_name &&
246
+ redirect_uris == o.redirect_uris &&
247
+ grant_types == o.grant_types &&
248
+ response_types == o.response_types &&
249
+ token_endpoint_auth_method == o.token_endpoint_auth_method &&
250
+ scope == o.scope
251
+ end
252
+
253
+ # @see the `==` method
254
+ # @param [Object] Object to be compared
255
+ def eql?(o)
256
+ self == o
257
+ end
258
+
259
+ # Calculates hash code according to all attributes.
260
+ # @return [Integer] Hash code
261
+ def hash
262
+ [client_id, client_id_issued_at, client_name, redirect_uris, grant_types, response_types, token_endpoint_auth_method, scope].hash
263
+ end
264
+
265
+ # Builds the object from hash
266
+ # @param [Hash] attributes Model attributes in the form of hash
267
+ # @return [Object] Returns the model itself
268
+ def self.build_from_hash(attributes)
269
+ return nil unless attributes.is_a?(Hash)
270
+ attributes = attributes.transform_keys(&:to_sym)
271
+ transformed_hash = {}
272
+ openapi_types.each_pair do |key, type|
273
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
274
+ transformed_hash["#{key}"] = nil
275
+ elsif type =~ /\AArray<(.*)>/i
276
+ # check to ensure the input is an array given that the attribute
277
+ # is documented as an array but the input is not
278
+ if attributes[attribute_map[key]].is_a?(Array)
279
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
280
+ end
281
+ elsif !attributes[attribute_map[key]].nil?
282
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
283
+ end
284
+ end
285
+ new(transformed_hash)
286
+ end
287
+
288
+ # Returns the object in the form of hash
289
+ # @return [Hash] Returns the object in the form of hash
290
+ def to_hash
291
+ hash = {}
292
+ self.class.attribute_map.each_pair do |attr, param|
293
+ value = self.send(attr)
294
+ if value.nil?
295
+ is_nullable = self.class.openapi_nullable.include?(attr)
296
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
297
+ end
298
+
299
+ hash[param] = _to_hash(value)
300
+ end
301
+ hash
302
+ end
303
+
304
+ end
305
+
306
+ end
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.10.16
6
+ The version of the OpenAPI document: 2026.10.18
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -36,6 +36,7 @@ module InternetData
36
36
  TOKEN_PATH = '/oauth/token'
37
37
  REVOKE_PATH = '/oauth/revoke'
38
38
  AUTHORIZE_PATH = '/oauth/authorize'
39
+ REGISTER_PATH = '/oauth/register'
39
40
  DEVICE_CODE_GRANT = 'urn:ietf:params:oauth:grant-type:device_code'
40
41
  # The longest single `sleep` the poll asks Ruby for, in seconds.
41
42
  LONGEST_SLEEP = 2**31 - 1
@@ -45,6 +46,7 @@ module InternetData
45
46
  OauthMetadata => %i[issuer authorization_endpoint token_endpoint],
46
47
  DeviceAuthorization => %i[device_code user_code verification_uri expires_in interval],
47
48
  TokenResponse => %i[access_token token_type expires_in],
49
+ ClientRegistration => %i[client_id client_id_issued_at client_name redirect_uris token_endpoint_auth_method],
48
50
  }.freeze
49
51
 
50
52
  def initialize(transport, retries:)
@@ -151,6 +153,31 @@ module InternetData
151
153
  [Digest::SHA256.digest(verifier)].pack('m0').tr('+/', '-_').delete('=')
152
154
  end
153
155
 
156
+ # Register a client for the authorization code flow, for an app that cannot
157
+ # serve a Client ID Metadata Document, and get its `client_id` for
158
+ # {#authorization_url} and {#exchange_authorization_code}.
159
+ #
160
+ # Each redirect URI must be https on a public host name, or http on a
161
+ # loopback address, which then matches on any port; the server refuses any
162
+ # other with {OauthRequestError} coded `invalid_redirect_uri`. Nothing is kept
163
+ # until a person approves the client, so registering again costs nothing, and
164
+ # this is retried like a read. No URI at all, or one that is empty or not
165
+ # UTF-8, raises ArgumentError before anything is sent.
166
+ #
167
+ # @param client_name [String, nil] shown to the person as the client's own
168
+ # claim; left out when empty.
169
+ # @return [ClientRegistration]
170
+ def register(redirect_uris, client_name: nil, timeout: nil)
171
+ raise ArgumentError, 'redirect_uris must list at least one URI' unless redirect_uris.is_a?(Array) && !redirect_uris.empty?
172
+
173
+ body = { 'redirect_uris' => redirect_uris.each_with_index.map { |uri, i| utf8!("redirect_uris[#{i}]", uri) } }
174
+ name = client_name.nil? ? '' : utf8!('client_name', client_name, empty: true)
175
+ body['client_name'] = name unless name.empty?
176
+ Retries.with_retries(@retries) do
177
+ decode(ClientRegistration, @transport.oauth_request(:POST, REGISTER_PATH, json: body, timeout: timeout).run)
178
+ end
179
+ end
180
+
154
181
  # Revoke an access or refresh token. A refresh token ends the whole grant and
155
182
  # every token it issued, which is how a machine signs out.
156
183
  #
@@ -226,6 +253,18 @@ module InternetData
226
253
  raise ArgumentError, "#{name} is not valid UTF-8"
227
254
  end
228
255
 
256
+ def utf8!(name, value, empty: false)
257
+ raise ArgumentError, "#{name} must be a String" unless value.is_a?(String)
258
+ raise ArgumentError, "#{name} must not be empty" if value.empty? && !empty
259
+
260
+ utf8 = value.encode(Encoding::UTF_8)
261
+ raise ArgumentError, "#{name} is not valid UTF-8" unless utf8.valid_encoding?
262
+
263
+ utf8
264
+ rescue EncodingError
265
+ raise ArgumentError, "#{name} is not valid UTF-8"
266
+ end
267
+
229
268
  def exchange(form, timeout)
230
269
  decode(TokenResponse, @transport.oauth_request(:POST, TOKEN_PATH, form: form, timeout: timeout).run)
231
270
  end
@@ -141,11 +141,13 @@ module InternetData
141
141
  #
142
142
  # The form is encoded here rather than by curl, so a `+` in a value leaves as
143
143
  # `%2B` and never arrives as a space.
144
- def oauth_request(http_method, path, form: nil, timeout: nil)
144
+ def oauth_request(http_method, path, form: nil, json: nil, timeout: nil)
145
145
  headers = { 'Accept' => 'application/json' }
146
146
  headers['Content-Type'] = 'application/x-www-form-urlencoded' unless form.nil?
147
+ headers['Content-Type'] = 'application/json' unless json.nil?
147
148
  request = build_request(http_method, path, header_params: headers, auth_names: [], timeout: timeout)
148
149
  request.options[:body] = URI.encode_www_form(form) unless form.nil?
150
+ request.options[:body] = JSON.generate(json) unless json.nil?
149
151
  request
150
152
  end
151
153
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InternetData
4
- VERSION = '2.7.0'
4
+ VERSION = '2.8.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: internetdata
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mslm Dev
@@ -42,6 +42,7 @@ files:
42
42
  - lib/internetdata/configuration.rb
43
43
  - lib/internetdata/database_api.rb
44
44
  - lib/internetdata/errors.rb
45
+ - lib/internetdata/models/client_registration.rb
45
46
  - lib/internetdata/models/database.rb
46
47
  - lib/internetdata/models/database_checksums_response.rb
47
48
  - lib/internetdata/models/database_format.rb