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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e93ac9511c215489f329d2a464a85ee094ddadb88b41710298fd6e7aeca1d48
4
- data.tar.gz: '0888c32a76cfabc24b32a74c5745f5fdc0252b2a9e28d395cadc6888eb52b1c9'
3
+ metadata.gz: 7742cc26953cb2a3549c474090533399801ccc4a73fc9edd9bd0576bb2043729
4
+ data.tar.gz: 7905082d94868140a43621a4ee5ae06b43c329895c1d5aa60079224daba8e97b
5
5
  SHA512:
6
- metadata.gz: 765f0d5cd8a1bdbdbb84b4d22cc60702d61547e4de445d13ac76d1b642cca88a82d9478e83566a75c1ba14bd021c8bc717fb4e5042b1c734480f3199da37b98f
7
- data.tar.gz: 8003b4a414f1b39a828fdfa3434d50a6f803bdc9c0a181ed4a544e131c44131ff3bc9836508c522d776fd2c767105e87dc8ff520d968a1af5862efd00c32dd3a
6
+ metadata.gz: 3d78140e011964c68cf77a4850e9e2cb7a5e24de3253009f84bfa4dcee97fbf3c49abd5f5f5cbbbed33419630981706ecdb4fae9abb99a801b979769e3ffee58
7
+ data.tar.gz: ef2358800b0b3a5aacafa57a7a5863fd408f402b516cb88f203d29c0b02172325e8c47913176b27c1b1bff47d975feb1f19d13b3d7ebc3edebdfe6dbc04b8628
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 1.0.1
2
+
3
+ * Fix oauth token request
4
+ * Add example web service for CLI authorization
5
+
1
6
  # 1.0.0
2
7
 
3
8
  * Initial version
data/README.md CHANGED
@@ -16,7 +16,19 @@ Using RubyGems:
16
16
  gem install timely-app
17
17
  ```
18
18
 
19
- ## Getting started
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
- def timely_auth_callback
31
- skip_verify_authorized!
42
+ def timely_auth_callback
43
+ skip_verify_authorized!
32
44
 
33
- client = TimelyApp::Client.new
34
- 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")
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
- if token["access_token"].present?
37
- client.access_token = token["access_token"]
38
- timely_user = client.get_current_user
48
+ if token["access_token"].present?
49
+ client.access_token = token["access_token"]
50
+ timely_user = client.get_current_user
39
51
 
40
- user = User.find_or_create_by(email: timely_user["email"])
41
- user.update!(timely_id: timely_user["id"], timely_access_token: token["access_token"], timely_refresh_token: token["refresh_token"])
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
- sign_in(user)
55
+ sign_in(user)
44
56
 
45
- redirect_to "/authorized"
46
- else
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
- Use client:
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("/1.1/oauth/token", body: {
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
- }, params: {})
23
+ )
23
24
  end
24
25
  end
25
26
  end
@@ -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
@@ -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
- error_class(response).new(body&.dig("errors", "message"), response: response, errors: body&.dig("errors"))
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
@@ -1,3 +1,3 @@
1
1
  module TimelyApp
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
data/timely-app.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'timely-app'
3
- s.version = '1.0.0'
3
+ s.version = '1.0.1'
4
4
  s.license = 'MIT'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = ['Andrei Makarov']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timely-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov