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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f170e78d25077fef771c650e74c87aa605035bfb
4
- data.tar.gz: 317fa2e67e77874f9048d89d5033d296b448844c
3
+ metadata.gz: 982d7dce841599fdd74241461d280ba4bde4c9c1
4
+ data.tar.gz: 8d3b175bbcd444ab08ebe7b01ac55df0b202f77b
5
5
  SHA512:
6
- metadata.gz: 0b9a2c0e8d991a7e8fa96a03de0333326fc92c8b69c65689ade91e00d8f9ad46fad37ecf301840170b9041dfa0a7aed94d5d93208ae9a4c6a0c62ede039ab370
7
- data.tar.gz: e8fc8528855d6230dd8951cf446fe8ec69cdf1692b252060037e99e6471eab540c855394d87086966dfa13eaada868f2c434bc21eb4069112b9e236ad6cf7250
6
+ metadata.gz: 3a4e2fe3a9e3014faf9dac52377c01ac2843dacc0e1de98ec00832f569d98e49f022a47621944d25426967aa12441932d84508078c27b9c3c7732fdf4bffb6f6
7
+ data.tar.gz: d8b4642f81be10b8169331fea76c7e5996770087842f1dfd03ddea1e41a8c32dcc23b9be1483bf29ffabb27008719458ed9cd0aba16f57f7368b23db7d096013
@@ -32,7 +32,7 @@ Style/NumericLiterals:
32
32
  Enabled: false
33
33
 
34
34
  Style/CaseIndentation:
35
- IndentWhenRelativeTo: end
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
- AlignWith: variable
73
+ EnforcedStyleAlignWith: variable
70
74
 
71
75
  Style/FrozenStringLiteralComment:
72
76
  Enabled: false
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rake'
4
3
  gem 'byebug'
4
+ gem 'rake'
5
5
  gem 'rubocop'
6
6
  gem 'yard'
7
7
 
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
@@ -9,3 +9,7 @@ up:
9
9
  commands:
10
10
  test: bundle exec rspec
11
11
  console: bin/console
12
+
13
+ packages:
14
+ - git@github.com:Shopify/dev-shopify.git
15
+
@@ -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
- resp, status, next_page = request :get, url, query: options.delete(:query),
52
- headers: options.delete(:headers),
53
- accept: options.delete(:accept),
54
- content_type: options.delete(:content_type),
55
- paginate: should_paginate, data: options
56
-
57
- # If we should paginate, then automatically traverse all next_pages
58
- if should_paginate
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 && resp = next_page.get
61
- next_page = resp.rels[:next]
62
- all_objs << resp.data
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/" + path.to_s)
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
@@ -1,3 +1,3 @@
1
1
  module Oktakit
2
- VERSION = '0.1.3'.freeze
2
+ VERSION = '0.1.4'.freeze
3
3
  end
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.3
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: 2016-07-26 00:00:00.000000000 Z
12
+ date: 2017-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sawyer