oktakit 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -2
- data/Gemfile +1 -1
- data/README.md +8 -0
- data/dev.yml +4 -0
- data/lib/oktakit/client.rb +26 -14
- data/lib/oktakit/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 982d7dce841599fdd74241461d280ba4bde4c9c1
|
4
|
+
data.tar.gz: 8d3b175bbcd444ab08ebe7b01ac55df0b202f77b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a4e2fe3a9e3014faf9dac52377c01ac2843dacc0e1de98ec00832f569d98e49f022a47621944d25426967aa12441932d84508078c27b9c3c7732fdf4bffb6f6
|
7
|
+
data.tar.gz: d8b4642f81be10b8169331fea76c7e5996770087842f1dfd03ddea1e41a8c32dcc23b9be1483bf29ffabb27008719458ed9cd0aba16f57f7368b23db7d096013
|
data/.rubocop.yml
CHANGED
@@ -32,7 +32,7 @@ Style/NumericLiterals:
|
|
32
32
|
Enabled: false
|
33
33
|
|
34
34
|
Style/CaseIndentation:
|
35
|
-
|
35
|
+
EnforcedStyle: end
|
36
36
|
|
37
37
|
Style/IndentHash:
|
38
38
|
EnforcedStyle: consistent
|
@@ -58,6 +58,10 @@ Metrics/ClassLength:
|
|
58
58
|
Metrics/MethodLength:
|
59
59
|
Enabled: false
|
60
60
|
|
61
|
+
Metrics/BlockLength:
|
62
|
+
Exclude:
|
63
|
+
- "**/*_spec.rb"
|
64
|
+
|
61
65
|
Metrics/ParameterLists:
|
62
66
|
Max: 5
|
63
67
|
CountKeywordArgs: false
|
@@ -66,7 +70,7 @@ Metrics/PerceivedComplexity:
|
|
66
70
|
Enabled: false
|
67
71
|
|
68
72
|
Lint/EndAlignment:
|
69
|
-
|
73
|
+
EnforcedStyleAlignWith: variable
|
70
74
|
|
71
75
|
Style/FrozenStringLiteralComment:
|
72
76
|
Enabled: false
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -26,6 +26,14 @@ client = Oktakit.new(token: 't0k3n', organization: 'my-great-org')
|
|
26
26
|
response, http_status = client.list_users
|
27
27
|
```
|
28
28
|
|
29
|
+
#### Pagination
|
30
|
+
Pass the `paginate` flag as options for any `get` action for Oktakit to autopaginate the response for you.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
client = Oktakit.new(token: 't0k3n', organization: 'my-great-org')
|
34
|
+
response, http_status = client.list_users(paginate: true)
|
35
|
+
```
|
36
|
+
|
29
37
|
## Development
|
30
38
|
|
31
39
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/dev.yml
CHANGED
data/lib/oktakit/client.rb
CHANGED
@@ -48,18 +48,25 @@ module Oktakit
|
|
48
48
|
# @return [Sawyer::Resource]
|
49
49
|
def get(url, options = {})
|
50
50
|
should_paginate = options.delete(:paginate)
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
51
|
+
request_options = {
|
52
|
+
query: options.delete(:query),
|
53
|
+
headers: options.delete(:headers),
|
54
|
+
accept: options.delete(:accept),
|
55
|
+
content_type: options.delete(:content_type),
|
56
|
+
paginate: should_paginate,
|
57
|
+
data: options
|
58
|
+
}
|
59
|
+
|
60
|
+
resp, status, next_page = request :get, url, **request_options
|
61
|
+
|
62
|
+
# If request succeeded and we should paginate, then automatically traverse all next_pages
|
63
|
+
if status == 200 && should_paginate
|
59
64
|
all_objs = [resp]
|
60
|
-
while next_page
|
61
|
-
next_page =
|
62
|
-
|
65
|
+
while next_page
|
66
|
+
resp, status, next_page = request :get, next_page, **request_options
|
67
|
+
break unless status == 200 # Return early if page request fails
|
68
|
+
|
69
|
+
all_objs << resp
|
63
70
|
end
|
64
71
|
resp = all_objs.flatten
|
65
72
|
end
|
@@ -153,11 +160,11 @@ module Oktakit
|
|
153
160
|
options[:headers][:accept] = accept if accept
|
154
161
|
options[:headers][:content_type] = content_type if content_type
|
155
162
|
|
156
|
-
uri = URI::Parser.new.escape("/api/v1
|
163
|
+
uri = URI::Parser.new.escape("/api/v1" + path.to_s)
|
157
164
|
@last_response = resp = sawyer_agent.call(method, uri, data, options)
|
158
165
|
|
159
166
|
response = [resp.data, resp.status]
|
160
|
-
response << resp.rels[:next] if paginate
|
167
|
+
response << absolute_to_relative_url(resp.rels[:next]) if paginate
|
161
168
|
response
|
162
169
|
end
|
163
170
|
|
@@ -178,7 +185,12 @@ module Oktakit
|
|
178
185
|
end
|
179
186
|
|
180
187
|
def api_endpoint
|
181
|
-
"https://#{@organization}.okta.com/api/v1
|
188
|
+
"https://#{@organization}.okta.com/api/v1"
|
189
|
+
end
|
190
|
+
|
191
|
+
def absolute_to_relative_url(next_ref)
|
192
|
+
return unless next_ref
|
193
|
+
next_ref.href.sub(api_endpoint, '')
|
182
194
|
end
|
183
195
|
end
|
184
196
|
end
|
data/lib/oktakit/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oktakit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Graeme Johnson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-03-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sawyer
|