timely-app 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +30 -18
- data/lib/timely-app/client/auth.rb +3 -2
- data/lib/timely-app/client.rb +5 -0
- data/lib/timely-app/response.rb +2 -1
- data/lib/timely-app/version.rb +1 -1
- data/timely-app.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7742cc26953cb2a3549c474090533399801ccc4a73fc9edd9bd0576bb2043729
|
4
|
+
data.tar.gz: 7905082d94868140a43621a4ee5ae06b43c329895c1d5aa60079224daba8e97b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d78140e011964c68cf77a4850e9e2cb7a5e24de3253009f84bfa4dcee97fbf3c49abd5f5f5cbbbed33419630981706ecdb4fae9abb99a801b979769e3ffee58
|
7
|
+
data.tar.gz: ef2358800b0b3a5aacafa57a7a5863fd408f402b516cb88f203d29c0b02172325e8c47913176b27c1b1bff47d975feb1f19d13b3d7ebc3edebdfe6dbc04b8628
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -16,7 +16,19 @@ Using RubyGems:
|
|
16
16
|
gem install timely-app
|
17
17
|
```
|
18
18
|
|
19
|
-
##
|
19
|
+
## Usage for CLI
|
20
|
+
|
21
|
+
Register your local service at https://app.timelyapp.com/{account_id}/oauth_applications
|
22
|
+
|
23
|
+
Run auth script:
|
24
|
+
|
25
|
+
```sh
|
26
|
+
TIMELY_CLIENT_ID=<CLIENT_ID> TIMELY_CLIENT_SECRET=<CLIENT_SECRET> ./examples/auth_cli.rb
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage for web service
|
30
|
+
|
31
|
+
Example web server: `./examples/auth_server.rb`
|
20
32
|
|
21
33
|
Implement link to Timely OAuth authorization page:
|
22
34
|
|
@@ -24,34 +36,34 @@ Implement link to Timely OAuth authorization page:
|
|
24
36
|
<%= link_to "Sign in with Timely", TimelyApp::Client.new.get_oauth_authorize_url(client_id: ENV.fetch("TIMELY_CLIENT_ID"), redirect_uri: ENV.fetch("TIMELY_REDIRECT_URI")) %>
|
25
37
|
```
|
26
38
|
|
27
|
-
Implement callback action to get access token:
|
39
|
+
Implement callback action to get access token (devise example):
|
28
40
|
|
29
41
|
```ruby
|
30
|
-
|
31
|
-
|
42
|
+
def timely_auth_callback
|
43
|
+
skip_verify_authorized!
|
32
44
|
|
33
|
-
|
34
|
-
|
45
|
+
client = TimelyApp::Client.new
|
46
|
+
token = client.post_oauth_token(client_id: ENV.fetch("TIMELY_CLIENT_ID"), client_secret: ENV.fetch("TIMELY_CLIENT_SECRET"), code: params["code"], redirect_uri: ENV.fetch("TIMELY_REDIRECT_URI"), grant_type: "authorization_code")
|
35
47
|
|
36
|
-
|
37
|
-
|
38
|
-
|
48
|
+
if token["access_token"].present?
|
49
|
+
client.access_token = token["access_token"]
|
50
|
+
timely_user = client.get_current_user
|
39
51
|
|
40
|
-
|
41
|
-
|
52
|
+
user = User.find_or_create_by(email: timely_user["email"])
|
53
|
+
user.update!(timely_id: timely_user["id"], timely_access_token: token["access_token"], timely_refresh_token: token["refresh_token"])
|
42
54
|
|
43
|
-
|
55
|
+
sign_in(user)
|
44
56
|
|
45
|
-
|
46
|
-
|
47
|
-
redirect_to "/not-authorized"
|
48
|
-
end
|
49
|
-
rescue TimelyApp::Error => _e
|
57
|
+
redirect_to "/authorized"
|
58
|
+
else
|
50
59
|
redirect_to "/not-authorized"
|
51
60
|
end
|
61
|
+
rescue TimelyApp::Error => _e
|
62
|
+
redirect_to "/not-authorized"
|
63
|
+
end
|
52
64
|
```
|
53
65
|
|
54
|
-
|
66
|
+
## Client usage
|
55
67
|
|
56
68
|
```ruby
|
57
69
|
timely = TimelyApp::Client.new(access_token: <USER_TOKEN_AFTER_OAUTH>, account_id: <ACCOUNT_ID>)
|
@@ -13,13 +13,14 @@ module TimelyApp
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def post_oauth_token(client_id:, client_secret:, code:, redirect_uri:, grant_type: "authorization_code")
|
16
|
-
post(
|
16
|
+
post(
|
17
|
+
"/1.1/oauth/token",
|
17
18
|
redirect_uri: redirect_uri,
|
18
19
|
code: code,
|
19
20
|
client_id: client_id,
|
20
21
|
client_secret: client_secret,
|
21
22
|
grant_type: grant_type
|
22
|
-
|
23
|
+
)
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
data/lib/timely-app/client.rb
CHANGED
@@ -57,6 +57,11 @@ module TimelyApp
|
|
57
57
|
|
58
58
|
response = @http.request(http_request)
|
59
59
|
|
60
|
+
if ENV["DEBUG"]
|
61
|
+
puts ">> request: #{http_request.method} #{http_request.path} #{http_request.body}"
|
62
|
+
puts "<< response: #{http_request.method} #{http_request.path} #{response.code} #{response.body}"
|
63
|
+
end
|
64
|
+
|
60
65
|
if response.is_a?(Net::HTTPSuccess)
|
61
66
|
Response.parse(response)
|
62
67
|
else
|
data/lib/timely-app/response.rb
CHANGED
@@ -28,7 +28,8 @@ module TimelyApp
|
|
28
28
|
def error(response)
|
29
29
|
if response.content_type == "application/json"
|
30
30
|
body = JSON.parse(response.body)
|
31
|
-
|
31
|
+
message = body&.dig("errors", "message") || body&.dig("error_description")
|
32
|
+
error_class(response).new(message, response: response, errors: body&.dig("errors"))
|
32
33
|
else
|
33
34
|
error_class(response).new(response: response)
|
34
35
|
end
|
data/lib/timely-app/version.rb
CHANGED
data/timely-app.gemspec
CHANGED