whenkani 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9f7f0865d0d3596b94ea14a999d4c3a0a1ee16ce
4
+ data.tar.gz: 03adb254a2fbf46ebe991ae857ae4ac729263d95
5
+ SHA512:
6
+ metadata.gz: 63f991b89ea064f9103e84422fe49caf54646b33395018fe2d48b591e6d364a30665cd6b70bff173e93ef528a6e15765c8156d7e365e798b56c97b4192d4782a
7
+ data.tar.gz: b491e9a3b154207eab6859514233ac812a90ed5036d22d7f7f70aeaf440936022c9dc6744241b93652d4903df4d2d0e429b71eeb7a10e041eb939da98744445c
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wanikani.gemspec
4
+ gemspec
@@ -0,0 +1,52 @@
1
+ # Whenkani
2
+
3
+ Tells you when you're ready to study at
4
+ [WaniKani](https://www.wanikani.com/dashboard).
5
+
6
+ ## Installing
7
+
8
+ ```
9
+ $ bundle gem install whenkani
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ First, you'll need your API key from your [Account
15
+ page](https://www.wanikani.com/account)
16
+
17
+ Set the API key via an environment variable (usually sourced in a profile):
18
+
19
+ ```
20
+ $ WANIKANI_API_KEY=abcdef12345 whenkani
21
+ ```
22
+
23
+ Set the API key as a command line argument:
24
+ ```
25
+ $ whenkani abcdef12345
26
+ ```
27
+
28
+ ## Output
29
+
30
+ ### When you're ready to study
31
+
32
+ When you have lessons or reviews to do, you'll see this output:
33
+
34
+ ```
35
+ $ whenkani
36
+ You're ready to study!
37
+ https://www.wanikani.com/dashboard
38
+ ```
39
+
40
+ `whenkani` will exit with code 0 if you're ready to study.
41
+
42
+ ### When you have no lessons or reviews
43
+
44
+ When you don't have lessons yet, whenkani will tell you how long to wait:
45
+
46
+ ```
47
+ $ whenkani
48
+ You're not ready, come back in 4 minutes
49
+ ```
50
+
51
+ `whenkani` will exit non-zero if you're not ready to study. This may be useful
52
+ if you want to incorporate this gem into other automation scripts.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "whenkani"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,40 @@
1
+ require "whenkani"
2
+
3
+ api_key = ARGV[0] || ENV['WANIKANI_API_KEY']
4
+ if api_key.nil? || api_key.empty?
5
+ raise <<~USAGE
6
+
7
+ No API key was provided. It's at the bottom fo your WaniKani Account page:
8
+ https://www.wanikani.com/account
9
+
10
+ usage (environment variable):
11
+ WANIKANI_API_KEY=abcdef12345 whenkani
12
+
13
+ usage (command line argument):
14
+ whenkani abcdef12345
15
+
16
+ USAGE
17
+ end
18
+
19
+ def human_time(seconds)
20
+ if seconds < 60
21
+ "#{seconds} seconds"
22
+ elsif seconds < (60 * 60)
23
+ "#{seconds / 60} minutes"
24
+ elsif seconds < (60 * 60 * 24)
25
+ "#{seconds / (60 * 60)} hours"
26
+ else
27
+ "#{seconds / (60 * 60 * 24)} days"
28
+ end
29
+ end
30
+
31
+ seconds = WhenKani.new(api_key).seconds_until_review
32
+
33
+ if seconds > 0
34
+ puts "You're not ready, come back in #{human_time(seconds)}"
35
+ exit 42
36
+ else
37
+ puts "You're ready to study!"
38
+ puts "https://www.wanikani.com/dashboard"
39
+ exit 0
40
+ end
@@ -0,0 +1,24 @@
1
+ require "net/http"
2
+ require "json"
3
+ require "whenkani/version"
4
+
5
+ class WhenKani
6
+ def initialize(api_key)
7
+ @api_key = api_key
8
+ end
9
+
10
+ def seconds_until_review
11
+ uri = URI("https://www.wanikani.com/api/user/#{@api_key}/study-queue")
12
+ response = JSON.parse(Net::HTTP.get(uri))
13
+ raise response["error"]["message"] if response.has_key?("error")
14
+ info = response["requested_information"]
15
+ seconds = info["next_review_date"] - Time.new.to_i
16
+ if info["reviews_available"] > 0 ||
17
+ info["lessons_available"] > 0 ||
18
+ seconds < 0
19
+ 0
20
+ else
21
+ seconds
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ class WhenKani
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'whenkani/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "whenkani"
8
+ spec.version = WhenKani::VERSION
9
+ spec.authors = ["Justin Searls"]
10
+ spec.email = ["searls@gmail.com"]
11
+
12
+ spec.summary = %q{Tells you when you're ready to study WaniKani}
13
+ spec.description = %q{Helps you know when you're ready to study WaniKani}
14
+ spec.homepage = "https://github.com/searls/whenkani"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.13"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "pry"
26
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: whenkani
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Searls
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-17 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
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: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Helps you know when you're ready to study WaniKani
56
+ email:
57
+ - searls@gmail.com
58
+ executables:
59
+ - whenkani
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - exe/whenkani
71
+ - lib/whenkani.rb
72
+ - lib/whenkani/version.rb
73
+ - whenkani.gemspec
74
+ homepage: https://github.com/searls/whenkani
75
+ licenses: []
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.5.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Tells you when you're ready to study WaniKani
97
+ test_files: []