ruboty-jobcan 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +50 -4
- data/img/group_id.png +0 -0
- data/lib/ruboty/actions/jobcan.rb +60 -75
- data/lib/ruboty/handlers/jobcan.rb +10 -20
- data/lib/ruboty/jobcan/version.rb +1 -1
- data/ruboty-jobcan.gemspec +4 -3
- metadata +24 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73e500010b3adf3025367661723360fa555e24b4
|
4
|
+
data.tar.gz: 4c29f7959546bb61e86d07401c320d4a0aab2e87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c43a02dfd75f6538fa8238c640bf1612696540d07d92ce3feae3459668bd42aa55a70617728bfcfd6baf3c5afba870a247a8fb381ab22c7542db1dccfabc397
|
7
|
+
data.tar.gz: bd5a0dbce45340ec74b456d0a9bf192c097d9e2e732c4b2fcab5703e7e943a945b1653f8816a021596ca831f2f32571a339896d30ceb72ed29e360a48b0df38c
|
data/README.md
CHANGED
@@ -1,13 +1,60 @@
|
|
1
1
|
# Ruboty::Jobcan
|
2
2
|
|
3
|
+
## Usage
|
4
|
+
|
5
|
+
To use JOBCAN API, you have to teach Ruboty either your code or login info.
|
6
|
+
|
7
|
+
### Teach JOBCAN code
|
8
|
+
|
3
9
|
```
|
4
10
|
ruboty remember my jobcan code <code>
|
11
|
+
```
|
12
|
+
|
13
|
+
`<code>` is the text attached to your mobile login URL,
|
14
|
+
e.g. `http://jobcan.jp/m?code=YOUR_CODE_GOES_HERE`.
|
15
|
+
Check out the invitation email from JOBCAN for the URL.
|
16
|
+
|
17
|
+
|
18
|
+
### Teach client ID, email, and password
|
19
|
+
|
20
|
+
Alternatively, you can use these environment variables to provide your credentials.
|
21
|
+
|
22
|
+
```
|
23
|
+
RUBOTY_JOBCAN_CLIENT_ID
|
24
|
+
RUBOTY_JOBCAN_EMAIL
|
25
|
+
RUBOTY_JOBCAN_PASSWORD
|
26
|
+
```
|
27
|
+
|
28
|
+
### Set group ID
|
29
|
+
|
30
|
+
Then set your default group ID.
|
31
|
+
|
32
|
+
```
|
5
33
|
ruboty remember my jobcan group id <group_id>
|
6
|
-
ruboty punch the clock
|
7
34
|
```
|
8
35
|
|
9
|
-
|
36
|
+
`<group_id>` is the numeric ID of your group;
|
37
|
+
ask your manager or check out the source code of https://ssl.jobcan.jp/employee for it.
|
38
|
+
|
39
|
+
![group ID](img/group_id.png)
|
40
|
+
|
41
|
+
|
42
|
+
You can also use group name aliases.
|
43
|
+
|
44
|
+
```
|
45
|
+
ruboty register my jobcan group alias <group_name> -> <group_id>
|
46
|
+
```
|
47
|
+
|
48
|
+
### Clock in/out
|
10
49
|
|
50
|
+
```
|
51
|
+
ruboty clock in
|
52
|
+
ruboty clock out
|
53
|
+
ruboty clock in at <group_name>
|
54
|
+
ruboty clock out at <group_name>
|
55
|
+
```
|
56
|
+
|
57
|
+
## Installation
|
11
58
|
|
12
59
|
```ruby
|
13
60
|
gem 'ruboty-jobcan'
|
@@ -29,5 +76,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
29
76
|
|
30
77
|
## Contributing
|
31
78
|
|
32
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
33
|
-
|
79
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/uasi/ruboty-jobcan.
|
data/img/group_id.png
ADDED
Binary file
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require "faraday"
|
2
|
+
require "faraday_middleware"
|
2
3
|
require "faraday-cookie_jar"
|
4
|
+
require "jbcn"
|
3
5
|
|
4
6
|
module Ruboty
|
5
7
|
module Actions
|
@@ -22,99 +24,82 @@ module Ruboty
|
|
22
24
|
message.reply("I remember.")
|
23
25
|
end
|
24
26
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
return
|
29
|
-
end
|
30
|
-
unless (group_id = user_data["group_id"])
|
31
|
-
message.reply("I don't know your JOBCAN group ID.")
|
32
|
-
return
|
33
|
-
end
|
34
|
-
client = JobcanClient.new(code, group_id, in_out)
|
35
|
-
client.authenticate!
|
36
|
-
status = client.punch_clock!
|
37
|
-
message.reply("OK, your current status is #{status}.")
|
38
|
-
rescue
|
39
|
-
message.reply("Error: #{$!}")
|
27
|
+
def register_group_alias
|
28
|
+
user_data["alias_#{message[:group_name]}"] = message[:group_id]
|
29
|
+
message.reply("I registered alias #{message[:group_name]} to ID #{message[:group_id]}.")
|
40
30
|
end
|
41
31
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
def clock_out
|
47
|
-
punch_clock(:out)
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
def user_data
|
53
|
-
brain_space = message.robot.brain.data[NAMESPACE] ||= {}
|
54
|
-
brain_space[message.from_name] ||= {}
|
55
|
-
end
|
56
|
-
|
57
|
-
class JobcanClient
|
58
|
-
def initialize(code, group_id, in_out)
|
59
|
-
@code = code
|
60
|
-
@group_id = group_id
|
61
|
-
@in_out = in_out
|
32
|
+
def clock_in_out
|
33
|
+
unless client
|
34
|
+
message.reply("I don't know your JOBCAN login info.")
|
35
|
+
return
|
62
36
|
end
|
63
37
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
38
|
+
if (group_name = message[:group_name])
|
39
|
+
unless (group_id = user_data["alias_#{group_name}"])
|
40
|
+
message.reply("I don't know that JOBCAN group alias '#{group_name}'.")
|
41
|
+
return
|
42
|
+
end
|
43
|
+
else
|
44
|
+
unless (group_id = user_data["group_id"])
|
45
|
+
message.reply("I don't know your JOBCAN group ID.")
|
46
|
+
return
|
68
47
|
end
|
69
48
|
end
|
70
49
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
76
|
-
result = JSON.parse(response.body) or fail "could not parse response"
|
77
|
-
if result["result"] == 0
|
78
|
-
if result["errors"] && result["errors"]["aditCount"] == "duplicate"
|
79
|
-
fail "you have punched the clock within a minute"
|
80
|
-
end
|
81
|
-
fail result["errors"].to_s
|
82
|
-
end
|
83
|
-
result["current_status"]
|
50
|
+
result = client.clock(message[:in_out].to_sym, group_id: group_id)
|
51
|
+
unless result.is_a?(Hash) && (current_status = result["current_status"])
|
52
|
+
message.reply("I got unknown response from JOBCAN: #{result}.")
|
53
|
+
return
|
84
54
|
end
|
85
55
|
|
86
|
-
|
56
|
+
message.reply("OK, your current status is #{current_status}.")
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
87
60
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
builder.adapter Faraday.default_adapter
|
61
|
+
def client
|
62
|
+
unless instance_variable_defined?(:@client)
|
63
|
+
if (credentials = code_credentials || user_credentials)
|
64
|
+
@client = Jbcn::Client.new
|
65
|
+
@client.authenticate(credentials)
|
66
|
+
else
|
67
|
+
@client = nil
|
96
68
|
end
|
97
69
|
end
|
70
|
+
@client
|
71
|
+
end
|
98
72
|
|
99
|
-
|
100
|
-
|
73
|
+
def code_credentials
|
74
|
+
if (code = user_data["code"])
|
75
|
+
Jbcn::CodeCredentials.new(code)
|
76
|
+
else
|
77
|
+
nil
|
101
78
|
end
|
79
|
+
end
|
102
80
|
|
103
|
-
|
104
|
-
|
81
|
+
def user_credentials
|
82
|
+
if login_env_present?
|
83
|
+
Jbcn::UserCredentials.new(
|
84
|
+
client_id: ENV["RUBOTY_JOBCAN_CLIENT_ID"],
|
85
|
+
username: ENV["RUBOTY_JOBCAN_USERNAME"] || ENV["RUBOTY_JOBCAN_EMAIL"],
|
86
|
+
password: ENV["RUBOTY_JOBCAN_PASSWORD"])
|
87
|
+
else
|
88
|
+
nil
|
105
89
|
end
|
90
|
+
end
|
106
91
|
|
107
|
-
|
108
|
-
|
109
|
-
|
92
|
+
def user_data
|
93
|
+
brain_space = message.robot.brain.data[NAMESPACE] ||= {}
|
94
|
+
brain_space[message.from_name] ||= {}
|
95
|
+
end
|
110
96
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
end
|
97
|
+
def login_env_present?
|
98
|
+
!!(
|
99
|
+
ENV["RUBOTY_JOBCAN_CLIENT_ID"] &&
|
100
|
+
ENV["RUBOTY_JOBCAN_PASSWORD"] &&
|
101
|
+
(ENV["RUBOTY_JOBCAN_USERNAME"] || ENV["RUBOTY_JOBCAN_EMAIL"])
|
102
|
+
)
|
118
103
|
end
|
119
104
|
end
|
120
105
|
end
|
@@ -14,21 +14,15 @@ module Ruboty
|
|
14
14
|
)
|
15
15
|
|
16
16
|
on(
|
17
|
-
/
|
18
|
-
description: "
|
19
|
-
name: "
|
17
|
+
/register my jobcan group alias (?<group_name>.+?) -> (?<group_id>\d+)\z/,
|
18
|
+
description: "Create alias to JOBCAN group ID",
|
19
|
+
name: "register_group_alias",
|
20
20
|
)
|
21
21
|
|
22
22
|
on(
|
23
|
-
/clock in
|
24
|
-
description: "Clock in on JOBCAN",
|
25
|
-
name: "
|
26
|
-
)
|
27
|
-
|
28
|
-
on(
|
29
|
-
/clock out\z/,
|
30
|
-
description: "Clock out on JOBCAN",
|
31
|
-
name: "clock_out",
|
23
|
+
/clock (?<in_out>in|out)(?: at (?<group_name>.+))?\z/,
|
24
|
+
description: "Clock in/out on JOBCAN (at group)",
|
25
|
+
name: "clock_in_out",
|
32
26
|
)
|
33
27
|
|
34
28
|
def remember_code(message)
|
@@ -39,16 +33,12 @@ module Ruboty
|
|
39
33
|
Ruboty::Actions::Jobcan.new(message).remember_group_id
|
40
34
|
end
|
41
35
|
|
42
|
-
def
|
43
|
-
Ruboty::Actions::Jobcan.new(message).
|
44
|
-
end
|
45
|
-
|
46
|
-
def clock_in(message)
|
47
|
-
Ruboty::Actions::Jobcan.new(message).clock_in
|
36
|
+
def register_group_alias(message)
|
37
|
+
Ruboty::Actions::Jobcan.new(message).register_group_alias
|
48
38
|
end
|
49
39
|
|
50
|
-
def
|
51
|
-
Ruboty::Actions::Jobcan.new(message).
|
40
|
+
def clock_in_out(message)
|
41
|
+
Ruboty::Actions::Jobcan.new(message).clock_in_out
|
52
42
|
end
|
53
43
|
end
|
54
44
|
end
|
data/ruboty-jobcan.gemspec
CHANGED
@@ -21,7 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.10"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
23
|
|
24
|
-
spec.add_runtime_dependency "faraday", "~> 0.9
|
25
|
-
spec.add_runtime_dependency "faraday_middleware", "~> 0.10
|
26
|
-
spec.add_runtime_dependency "faraday-cookie_jar", "~> 0.0
|
24
|
+
spec.add_runtime_dependency "faraday", "~> 0.9"
|
25
|
+
spec.add_runtime_dependency "faraday_middleware", "~> 0.10"
|
26
|
+
spec.add_runtime_dependency "faraday-cookie_jar", "~> 0.0"
|
27
|
+
spec.add_runtime_dependency "jbcn", "~> 0.1"
|
27
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-jobcan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomoki Aonuma
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,42 +44,56 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.9
|
47
|
+
version: '0.9'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.9
|
54
|
+
version: '0.9'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: faraday_middleware
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.10
|
61
|
+
version: '0.10'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.10
|
68
|
+
version: '0.10'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: faraday-cookie_jar
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.0
|
75
|
+
version: '0.0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.0
|
82
|
+
version: '0.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: jbcn
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.1'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.1'
|
83
97
|
description: Ruboty plug-in for punching the clock on JOBCAN.
|
84
98
|
email:
|
85
99
|
- uasi@uasi.jp
|
@@ -94,6 +108,7 @@ files:
|
|
94
108
|
- Rakefile
|
95
109
|
- bin/console
|
96
110
|
- bin/setup
|
111
|
+
- img/group_id.png
|
97
112
|
- lib/ruboty/actions/jobcan.rb
|
98
113
|
- lib/ruboty/handlers/jobcan.rb
|
99
114
|
- lib/ruboty/jobcan.rb
|
@@ -118,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
133
|
version: '0'
|
119
134
|
requirements: []
|
120
135
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
136
|
+
rubygems_version: 2.6.8
|
122
137
|
signing_key:
|
123
138
|
specification_version: 4
|
124
139
|
summary: Ruboty plug-in for punching the clock on JOBCAN.
|