timedoctor 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/console +20 -18
- data/lib/timedoctor.rb +1 -0
- data/lib/timedoctor/auth.rb +13 -0
- data/lib/timedoctor/token.rb +50 -44
- data/lib/timedoctor/worker.rb +3 -3
- data/lib/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1863262f810d0a719b977fe636c3533d7466f0a34d39ab89f72384c9ef0ca5b7
|
4
|
+
data.tar.gz: 74229ed160f0c670c813975561b54009b5d0be70d1ed63642d9f41f7a6ba8e4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f52af45bb440b0a8d7b408cd70d867e7153c74934e46ee850be47512680ddf851856733af4c745707f330f18a2be40d72205a8f5a62d881d04f0288bd0b1053a
|
7
|
+
data.tar.gz: f1158310c37b58803bc15bc7862e1f422e1c81ccdf9df38b305ecb9f47ca0bec0cfa34182eb8d4f64e1de3e264be1d43f4edb112f3679c4e7ecebe910cd0fd0c
|
data/Gemfile.lock
CHANGED
data/bin/console
CHANGED
@@ -13,30 +13,32 @@ require 'timedoctor'
|
|
13
13
|
# require 'irb'
|
14
14
|
# IRB.start(__FILE__)
|
15
15
|
#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
config = {
|
17
|
+
client_id: '1091_4hnloyc6pqqscckokws808o8soocko4c44owwws404g8k4sgos',
|
18
|
+
client_secret: '7wvmks0khckcw40s00cssg4w8s404o8g0g8k00cgo8kow0cow',
|
19
|
+
|
20
20
|
# access_token:
|
21
21
|
# "Y2ZkMGY5OTA1NGI3NmJjZTZlYWJlYjczNGM4N2E2NTYwZjFmNzhjZGVhMGY3ZmU0MTIyZjQ5NTNkOGIzYWI3ZA",
|
22
22
|
# refresh_token:
|
23
23
|
# "ZmM3OTg1NjZmYjgwYmZlYzM2NzAwMjFlZmFhZmU4MDk1Y2ZhZWNlYjMyYTg0NzlmMzRmNzBiOWM5NTUxNjY4MA",
|
24
24
|
# user_id: 1188995,
|
25
25
|
# company_id: 587525,
|
26
|
-
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
|
38
|
-
|
39
|
-
|
26
|
+
|
27
|
+
# on_token_refresh: ->(data, conf) do
|
28
|
+
# p 'SUCCESS'
|
29
|
+
#
|
30
|
+
# p data
|
31
|
+
#
|
32
|
+
# conf[:access_token] = data[:access_token]
|
33
|
+
# conf[:refresh_token] = data[:refresh_token]
|
34
|
+
# end,
|
35
|
+
#
|
36
|
+
# on_token_refresh_error: ->(data, conf) { p "FAILURE" }
|
37
|
+
on_token_authorize_error: ->(data, conf) { p "FAILURE" }
|
38
|
+
}
|
39
|
+
|
40
|
+
p TimeDoctor::Auth.new(config).fetch_token
|
41
|
+
# p TimeDoctor::Client.new(config).authorize
|
40
42
|
#
|
41
43
|
# # p client.companies.list
|
42
44
|
#
|
data/lib/timedoctor.rb
CHANGED
data/lib/timedoctor/token.rb
CHANGED
@@ -1,51 +1,57 @@
|
|
1
1
|
module TimeDoctor
|
2
2
|
class Token
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
3
|
+
ENTRY = 'https://webapi.timedoctor.com/oauth/v2/token'.freeze
|
4
|
+
|
5
|
+
def initialize(config)
|
6
|
+
@config = config
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :config
|
10
|
+
|
11
|
+
def fetch
|
12
|
+
response = Faraday.get ENTRY,
|
13
|
+
client_id: config[:client_id],
|
14
|
+
client_secret: config[:client_secret],
|
15
|
+
code: config[:code],
|
16
|
+
redirect_uri: config[:redirect_uri],
|
17
|
+
grant_type: :authorization_code,
|
18
|
+
_format: :json
|
19
|
+
|
20
|
+
data = JSON.parse(response.body, symbolize_names: true)
|
21
|
+
|
22
|
+
case response.status
|
23
|
+
when 200
|
24
|
+
config[:access_token] = data[:access_token]
|
25
|
+
config[:refresh_token] = data[:refresh_token]
|
26
|
+
config[:on_token_authorize].call(data, config)
|
27
|
+
data
|
28
|
+
when 400
|
29
|
+
config[:on_token_authorize_error].call(data, config)
|
30
|
+
else
|
31
|
+
raise UnknownError, response
|
27
32
|
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def refresh
|
36
|
+
response = Faraday.get ENTRY,
|
37
|
+
refresh_token: config[:refresh_token],
|
38
|
+
client_id: config[:client_id],
|
39
|
+
client_secret: config[:client_secret],
|
40
|
+
grant_type: :refresh_token,
|
41
|
+
_format: :json
|
42
|
+
|
43
|
+
data = JSON.parse(response.body, symbolize_names: true)
|
28
44
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
data = JSON.parse(response.body, symbolize_names: true)
|
40
|
-
config[:access_token] = data[:access_token]
|
41
|
-
config[:refresh_token] = data[:refresh_token]
|
42
|
-
config[:on_token_refresh].call(data, config)
|
43
|
-
when 400
|
44
|
-
data = JSON.parse(response.body, symbolize_names: true)
|
45
|
-
config[:on_token_refresh_error].call(data, config)
|
46
|
-
else
|
47
|
-
raise UnknownError, response
|
48
|
-
end
|
45
|
+
case response.status
|
46
|
+
when 200
|
47
|
+
config[:access_token] = data[:access_token]
|
48
|
+
config[:refresh_token] = data[:refresh_token]
|
49
|
+
config[:on_token_refresh].call(data, config)
|
50
|
+
data
|
51
|
+
when 400
|
52
|
+
config[:on_token_refresh_error].call(data, config)
|
53
|
+
else
|
54
|
+
raise UnknownError, response
|
49
55
|
end
|
50
56
|
end
|
51
57
|
end
|
data/lib/timedoctor/worker.rb
CHANGED
@@ -5,13 +5,13 @@ module TimeDoctor
|
|
5
5
|
attr_reader :config, :conn
|
6
6
|
|
7
7
|
def initialize(config)
|
8
|
-
raise EmptyAccessToken unless config[:access_token]
|
9
|
-
|
10
8
|
@config = config
|
11
9
|
@conn = Faraday.new(url: ENTRY)
|
12
10
|
end
|
13
11
|
|
14
12
|
def exchange(method, url, params = {})
|
13
|
+
raise EmptyAccessToken unless config[:access_token]
|
14
|
+
|
15
15
|
params[:access_token] = config[:access_token]
|
16
16
|
params[:_format] = :json
|
17
17
|
|
@@ -21,7 +21,7 @@ module TimeDoctor
|
|
21
21
|
when 200
|
22
22
|
JSON.parse(response.body, symbolize_names: true)
|
23
23
|
when 401
|
24
|
-
Token.
|
24
|
+
Token.new(config).refresh
|
25
25
|
exchange(method, url, params)
|
26
26
|
else
|
27
27
|
raise UnknownError, response
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timedoctor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Yak
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- bin/console
|
143
143
|
- bin/setup
|
144
144
|
- lib/timedoctor.rb
|
145
|
+
- lib/timedoctor/auth.rb
|
145
146
|
- lib/timedoctor/client.rb
|
146
147
|
- lib/timedoctor/config.rb
|
147
148
|
- lib/timedoctor/core/absent_late.rb
|