timedoctor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +16 -0
- data/.simplecov +9 -0
- data/.travis.yml +11 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +81 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +6 -0
- data/bin/console +34 -0
- data/bin/setup +8 -0
- data/lib/timedoctor.rb +9 -0
- data/lib/timedoctor/client.rb +61 -0
- data/lib/timedoctor/config.rb +28 -0
- data/lib/timedoctor/core/absent_late.rb +13 -0
- data/lib/timedoctor/core/base.rb +17 -0
- data/lib/timedoctor/core/companies.rb +17 -0
- data/lib/timedoctor/core/payrolls.rb +13 -0
- data/lib/timedoctor/core/poortime.rb +9 -0
- data/lib/timedoctor/core/projects.rb +37 -0
- data/lib/timedoctor/core/tasks.rb +21 -0
- data/lib/timedoctor/core/users.rb +13 -0
- data/lib/timedoctor/core/web_app.rb +9 -0
- data/lib/timedoctor/core/worklogs.rb +9 -0
- data/lib/timedoctor/exceptions.rb +41 -0
- data/lib/timedoctor/payload.rb +25 -0
- data/lib/timedoctor/token.rb +45 -0
- data/lib/timedoctor/worker.rb +32 -0
- data/lib/version.rb +3 -0
- data/timedoctor.gemspec +31 -0
- metadata +187 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f001d7dff95468e48afdcd400137316259db0879011926b82303ee0121f79a7c
|
4
|
+
data.tar.gz: f36f2d190fb846a05673d7b99db8a3d4f4874682c503b6e8aada23c550dc5265
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2dc32f33dd81c6d8f2a95229a4da8bf1d7648d715f8ff3417cb2c1704a6a7b38ef8e09ee10371ac5d23d8cac4fff6d8d50324b65d7db412075f529ad8d6f4714
|
7
|
+
data.tar.gz: a76fe0fe980c5a055bf5fa79e2d586ead6a69ec153032dd78403d08a7f10b36196885eecdfebfd98bf1c76668179a43e25e0df736f880a277e9e7d9786f9fe3d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.simplecov
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
timedoctor (0.1.0)
|
5
|
+
faraday (~> 0.15.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.5.2)
|
11
|
+
public_suffix (>= 2.0.2, < 4.0)
|
12
|
+
ast (2.4.0)
|
13
|
+
codecov (0.1.10)
|
14
|
+
json
|
15
|
+
simplecov
|
16
|
+
url
|
17
|
+
crack (0.4.3)
|
18
|
+
safe_yaml (~> 1.0.0)
|
19
|
+
diff-lcs (1.3)
|
20
|
+
docile (1.3.0)
|
21
|
+
faraday (0.15.0)
|
22
|
+
multipart-post (>= 1.2, < 3)
|
23
|
+
hashdiff (0.3.7)
|
24
|
+
json (2.1.0)
|
25
|
+
multipart-post (2.0.0)
|
26
|
+
parallel (1.12.1)
|
27
|
+
parser (2.5.1.0)
|
28
|
+
ast (~> 2.4.0)
|
29
|
+
powerpack (0.1.1)
|
30
|
+
public_suffix (3.0.2)
|
31
|
+
rainbow (3.0.0)
|
32
|
+
rake (12.3.1)
|
33
|
+
rspec (3.7.0)
|
34
|
+
rspec-core (~> 3.7.0)
|
35
|
+
rspec-expectations (~> 3.7.0)
|
36
|
+
rspec-mocks (~> 3.7.0)
|
37
|
+
rspec-core (3.7.1)
|
38
|
+
rspec-support (~> 3.7.0)
|
39
|
+
rspec-expectations (3.7.0)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.7.0)
|
42
|
+
rspec-mocks (3.7.0)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.7.0)
|
45
|
+
rspec-support (3.7.1)
|
46
|
+
rubocop (0.55.0)
|
47
|
+
parallel (~> 1.10)
|
48
|
+
parser (>= 2.5)
|
49
|
+
powerpack (~> 0.1)
|
50
|
+
rainbow (>= 2.2.2, < 4.0)
|
51
|
+
ruby-progressbar (~> 1.7)
|
52
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
53
|
+
ruby-progressbar (1.9.0)
|
54
|
+
safe_yaml (1.0.4)
|
55
|
+
simplecov (0.16.1)
|
56
|
+
docile (~> 1.1)
|
57
|
+
json (>= 1.8, < 3)
|
58
|
+
simplecov-html (~> 0.10.0)
|
59
|
+
simplecov-html (0.10.2)
|
60
|
+
unicode-display_width (1.3.2)
|
61
|
+
url (0.3.2)
|
62
|
+
webmock (3.3.0)
|
63
|
+
addressable (>= 2.3.6)
|
64
|
+
crack (>= 0.3.2)
|
65
|
+
hashdiff
|
66
|
+
|
67
|
+
PLATFORMS
|
68
|
+
ruby
|
69
|
+
|
70
|
+
DEPENDENCIES
|
71
|
+
bundler (~> 1.16)
|
72
|
+
codecov (~> 0.1.10)
|
73
|
+
rake (~> 12.3)
|
74
|
+
rspec (~> 3.7)
|
75
|
+
rubocop (~> 0.55.0)
|
76
|
+
simplecov (~> 0.16.1)
|
77
|
+
timedoctor!
|
78
|
+
webmock (~> 3.3)
|
79
|
+
|
80
|
+
BUNDLED WITH
|
81
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Your Name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# TimeDoctor
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/EugeneYak/timedoctor-ruby.svg?branch=master)](https://travis-ci.org/EugeneYak/timedoctor-ruby)
|
4
|
+
[![codecov](https://codecov.io/gh/EugeneYak/timedoctor/branch/master/graph/badge.svg)](https://codecov.io/gh/EugeneYak/timedoctor)
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/fefa2e9bc6ec9fa5917c/maintainability)](https://codeclimate.com/github/EugeneYak/timedoctor-ruby/maintainability)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'timedoctor'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install timedoctor
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/EugeneYak/timedoctor. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
33
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
34
|
+
|
35
|
+
## Code of Conduct
|
36
|
+
|
37
|
+
Everyone interacting in the TimeDoctor project’s codebases, issue trackers, chat rooms and mailing lists.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'timedoctor'
|
5
|
+
|
6
|
+
require 'date'
|
7
|
+
|
8
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
9
|
+
# with your gem easier. You can also use a different console, if you like.
|
10
|
+
|
11
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
12
|
+
# require "pry"
|
13
|
+
# Pry.start
|
14
|
+
|
15
|
+
# require 'irb'
|
16
|
+
# IRB.start(__FILE__)
|
17
|
+
|
18
|
+
|
19
|
+
TimeDoctor::Config.configure do |conf|
|
20
|
+
conf.client_id = '1091_4hnloyc6pqqscckokws808o8soocko4c44owwws404g8k4sgos'
|
21
|
+
conf.client_secret = '7wvmks0khckcw40s00cssg4w8s404o8g0g8k00cgo8kow0cow'
|
22
|
+
|
23
|
+
conf.on_token_refresh = lambda do |data, _payload|
|
24
|
+
p 'REFRESH'
|
25
|
+
p data[:access_token], data[:refresh_token]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
client = TimeDoctor::Client.new access_token: 'MjQ5NDUzYTlhZGJjMDc0OGZlNTQwZjJkY2RmZGYwMjM0OWIxNmIwMmJhMWQ1YWZlZWM0NzRjNjI2NjIwNDk4YQ',
|
30
|
+
refresh_token: 'YmUxOTFjNjE1Njc0YzRmNDYyZGIzZDZlYzFmZWU0MzViNDBmNjIwNDI1NGVhNGQ3ZThkNTNjOTIwNmZkNzNjNA'
|
31
|
+
|
32
|
+
p client.companies.list[:user][:full_name]
|
33
|
+
|
34
|
+
# TimeDoctor::Client.new('token')
|
data/bin/setup
ADDED
data/lib/timedoctor.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative 'core/base'
|
2
|
+
|
3
|
+
require_relative 'core/absent_late'
|
4
|
+
require_relative 'core/companies'
|
5
|
+
require_relative 'core/payrolls'
|
6
|
+
require_relative 'core/poortime'
|
7
|
+
require_relative 'core/projects'
|
8
|
+
require_relative 'core/tasks'
|
9
|
+
require_relative 'core/users'
|
10
|
+
require_relative 'core/web_app'
|
11
|
+
require_relative 'core/worklogs'
|
12
|
+
|
13
|
+
module TimeDoctor
|
14
|
+
class Client
|
15
|
+
CORE = TimeDoctor::Core
|
16
|
+
|
17
|
+
attr_reader :payload
|
18
|
+
|
19
|
+
def initialize(payload = {})
|
20
|
+
raise EmptyAccessToken unless payload[:access_token]
|
21
|
+
@payload = Payload.new(payload)
|
22
|
+
@worker = Worker.new(@payload)
|
23
|
+
end
|
24
|
+
|
25
|
+
def absent_and_late
|
26
|
+
CORE::AbsentAndLate.new(@worker)
|
27
|
+
end
|
28
|
+
|
29
|
+
def companies
|
30
|
+
CORE::Companies.new(@worker)
|
31
|
+
end
|
32
|
+
|
33
|
+
def payrolls
|
34
|
+
CORE::Payrolls.new(@worker)
|
35
|
+
end
|
36
|
+
|
37
|
+
def poortime
|
38
|
+
CORE::Poortime.new(@worker)
|
39
|
+
end
|
40
|
+
|
41
|
+
def projects
|
42
|
+
CORE::Projects.new(@worker)
|
43
|
+
end
|
44
|
+
|
45
|
+
def tasks
|
46
|
+
CORE::Tasks.new(@worker)
|
47
|
+
end
|
48
|
+
|
49
|
+
def users
|
50
|
+
CORE::Users.new(@worker)
|
51
|
+
end
|
52
|
+
|
53
|
+
def web_and_app
|
54
|
+
CORE::WebAndApp.new(@worker)
|
55
|
+
end
|
56
|
+
|
57
|
+
def worklogs
|
58
|
+
CORE::Worklogs.new(@worker)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module TimeDoctor
|
4
|
+
class Config
|
5
|
+
class << self
|
6
|
+
def configure(options = {}, &blk)
|
7
|
+
@config = OpenStruct.new(options)
|
8
|
+
instance_exec(@config, &blk) if block_given?
|
9
|
+
end
|
10
|
+
|
11
|
+
def config
|
12
|
+
@config ||= OpenStruct.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def [](key)
|
16
|
+
config[key]
|
17
|
+
end
|
18
|
+
|
19
|
+
def []=(key, value)
|
20
|
+
config[key] = value
|
21
|
+
end
|
22
|
+
|
23
|
+
def inspect
|
24
|
+
config.to_h
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module TimeDoctor
|
2
|
+
module Core
|
3
|
+
class AbsentAndLate < Base
|
4
|
+
def list(company_id:, **params)
|
5
|
+
exchange :get, "/v1.1/companies/#{company_id}/absent-and-late", params
|
6
|
+
end
|
7
|
+
|
8
|
+
def update(company_id:, **params)
|
9
|
+
exchange :put, "/v1.1/companies/#{company_id}/absent-and-late", params
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module TimeDoctor
|
2
|
+
module Core
|
3
|
+
class Companies < Base
|
4
|
+
def list(**params)
|
5
|
+
exchange :get, '/v1.1/companies', params
|
6
|
+
end
|
7
|
+
|
8
|
+
def create(**params)
|
9
|
+
exchange :post, '/v1.1/companies', params
|
10
|
+
end
|
11
|
+
|
12
|
+
def invite_user(**params)
|
13
|
+
exchange :post, '/v1.1/companies/invites', params
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module TimeDoctor
|
2
|
+
module Core
|
3
|
+
class Payrolls < Base
|
4
|
+
def list(company_id:, **params)
|
5
|
+
exchange :get, "/v1.1/companies/#{company_id}/payrolls", params
|
6
|
+
end
|
7
|
+
|
8
|
+
def update(company_id:, payroll_id:, **params)
|
9
|
+
exchange :put, "/v1.1/companies/#{company_id}/payrolls/#{payroll_id}", params
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module TimeDoctor
|
2
|
+
module Core
|
3
|
+
class Projects < Base
|
4
|
+
def list(company_id:, user_id:, **params)
|
5
|
+
exchange :get, "/v1.1/companies/#{company_id}/users/#{user_id}/projects", params
|
6
|
+
end
|
7
|
+
|
8
|
+
def create(company_id:, user_id:, **params)
|
9
|
+
exchange :post, "/v1.1/companies/#{company_id}/users/#{user_id}/projects", params
|
10
|
+
end
|
11
|
+
|
12
|
+
def delete(company_id:, user_id:, project_id:, **params)
|
13
|
+
exchange :delete,
|
14
|
+
"/v1.1/companies/#{company_id}/users/#{user_id}/projects/#{project_id}",
|
15
|
+
params
|
16
|
+
end
|
17
|
+
|
18
|
+
def info(company_id:, user_id:, project_id:, **params)
|
19
|
+
exchange :get,
|
20
|
+
"/v1.1/companies/#{company_id}/users/#{user_id}/projects/#{project_id}",
|
21
|
+
params
|
22
|
+
end
|
23
|
+
|
24
|
+
def assign_user(company_id:, user_id:, project_id:, **params)
|
25
|
+
exchange :put,
|
26
|
+
"/v1.1/companies/#{company_id}/users/#{user_id}/projects/#{project_id}",
|
27
|
+
params
|
28
|
+
end
|
29
|
+
|
30
|
+
def unassign_user(company_id:, user_id:, project_id:, **params)
|
31
|
+
exchange :delete,
|
32
|
+
"/v1.1/companies/#{company_id}/users/#{user_id}/projects/#{project_id}/users",
|
33
|
+
params
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module TimeDoctor
|
2
|
+
module Core
|
3
|
+
class Tasks < Base
|
4
|
+
def list(company_id:, user_id:, **params)
|
5
|
+
exchange :get, "/v1.1/companies/#{company_id}/users/#{user_id}/tasks", params
|
6
|
+
end
|
7
|
+
|
8
|
+
def create(company_id:, user_id:, **params)
|
9
|
+
exchange :post, "/v1.1/companies/#{company_id}/users/#{user_id}/tasks", params
|
10
|
+
end
|
11
|
+
|
12
|
+
def info(company_id:, user_id:, task_id:, **params)
|
13
|
+
exchange :get, "/v1.1/companies/#{company_id}/users/#{user_id}/tasks/#{task_id}", params
|
14
|
+
end
|
15
|
+
|
16
|
+
def update(company_id:, user_id:, task_id:, **params)
|
17
|
+
exchange :put, "/v1.1/companies/#{company_id}/users/#{user_id}/tasks/#{task_id}", params
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module TimeDoctor
|
2
|
+
module Core
|
3
|
+
class Users < Base
|
4
|
+
def list(company_id:, **params)
|
5
|
+
exchange :get, "/v1.1/companies/#{company_id}/users", params
|
6
|
+
end
|
7
|
+
|
8
|
+
def info(company_id:, user_id:, **params)
|
9
|
+
exchange :get, "/v1.1/companies/#{company_id}/users/#{user_id}", params
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module TimeDoctor
|
2
|
+
class TimeDoctorError < StandardError
|
3
|
+
def initialize(response)
|
4
|
+
@code = response.status
|
5
|
+
@body = JSON.parse(response.body)
|
6
|
+
@message = create_message
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :code, :body, :message
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def create_message
|
14
|
+
message = indent("Code: #{@code}")
|
15
|
+
@body.delete('code')
|
16
|
+
@body.each { |k, v| message << indent("#{format k}: #{format v}") }
|
17
|
+
message
|
18
|
+
end
|
19
|
+
|
20
|
+
def indent(str)
|
21
|
+
"\n #{str}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def format(str)
|
25
|
+
str.tr('_', ' ').capitalize
|
26
|
+
rescue NoMethodError
|
27
|
+
str
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class UnauthorizedError < TimeDoctorError; end
|
32
|
+
|
33
|
+
class UnknownError < TimeDoctorError; end
|
34
|
+
|
35
|
+
class InvalidRefreshTokenError < TimeDoctorError; end
|
36
|
+
|
37
|
+
class EmptyAccessToken < StandardError
|
38
|
+
attr_reader :message
|
39
|
+
@message = 'The access token is not specified'
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module TimeDoctor
|
2
|
+
class Payload
|
3
|
+
attr_reader :data
|
4
|
+
|
5
|
+
def initialize(payload = {})
|
6
|
+
@data = payload
|
7
|
+
end
|
8
|
+
|
9
|
+
def [](key)
|
10
|
+
data[key] || Config[key]
|
11
|
+
end
|
12
|
+
|
13
|
+
def []=(key, value)
|
14
|
+
data[key] = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(name, *params)
|
18
|
+
callback = self[name]
|
19
|
+
return unless callback
|
20
|
+
|
21
|
+
params = params << self
|
22
|
+
callback.call(*params)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module TimeDoctor
|
2
|
+
class Token
|
3
|
+
class << self
|
4
|
+
ENTRY = 'https://webapi.timedoctor.com/oauth/v2/token'.freeze
|
5
|
+
|
6
|
+
def authorize(payload)
|
7
|
+
payload = Payload.new(payload)
|
8
|
+
|
9
|
+
response = Faraday.get ENTRY,
|
10
|
+
client_id: payload[:client_id],
|
11
|
+
client_secret: payload[:client_secret],
|
12
|
+
code: payload[:code],
|
13
|
+
redirect_uri: payload[:redirect_uri],
|
14
|
+
grant_type: :authorization_code,
|
15
|
+
_format: :json
|
16
|
+
|
17
|
+
data = body(response)
|
18
|
+
payload.call(:on_token_authorize, data)
|
19
|
+
data
|
20
|
+
end
|
21
|
+
|
22
|
+
def refresh(payload)
|
23
|
+
response = Faraday.get ENTRY,
|
24
|
+
refresh_token: payload[:refresh_token],
|
25
|
+
client_id: payload[:client_id],
|
26
|
+
client_secret: payload[:client_secret],
|
27
|
+
grant_type: :refresh_token,
|
28
|
+
_format: :json
|
29
|
+
|
30
|
+
data = body(response)
|
31
|
+
payload[:access_token] = data[:access_token]
|
32
|
+
payload[:refresh_token] = data[:refresh_token]
|
33
|
+
payload.call(:on_token_refresh, data)
|
34
|
+
data
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def body(response)
|
40
|
+
raise UnknownError, response if response.status != 200
|
41
|
+
JSON.parse(response.body, symbolize_names: true)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module TimeDoctor
|
2
|
+
class Worker
|
3
|
+
ENTRY = 'https://webapi.timedoctor.com/'.freeze
|
4
|
+
|
5
|
+
attr_reader :payload
|
6
|
+
|
7
|
+
def initialize(payload)
|
8
|
+
raise EmptyAccessToken unless payload[:access_token]
|
9
|
+
|
10
|
+
@payload = payload
|
11
|
+
@conn = Faraday.new(url: ENTRY)
|
12
|
+
end
|
13
|
+
|
14
|
+
def exchange(method, url, params = {}, badly = false)
|
15
|
+
params[:access_token] = @payload[:access_token]
|
16
|
+
params[:_format] = :json
|
17
|
+
|
18
|
+
response = @conn.public_send method, url, params
|
19
|
+
|
20
|
+
case response.status
|
21
|
+
when 200
|
22
|
+
JSON.parse(response.body, symbolize_names: true)
|
23
|
+
when 401
|
24
|
+
raise UnauthorizedError, response if badly
|
25
|
+
Token.refresh(@payload)
|
26
|
+
exchange(method, url, params, true)
|
27
|
+
else
|
28
|
+
raise UnknownError, response
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/version.rb
ADDED
data/timedoctor.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'timedoctor'
|
7
|
+
spec.version = TimeDoctor::VERSION
|
8
|
+
spec.authors = ['Eugene Yak']
|
9
|
+
spec.email = ['geneayak@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Client for TimeDoctor API'
|
12
|
+
spec.homepage = 'https://github.com/EugeneYak/timedoctor'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'faraday', '~> 0.15.0'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
25
|
+
spec.add_development_dependency 'codecov', '~> 0.1.10'
|
26
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.7'
|
28
|
+
spec.add_development_dependency 'rubocop', '~> 0.55.0'
|
29
|
+
spec.add_development_dependency 'simplecov', '~> 0.16.1'
|
30
|
+
spec.add_development_dependency 'webmock', '~> 3.3'
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: timedoctor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eugene Yak
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.15.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.15.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: codecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.1.10
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.10
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '12.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '12.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.55.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.55.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.16.1
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.16.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.3'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.3'
|
125
|
+
description:
|
126
|
+
email:
|
127
|
+
- geneayak@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".rubocop.yml"
|
135
|
+
- ".simplecov"
|
136
|
+
- ".travis.yml"
|
137
|
+
- Gemfile
|
138
|
+
- Gemfile.lock
|
139
|
+
- LICENSE.txt
|
140
|
+
- README.md
|
141
|
+
- Rakefile
|
142
|
+
- bin/console
|
143
|
+
- bin/setup
|
144
|
+
- lib/timedoctor.rb
|
145
|
+
- lib/timedoctor/client.rb
|
146
|
+
- lib/timedoctor/config.rb
|
147
|
+
- lib/timedoctor/core/absent_late.rb
|
148
|
+
- lib/timedoctor/core/base.rb
|
149
|
+
- lib/timedoctor/core/companies.rb
|
150
|
+
- lib/timedoctor/core/payrolls.rb
|
151
|
+
- lib/timedoctor/core/poortime.rb
|
152
|
+
- lib/timedoctor/core/projects.rb
|
153
|
+
- lib/timedoctor/core/tasks.rb
|
154
|
+
- lib/timedoctor/core/users.rb
|
155
|
+
- lib/timedoctor/core/web_app.rb
|
156
|
+
- lib/timedoctor/core/worklogs.rb
|
157
|
+
- lib/timedoctor/exceptions.rb
|
158
|
+
- lib/timedoctor/payload.rb
|
159
|
+
- lib/timedoctor/token.rb
|
160
|
+
- lib/timedoctor/worker.rb
|
161
|
+
- lib/version.rb
|
162
|
+
- timedoctor.gemspec
|
163
|
+
homepage: https://github.com/EugeneYak/timedoctor
|
164
|
+
licenses:
|
165
|
+
- MIT
|
166
|
+
metadata: {}
|
167
|
+
post_install_message:
|
168
|
+
rdoc_options: []
|
169
|
+
require_paths:
|
170
|
+
- lib
|
171
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
requirements: []
|
182
|
+
rubyforge_project:
|
183
|
+
rubygems_version: 2.7.3
|
184
|
+
signing_key:
|
185
|
+
specification_version: 4
|
186
|
+
summary: Client for TimeDoctor API
|
187
|
+
test_files: []
|