ruboty-jobcan 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/ruboty/actions/jobcan.rb +104 -0
- data/lib/ruboty/handlers/jobcan.rb +35 -0
- data/lib/ruboty/jobcan.rb +3 -0
- data/lib/ruboty/jobcan/version.rb +5 -0
- data/ruboty-jobcan.gemspec +27 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d024fdf806849cce74402a4f3ff17cfc85c1102b
|
4
|
+
data.tar.gz: f91996db70b6e397e3458b3d9598d66c6c28b596
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 14a0a391c1b2fec21b64c20602a65aee20738811b5ff08a5353d39348e499ab0e4ebfd6417457306007140682ff9cde659b670b4aa56c1b1f6a3042a29f34009
|
7
|
+
data.tar.gz: 175d4e6ed45dfcb90b60a151e1d8b7fe8aff6b8109a5a9596413de1540afc68ebbcb7b64c2470ce92890f12b45f050191317e8b5bca0145aafd15709e95db55a
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Ruboty::Jobcan
|
2
|
+
|
3
|
+
```
|
4
|
+
ruboty remember my jobcan code <code>
|
5
|
+
ruboty remember my jobcan group id <group_id>
|
6
|
+
ruboty punch the clock
|
7
|
+
```
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'ruboty-jobcan'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install ruboty-jobcan
|
23
|
+
|
24
|
+
## Development
|
25
|
+
|
26
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
27
|
+
|
28
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ruboty-jobcan.
|
33
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ruboty/jobcan"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday-cookie_jar"
|
3
|
+
|
4
|
+
module Ruboty
|
5
|
+
module Actions
|
6
|
+
class Jobcan
|
7
|
+
NAMESPACE = "jobcan"
|
8
|
+
|
9
|
+
attr_reader :message
|
10
|
+
|
11
|
+
def initialize(message)
|
12
|
+
@message = message
|
13
|
+
end
|
14
|
+
|
15
|
+
def remember_code
|
16
|
+
user_data["code"] = message[:code]
|
17
|
+
message.reply("I remember.")
|
18
|
+
end
|
19
|
+
|
20
|
+
def remember_group_id
|
21
|
+
user_data["group_id"] = message[:group_id]
|
22
|
+
message.reply("I remember.")
|
23
|
+
end
|
24
|
+
|
25
|
+
def punch_clock
|
26
|
+
unless (code = user_data["code"])
|
27
|
+
message.reply("I don't know your JOBCAN code.")
|
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)
|
35
|
+
client.authenticate!
|
36
|
+
status = client.punch_clock!
|
37
|
+
message.reply("OK, your current status is #{status}.")
|
38
|
+
rescue
|
39
|
+
message.reply("Error: #{$!}")
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def user_data
|
45
|
+
brain_space = message.robot.brain.data[NAMESPACE] ||= {}
|
46
|
+
brain_space[message.from_name] ||= {}
|
47
|
+
end
|
48
|
+
|
49
|
+
class JobcanClient
|
50
|
+
def initialize(code, group_id)
|
51
|
+
@code = code
|
52
|
+
@group_id = group_id
|
53
|
+
end
|
54
|
+
|
55
|
+
def authenticate!
|
56
|
+
response = faraday.get(authenticate_url)
|
57
|
+
unless response.status == 200
|
58
|
+
fail "could not log in to JOBCAN; it returned #{response.status}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def punch_clock!
|
63
|
+
response = faraday.post(punch_clock_url, punch_clock_request_body)
|
64
|
+
unless response.status == 200
|
65
|
+
fail "could not punch the clock on JOBCAN; it returned #{response.status}"
|
66
|
+
end
|
67
|
+
result = JSON.parse(response.body) or fail "could not parse response"
|
68
|
+
if result["result"] == 0
|
69
|
+
if result["errors"] && result["errors"]["aditCount"] == "duplicate"
|
70
|
+
fail "you have punched the clock within a minute"
|
71
|
+
end
|
72
|
+
fail result["errors"].to_s
|
73
|
+
end
|
74
|
+
result["current_status"]
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def faraday
|
80
|
+
@faraday ||= Faraday.new do |builder|
|
81
|
+
# Note that the server will return JSON string with text/html content type.
|
82
|
+
# Don't use `builder.response :json` here.
|
83
|
+
builder.request :url_encoded
|
84
|
+
builder.use FaradayMiddleware::FollowRedirects
|
85
|
+
builder.use :cookie_jar
|
86
|
+
builder.adapter Faraday.default_adapter
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def authenticate_url
|
91
|
+
"https://ssl.jobcan.jp/employee?code=#{@code}"
|
92
|
+
end
|
93
|
+
|
94
|
+
def punch_clock_url
|
95
|
+
"https://ssl.jobcan.jp/employee/index/adit"
|
96
|
+
end
|
97
|
+
|
98
|
+
def punch_clock_request_body
|
99
|
+
{ is_yakin: "0", adit_item: "DEF", adit_group_id: @group_id, notice: "" }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Handlers
|
3
|
+
class Jobcan < Base
|
4
|
+
on(
|
5
|
+
/remember my jobcan code (?<code>[0-9a-f]{32})\z/,
|
6
|
+
description: "Remember sender's JOBCAN code",
|
7
|
+
name: "remember_code",
|
8
|
+
)
|
9
|
+
|
10
|
+
on(
|
11
|
+
/remember my jobcan group id (?<group_id>\d+)\z/,
|
12
|
+
description: "Remember sender's JOBCAN group ID",
|
13
|
+
name: "remember_group_id",
|
14
|
+
)
|
15
|
+
|
16
|
+
on(
|
17
|
+
/punch the clock\z/,
|
18
|
+
description: "Punch the clock on JOBCAN",
|
19
|
+
name: "punch_clock",
|
20
|
+
)
|
21
|
+
|
22
|
+
def remember_code(message)
|
23
|
+
Ruboty::Actions::Jobcan.new(message).remember_code
|
24
|
+
end
|
25
|
+
|
26
|
+
def remember_group_id(message)
|
27
|
+
Ruboty::Actions::Jobcan.new(message).remember_group_id
|
28
|
+
end
|
29
|
+
|
30
|
+
def punch_clock(message)
|
31
|
+
Ruboty::Actions::Jobcan.new(message).punch_clock
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruboty/jobcan/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruboty-jobcan"
|
8
|
+
spec.version = Ruboty::Jobcan::VERSION
|
9
|
+
spec.authors = ["Tomoki Aonuma"]
|
10
|
+
spec.email = ["uasi@uasi.jp"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruboty plug-in for punching the clock on JOBCAN.}
|
13
|
+
spec.description = %q{Ruboty plug-in for punching the clock on JOBCAN.}
|
14
|
+
spec.homepage = "https://github.com/uasi/ruboty-jobcan"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "faraday", "~> 0.9.0"
|
25
|
+
spec.add_runtime_dependency "faraday_middleware", "~> 0.10.0"
|
26
|
+
spec.add_runtime_dependency "faraday-cookie_jar", "~> 0.0.6"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-jobcan
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomoki Aonuma
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.9.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday_middleware
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.10.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.10.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday-cookie_jar
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.0.6
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.0.6
|
83
|
+
description: Ruboty plug-in for punching the clock on JOBCAN.
|
84
|
+
email:
|
85
|
+
- uasi@uasi.jp
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- lib/ruboty/actions/jobcan.rb
|
98
|
+
- lib/ruboty/handlers/jobcan.rb
|
99
|
+
- lib/ruboty/jobcan.rb
|
100
|
+
- lib/ruboty/jobcan/version.rb
|
101
|
+
- ruboty-jobcan.gemspec
|
102
|
+
homepage: https://github.com/uasi/ruboty-jobcan
|
103
|
+
licenses: []
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.4.5.1
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Ruboty plug-in for punching the clock on JOBCAN.
|
125
|
+
test_files: []
|