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 +4 -4
- data/.travis.yml +1 -0
- data/README.md +1 -1
- data/lib/oktakit/client.rb +25 -6
- data/lib/oktakit/client/factors.rb +1 -1
- data/lib/oktakit/client/users.rb +4 -4
- data/lib/oktakit/error.rb +21 -17
- 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: 3adab52f184b5c0fba4fd028e4cdff2feab41de2
|
4
|
+
data.tar.gz: c9a1251fb849eb6c7b411bc8d60b911cc6c5f37d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 367d9245869de129a64f7da78e72b4927750489897fdd3607a4a61cb4f658158db91ab5a84428255a6d05cf8b6259ea986213ace723b0ac94022acc676c934bc
|
7
|
+
data.tar.gz: 85facd5085b68c9f007cea04819b83469744175e33c78264129bc9614d5272487f03bee05f925a2488dfba59116d950edd3b414f5a555e3c026999480090dc45
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -19,7 +19,7 @@ And then execute:
|
|
19
19
|
|
20
20
|
## Usage
|
21
21
|
|
22
|
-
`Oktakit`
|
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')
|
data/lib/oktakit/client.rb
CHANGED
@@ -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
|
-
|
50
|
-
|
51
|
-
|
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 =
|
142
|
-
|
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>]
|
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')
|
data/lib/oktakit/client/users.rb
CHANGED
@@ -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.
|
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.
|
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
|
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.
|
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 =
|
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)
|
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.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-
|
12
|
+
date: 2016-07-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sawyer
|