oktakit 0.1.0 → 0.1.1

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: a9909ae42a8aab1535c521ce334ab75809daf340
4
- data.tar.gz: d961502c418a988213484c0427e080078ab1719e
3
+ metadata.gz: 3adab52f184b5c0fba4fd028e4cdff2feab41de2
4
+ data.tar.gz: c9a1251fb849eb6c7b411bc8d60b911cc6c5f37d
5
5
  SHA512:
6
- metadata.gz: cbb1128f0b98700c17e9476b46a72c5ce4024962e773b2331d11808432623ea7722f8e082dfec04170fa65b9e6d0621992db59d4e67a678d084a75b045555af1
7
- data.tar.gz: 8721eb00c6ea3dc40fa13c980a1b02c4d472198f65dc7b6b6016171e6a8f183fc394bd7e412bbc6c3f2a4da79084d69beb87e6b972500289dbfece6145f8a858
6
+ metadata.gz: 367d9245869de129a64f7da78e72b4927750489897fdd3607a4a61cb4f658158db91ab5a84428255a6d05cf8b6259ea986213ace723b0ac94022acc676c934bc
7
+ data.tar.gz: 85facd5085b68c9f007cea04819b83469744175e33c78264129bc9614d5272487f03bee05f925a2488dfba59116d950edd3b414f5a555e3c026999480090dc45
data/.travis.yml CHANGED
@@ -3,4 +3,5 @@ before_install: gem install bundler
3
3
  rvm:
4
4
  - '2.1'
5
5
  - '2.2'
6
+ - '2.3.1'
6
7
 
data/README.md CHANGED
@@ -19,7 +19,7 @@ And then execute:
19
19
 
20
20
  ## Usage
21
21
 
22
- `Oktakit` follow the same patterns as [`Octokit`](https://github.com/octokit/octokit.rb), if you are familiar with it you should feel right at home.
22
+ `Oktakit` follows similar patterns as found in [`Octokit`](https://github.com/octokit/octokit.rb). So if you are familiar with Oktakit, then you should feel right at home.
23
23
 
24
24
  ```ruby
25
25
  client = Oktakit.new(token: 't0k3n', organization: 'my-great-org')
@@ -43,12 +43,28 @@ module Oktakit
43
43
  # @param options[:headers] [Hash] Optional. Header params for the request.
44
44
  # @param options[:accept] [String] Optional. The content type to accept. Default application/json
45
45
  # @param options[:content_type] [String] Optional. The content type for the request. Default application/json
46
+ # @param options[:paginate] [Boolean] Optional. If true, will auto-paginate Okta's API responses.
46
47
  # @param options [Hash] Optional. Body params for request.
47
48
  # @return [Sawyer::Resource]
48
49
  def get(url, options = {})
49
- request :get, url, query: options.delete(:query), headers: options.delete(:headers),
50
- accept: options.delete(:accept), content_type: options.delete(:content_type),
51
- data: options
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
59
+ all_objs = [resp]
60
+ while next_page && resp = next_page.get
61
+ next_page = resp.rels[:next]
62
+ all_objs << resp.data
63
+ end
64
+ resp = all_objs.flatten
65
+ end
66
+
67
+ [resp, status]
52
68
  end
53
69
 
54
70
  # Make a HTTP POST request
@@ -130,7 +146,7 @@ module Oktakit
130
146
 
131
147
  private
132
148
 
133
- def request(method, path, data:, query:, headers:, accept:, content_type:)
149
+ def request(method, path, data:, query:, headers:, accept:, content_type:, paginate: false)
134
150
  options = {}
135
151
  options[:query] = query || {}
136
152
  options[:headers] = headers || {}
@@ -138,8 +154,11 @@ module Oktakit
138
154
  options[:headers][:content_type] = content_type if content_type
139
155
 
140
156
  uri = URI::Parser.new.escape("/api/v1/" + path.to_s)
141
- @last_response = response = sawyer_agent.call(method, uri, data, options)
142
- [response.data, response.status]
157
+ @last_response = resp = sawyer_agent.call(method, uri, data, options)
158
+
159
+ response = [resp.data, resp.status]
160
+ response << resp.rels[:next] if paginate
161
+ response
143
162
  end
144
163
 
145
164
  def sawyer_agent
@@ -74,7 +74,7 @@ module Oktakit
74
74
  # @param options[:accept] [String] Optional. The content type to accept. Default application/json
75
75
  # @param options[:content_type] [String] Optional. The content type for the request. Default application/json
76
76
  # @param options [Hash] Optional. Body params for request.
77
- # @return [Hash<Sawyer::Resource>] All responses return the enrolled Factor with a status of either PENDING_ACTIVATION or ACTIVE.
77
+ # @return [Hash<Sawyer::Resource>] The enrolled Factor with a status of either PENDING_ACTIVATION or ACTIVE.
78
78
  # @see http://developer.okta.com/docs/api/resources/factors.html#enroll-factor
79
79
  # @example
80
80
  # Oktakit.enroll_factor('id')
@@ -118,7 +118,7 @@ module Oktakit
118
118
  # @param options[:accept] [String] Optional. The content type to accept. Default application/json
119
119
  # @param options[:content_type] [String] Optional. The content type for the request. Default application/json
120
120
  # @param options [Hash] Optional. Body params for request.
121
- # @return [Hash<Sawyer::Resource>] Returns empty object by default. When sendEmail is false, returns an activation link for the user to set up their account.
121
+ # @return [Hash<Sawyer::Resource>] Returns empty object by default. If sendEmail is false, a user activation link.
122
122
  # @see http://developer.okta.com/docs/api/resources/users.html#activate-user
123
123
  # @example
124
124
  # Oktakit.activate_user('id')
@@ -198,7 +198,7 @@ module Oktakit
198
198
  # @param options[:accept] [String] Optional. The content type to accept. Default application/json
199
199
  # @param options[:content_type] [String] Optional. The content type for the request. Default application/json
200
200
  # @param options [Hash] Optional. Body params for request.
201
- # @return [Hash<Sawyer::Resource>] Returns an empty object by default. When sendEmail is false, returns a link for the user to reset their password.
201
+ # @return [Hash<Sawyer::Resource>] Returns an empty object by default. If sendEmail is false a password reset link
202
202
  # @see http://developer.okta.com/docs/api/resources/users.html#reset-password
203
203
  # @example
204
204
  # Oktakit.reset_password('id')
@@ -214,7 +214,7 @@ module Oktakit
214
214
  # @param options[:accept] [String] Optional. The content type to accept. Default application/json
215
215
  # @param options[:content_type] [String] Optional. The content type for the request. Default application/json
216
216
  # @param options [Hash] Optional. Body params for request.
217
- # @return [Hash<Sawyer::Resource>] Returns the complete user object by default. When tempPassword is true, returns the temporary password.
217
+ # @return [Hash<Sawyer::Resource>] Returns the user by default. If tempPassword is true, a temporary password.
218
218
  # @see http://developer.okta.com/docs/api/resources/users.html#expire-password
219
219
  # @example
220
220
  # Oktakit.expire_password('id')
@@ -246,7 +246,7 @@ module Oktakit
246
246
  # @param options[:accept] [String] Optional. The content type to accept. Default application/json
247
247
  # @param options[:content_type] [String] Optional. The content type for the request. Default application/json
248
248
  # @param options [Hash] Optional. Body params for request.
249
- # @return [Hash<Sawyer::Resource>] Returns an empty object by default. When sendEmail is false, returns a link for the user to reset their password.
249
+ # @return [Hash<Sawyer::Resource>] Returns an empty object by default. If sendEmail is false a password reset link
250
250
  # @see http://developer.okta.com/docs/api/resources/users.html#forgot-password
251
251
  # @example
252
252
  # Oktakit.forgot_password('id')
data/lib/oktakit/error.rb CHANGED
@@ -8,27 +8,31 @@ module Oktakit
8
8
  # @return [Oktakit::Error]
9
9
  def self.from_response(response)
10
10
  status = response[:status].to_i
11
- if klass = case status
12
- when 400 then Oktakit::BadRequest
13
- when 401 then Oktakit::Unauthorized
14
- when 403 then Oktakit::Forbidden
15
- when 404 then Oktakit::NotFound
16
- when 405 then Oktakit::MethodNotAllowed
17
- when 406 then Oktakit::NotAcceptable
18
- when 409 then Oktakit::Conflict
19
- when 415 then Oktakit::UnsupportedMediaType
20
- when 422 then Oktakit::UnprocessableEntity
21
- when 400..499 then Oktakit::ClientError
22
- when 500 then Oktakit::InternalServerError
23
- when 501 then Oktakit::NotImplemented
24
- when 502 then Oktakit::BadGateway
25
- when 503 then Oktakit::ServiceUnavailable
26
- when 500..599 then Oktakit::ServerError
27
- end
11
+ if klass = error(status)
28
12
  klass.new(response)
29
13
  end
30
14
  end
31
15
 
16
+ def self.error(status)
17
+ case status
18
+ when 400 then Oktakit::BadRequest
19
+ when 401 then Oktakit::Unauthorized
20
+ when 403 then Oktakit::Forbidden
21
+ when 404 then Oktakit::NotFound
22
+ when 405 then Oktakit::MethodNotAllowed
23
+ when 406 then Oktakit::NotAcceptable
24
+ when 409 then Oktakit::Conflict
25
+ when 415 then Oktakit::UnsupportedMediaType
26
+ when 422 then Oktakit::UnprocessableEntity
27
+ when 400..499 then Oktakit::ClientError
28
+ when 500 then Oktakit::InternalServerError
29
+ when 501 then Oktakit::NotImplemented
30
+ when 502 then Oktakit::BadGateway
31
+ when 503 then Oktakit::ServiceUnavailable
32
+ when 500..599 then Oktakit::ServerError
33
+ end
34
+ end
35
+
32
36
  def initialize(response = nil)
33
37
  @response = response
34
38
  super(build_error_message)
@@ -1,3 +1,3 @@
1
1
  module Oktakit
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.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.0
4
+ version: 0.1.1
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-14 00:00:00.000000000 Z
12
+ date: 2016-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sawyer