akashiyaki 0.1.0 → 0.2.0

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
  SHA1:
3
- metadata.gz: 3516ea38703505100c73a82cd3262c704ec333b9
4
- data.tar.gz: 649780f3325523cb58182e656c726c06df5e206a
3
+ metadata.gz: 652a4b0a3b87f208ed5b4e3bf586aafdb943421f
4
+ data.tar.gz: 5c4ee1c02c2a749ca78bdf9b04e76b841d8e64b0
5
5
  SHA512:
6
- metadata.gz: bb0914d7efb2e55d789ebaecead204ec5caf60548c67027335c78c12d26afc3ed5f25df11bbda4e2aa8f04a29fca10bb0b0629b90f7187bcf670721031b2d6bb
7
- data.tar.gz: 38a6cec60f5d6b6d9567407c4bcea47f94d9872a54b172e44b2b2b721ad7f0401410af314c91d4632b67242a8346bcc790c92fb12fc0e5b7cb94230662561f38
6
+ metadata.gz: b415ece85b90835994b649f888bac5378c22e81ed3041971a43616afbcf599f2f1ae71ee692890c55a09d71c4db73c8f790a802765ffa8f56ae91609ed47f9df
7
+ data.tar.gz: cecd482c7b2f9f1ce8f3ad25cdb48ad5592fcb2e85b21d1010d3599debb88b6eb752da82c503fc80373e8410e46d68ea52e31f6f6acea6dd668828608e2ea3f6
data/README.md CHANGED
@@ -18,7 +18,7 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install akashiyaki
20
20
 
21
- ## Usage
21
+ ## Library
22
22
 
23
23
  ```rb
24
24
  require "akashiyaki"
@@ -30,10 +30,67 @@ client.start_break
30
30
  client.finish_break
31
31
  ```
32
32
 
33
+ ## CLI
34
+
35
+ Akashiyaki includes `ak4` command that is a CLI tool to access AKASHI.
36
+
37
+ Basic usage:
38
+
39
+ ```bash
40
+ # To start work
41
+ ak4 work start
42
+
43
+ # To finish work
44
+ ak4 work finish
45
+
46
+ # To start break
47
+ ak4 break start
48
+
49
+ # To finish break
50
+ ak4 break finish
51
+ ```
52
+
53
+ When `ak4` is executed without account information, `ak4` asks you about your account:
54
+
55
+ ```bash
56
+ $ ak4 work finish
57
+ Company ID: mycompany
58
+ Login ID: myid
59
+ Password: %
60
+ ```
61
+
62
+ If you think it's too much bother to enter account information everytime, you can save your account as configuration file `~/.config/ak4/account.yaml` (or `~/.config/ak4/account.json`):
63
+
64
+ ```yaml
65
+ company: mycompany
66
+ id: myid
67
+ password: mypassword
68
+ ```
69
+
70
+ `ak4` reads account information from `$XDG_CONFIG_HOME` directory.
71
+
72
+ If you don't want to save your password, you can save only company ID and login ID:
73
+
74
+ ```yaml
75
+ company: mycompany
76
+ id: myid
77
+ ```
78
+
79
+ So `ak4` asks you about only password.
80
+
81
+ You can also use command options:
82
+
83
+ ```bash
84
+ Options:
85
+ [--config=CONFIG]
86
+ -c, [--company=COMPANY]
87
+ -i, [--id=ID]
88
+ -p, [--password=PASSWORD]
89
+ ```
90
+
33
91
  ## Development
34
92
 
35
93
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
-
37
94
  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).
38
95
 
39
96
  ## Contributing
data/akashiyaki.gemspec CHANGED
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "minitest", "~> 5.0"
26
26
 
27
27
  spec.add_runtime_dependency "mechanize", "~> 2.7.5"
28
+ spec.add_runtime_dependency "thor", "~> 0.19.4"
28
29
  end
data/exe/ak4 ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
5
+
6
+ require "akashiyaki/cli"
7
+
8
+ Akashiyaki::Cli.start(ARGV)
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ Account = Struct.new("Account", :company, :id, :password)
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "io/console"
4
+ require "json"
5
+ require "yaml"
6
+
7
+ require "akashiyaki/account"
8
+
9
+ module Akashiyaki
10
+ class AccountParser
11
+ def initialize(options)
12
+ @options = options
13
+ end
14
+
15
+ def parse
16
+ Account.new(company, id, password)
17
+ end
18
+
19
+ private
20
+
21
+ def company
22
+ return @options[:company] if @options[:company]
23
+ return config["company"] if config["company"]
24
+
25
+ print "Company ID: "
26
+ STDIN.gets.chomp
27
+ end
28
+
29
+ def config
30
+ @config ||= load_config_file
31
+ end
32
+
33
+ def id
34
+ return @options[:id] if @options[:id]
35
+ return config["id"] if config["id"]
36
+
37
+ print "Login ID: "
38
+ STDIN.gets.chomp
39
+ end
40
+
41
+ def password
42
+ return @options[:password] if @options[:password]
43
+ return config[:password] if config[:password]
44
+
45
+ print "Password: "
46
+ STDIN.noecho(&:gets).chomp
47
+ end
48
+
49
+ def search_config
50
+ if @options[:config]
51
+ path = File.expand_path(@options[:config])
52
+ return path if File.exist?(path)
53
+ end
54
+
55
+ %w(json yaml yml).each do |ext|
56
+ path = File.join(config_dir, "account.#{ext}")
57
+ return path if File.exist?(path)
58
+ end
59
+
60
+ nil
61
+ end
62
+
63
+ def config_dir
64
+ @config_dir ||=
65
+ File.join(
66
+ ENV["XDG_CONFIG_HOME"] || File.expand_path("~/.config"),
67
+ "ak4"
68
+ )
69
+ end
70
+
71
+ def load_config_file
72
+ config_file = search_config
73
+
74
+ return {} unless config_file
75
+
76
+ case config_file
77
+ when /\.json$/
78
+ JSON.parse(File.read(config_file))
79
+ when /\.ya?ml$/
80
+ YAML.load_file(config_file)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,50 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require "thor"
5
+
6
+ require "akashiyaki/account_parser"
7
+ require "akashiyaki/command"
8
+
9
+ module Akashiyaki
10
+ class Cli < Thor
11
+ class << self
12
+ def mode(mode, start, finish)
13
+ desc "#{mode} ACTION [options]", "#{start}/#{finish}"
14
+ subcommand mode, command_class(mode, start, finish)
15
+ end
16
+
17
+ private
18
+
19
+ def command_class(mode, start, finish)
20
+ Class.new(Thor).tap do |c|
21
+ c.desc "start [options]", start
22
+ c.send(:define_method, :start) do
23
+ Command.new(
24
+ mode,
25
+ :start,
26
+ AccountParser.new(options).parse
27
+ ).run
28
+ end
29
+
30
+ c.desc "finish [options]", finish
31
+ c.send(:define_method, :finish) do
32
+ Command.new(
33
+ mode,
34
+ :finish,
35
+ AccountParser.new(options).parse
36
+ ).run
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ class_option :config, type: :string
43
+ class_option :company, aliases: "-c", type: :string
44
+ class_option :id, aliases: "-i", type: :string
45
+ class_option :password, aliases: "-p", type: :string
46
+
47
+ mode("work", "出勤", "退勤")
48
+ mode("break", "休憩開始", "休憩終了")
49
+ end
50
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "akashiyaki/client"
4
+
5
+ module Akashiyaki
6
+ class Command
7
+ attr_reader :mode, :action, :account
8
+
9
+ def initialize(mode, action, account)
10
+ @mode = mode
11
+ @action = action
12
+ @account = account
13
+ end
14
+
15
+ def run
16
+ client.send(:"#{action}_#{mode}")
17
+ end
18
+
19
+ private
20
+
21
+ def client
22
+ @client ||=
23
+ Client.new(
24
+ account.company,
25
+ account.id,
26
+ account.password
27
+ )
28
+ end
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Akashiyaki
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: akashiyaki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nownabe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-02 00:00:00.000000000 Z
11
+ date: 2017-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,10 +66,25 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.7.5
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.19.4
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.19.4
69
83
  description:
70
84
  email:
71
85
  - nownabe@gmail.com
72
- executables: []
86
+ executables:
87
+ - ak4
73
88
  extensions: []
74
89
  extra_rdoc_files: []
75
90
  files:
@@ -82,8 +97,13 @@ files:
82
97
  - akashiyaki.gemspec
83
98
  - bin/console
84
99
  - bin/setup
100
+ - exe/ak4
85
101
  - lib/akashiyaki.rb
102
+ - lib/akashiyaki/account.rb
103
+ - lib/akashiyaki/account_parser.rb
104
+ - lib/akashiyaki/cli.rb
86
105
  - lib/akashiyaki/client.rb
106
+ - lib/akashiyaki/command.rb
87
107
  - lib/akashiyaki/version.rb
88
108
  homepage: https://github.com/nownabe/akashiyaki
89
109
  licenses: