habitica_cli 0.0.1
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 +15 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +12 -0
- data/bin/habitica +14 -0
- data/habitica-cli.gemspec +31 -0
- data/lib/habitica_cli/api.rb +46 -0
- data/lib/habitica_cli/cache.rb +43 -0
- data/lib/habitica_cli/commands/add.rb +17 -0
- data/lib/habitica_cli/commands/clear.rb +14 -0
- data/lib/habitica_cli/commands/do.rb +16 -0
- data/lib/habitica_cli/commands/list.rb +15 -0
- data/lib/habitica_cli/commands/shared.rb +39 -0
- data/lib/habitica_cli/commands/status.rb +23 -0
- data/lib/habitica_cli/constants.rb +7 -0
- data/lib/habitica_cli/main.rb +67 -0
- data/lib/habitica_cli/version.rb +3 -0
- data/lib/habitica_cli.rb +24 -0
- data/spec/api_spec.rb +28 -0
- data/spec/cache_spec.rb +64 -0
- data/spec/habitica_cli_spec.rb +4 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/support/.gitkeep +0 -0
- metadata +208 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fbb422d94f5bab18d8ee01b611d5722b31809ec8
|
4
|
+
data.tar.gz: dfef128671329117f2b75d43f05fd1f839cb9e75
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c9f1f8db03e4c756ec5be6bd0b2a94ce8d7b791a551899ba61708018b7df98a1e313ca26f1f035e8678b9cebb2b7c855a49df4e113077112b3d8fa6218fcc8cc
|
7
|
+
data.tar.gz: 96f988ef139e80ab147858f5c16a8cf921447f3b19fa23c5465129586712ac353e3025948eb222c190cfb4b0666c0627d775f70b68e0ccdf780af9a5fa399113
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.2
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 Nick Tomlin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# habitica-cli
|
2
|
+
|
3
|
+
A command line interface for habitica
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'habitica-cli'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install habitica-cli
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
The cli needs your habitica user id and api key. You can configure these via the following:
|
24
|
+
|
25
|
+
- Setting/Exporting `HABIT_USER` and `HABIT_KEY` in your environment
|
26
|
+
- Using the `--habit-user` and `--habit-key` flags e.g. `habitica list --habit-user='user-id' --habit-key='user-api-key'`
|
27
|
+
|
28
|
+
```shell
|
29
|
+
habitica <command> <action>
|
30
|
+
```
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
```
|
35
|
+
bundle
|
36
|
+
# lint and run specs
|
37
|
+
rake
|
38
|
+
|
39
|
+
# run specs
|
40
|
+
rake spec
|
41
|
+
|
42
|
+
# lint
|
43
|
+
rake rubocop
|
44
|
+
```
|
45
|
+
|
46
|
+
1. Fork it ( https://github.com/[my-github-username]/habitica-cli/fork )
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rubocop/rake_task'
|
3
|
+
require 'rubygems/package_task'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
spec = eval(File.read('habitica-cli.gemspec')) # rubocop:disable Lint/Eval
|
7
|
+
|
8
|
+
Gem::PackageTask.new(spec)
|
9
|
+
RuboCop::RakeTask.new
|
10
|
+
RSpec::Core::RakeTask.new(:spec)
|
11
|
+
|
12
|
+
task default: %w(rubocop spec)
|
data/bin/habitica
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'habitica_cli'
|
4
|
+
|
5
|
+
banner = <<-BANNER
|
6
|
+
____ ____ ____ ____ ____ ____ ____ ____
|
7
|
+
||h ||||a ||||b ||||i ||||t ||||i ||||c ||||a ||
|
8
|
+
||__||||__||||__||||__||||__||||__||||__||||__||
|
9
|
+
|
10
|
+
BANNER
|
11
|
+
|
12
|
+
puts banner if ARGV.empty?
|
13
|
+
|
14
|
+
HabiticaCli.start(ARGV)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'habitica_cli/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'habitica_cli'
|
8
|
+
spec.version = HabiticaCli::VERSION
|
9
|
+
spec.authors = ['Nick Tomlin']
|
10
|
+
spec.email = ['nick.tomlin@gmail.com']
|
11
|
+
spec.summary = 'A minimal CLI for habitica'
|
12
|
+
spec.description = 'Provides a minijmal highline based ruby cli for habitica' # rubocop:disable Metrics/LineLength
|
13
|
+
spec.homepage = 'https://github.com/nicktomlin/habitica-cli-ruby'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables << 'habitica'
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'faraday', '~> 0.9.2'
|
22
|
+
spec.add_dependency 'faraday_middleware', '~> 0.10.0'
|
23
|
+
spec.add_dependency 'thor', '~> 0.19.1'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rubocop', '~> 0.36.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.4.0'
|
29
|
+
spec.add_development_dependency 'webmock', '~> 1.22', '>= 1.22.6'
|
30
|
+
spec.add_development_dependency 'pry'
|
31
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module HabiticaCli
|
2
|
+
# responsible for communicating with habit at a low level
|
3
|
+
class Api
|
4
|
+
def initialize(user_id, api_token)
|
5
|
+
@debug = ENV['DEBUG_HABITICA'] == 'true'
|
6
|
+
|
7
|
+
@connection = create_connection(user_id, api_token)
|
8
|
+
end
|
9
|
+
|
10
|
+
def get(url)
|
11
|
+
@connection.get(url)
|
12
|
+
end
|
13
|
+
|
14
|
+
def post(url, body = nil)
|
15
|
+
@connection.post(url, body)
|
16
|
+
end
|
17
|
+
|
18
|
+
def put(url, body)
|
19
|
+
@connection.put(url, body)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def default_headers(user_id, api_token)
|
25
|
+
{
|
26
|
+
'x-api-key' => api_token,
|
27
|
+
'x-api-user' => user_id,
|
28
|
+
'Content-Type' => 'application/json'
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_connection(user_id, api_token)
|
33
|
+
Faraday.new(
|
34
|
+
url: 'https://habitica.com/api/v2/',
|
35
|
+
headers: default_headers(user_id, api_token)
|
36
|
+
) do |faraday|
|
37
|
+
faraday.request :json
|
38
|
+
|
39
|
+
faraday.response :json, content_type: /\bjson$/
|
40
|
+
faraday.response :logger if @debug
|
41
|
+
|
42
|
+
faraday.adapter Faraday.default_adapter
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module HabiticaCli
|
2
|
+
# Extremely simplistic layer on top of PStore
|
3
|
+
# Responsible for caching habit responses
|
4
|
+
class Cache
|
5
|
+
def initialize(path = nil)
|
6
|
+
@path = path || File.join(Dir.home, '.habitca-cli-cache')
|
7
|
+
create_store(@path)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_store(path)
|
11
|
+
@store = PStore.new(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(key, default = nil)
|
15
|
+
@store.transaction { @store.fetch(key, default) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def destroy!
|
19
|
+
File.delete(@store.path)
|
20
|
+
create_store(@path)
|
21
|
+
end
|
22
|
+
|
23
|
+
# rubocop:disable Metrics/MethodLength
|
24
|
+
def store_tasks(items)
|
25
|
+
shortened = nil
|
26
|
+
count = get('count', 0)
|
27
|
+
@store.transaction do
|
28
|
+
shortened = items.map do |item|
|
29
|
+
count += 1
|
30
|
+
short_id = "#{item['id'][0]}#{count}"
|
31
|
+
|
32
|
+
@store[short_id] = item
|
33
|
+
|
34
|
+
item['cid'] = short_id
|
35
|
+
item
|
36
|
+
end
|
37
|
+
@store[:count] = count
|
38
|
+
end
|
39
|
+
shortened
|
40
|
+
end
|
41
|
+
# rubocop:enable
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module HabiticaCli
|
2
|
+
# responsible for adding new todos, tasks, and dailies
|
3
|
+
# also for for caching the newly added todo
|
4
|
+
module Commands
|
5
|
+
def self.add(env, type, text)
|
6
|
+
validate_type(type)
|
7
|
+
response = env.api.post('user/tasks', type: type, text: text)
|
8
|
+
|
9
|
+
if response.success?
|
10
|
+
task = cache_tasks(env, [response.body], type).first
|
11
|
+
puts "Added #{task['text']} [#{task['cid']}]"
|
12
|
+
else
|
13
|
+
puts "Error adding #{text}: #{response.body}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module HabiticaCli
|
2
|
+
# Clear completed tasks
|
3
|
+
# to slim down output
|
4
|
+
module Commands
|
5
|
+
def self.clear(env)
|
6
|
+
env.api.post('user/tasks/clear-completed')
|
7
|
+
if response.success?
|
8
|
+
puts 'Tasks cleared'
|
9
|
+
else
|
10
|
+
puts "Error #{response.body}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module HabiticaCli
|
2
|
+
# Responsible for completing tasks
|
3
|
+
module Commands
|
4
|
+
def self.do(env, cache_ids)
|
5
|
+
items = cache_ids.map { |id| env.cache.get(id) }
|
6
|
+
items.each do |item|
|
7
|
+
response = env.api.post("user/tasks/#{item['id']}/up")
|
8
|
+
if response.success?
|
9
|
+
puts "Completed: #{item['text']}"
|
10
|
+
else
|
11
|
+
puts "Error #{response.body}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module HabiticaCli
|
2
|
+
# Responsible for listing tasks
|
3
|
+
module Commands
|
4
|
+
def self.list(env, type = nil)
|
5
|
+
validate_type(type) if type
|
6
|
+
response = env.api.get('user/tasks')
|
7
|
+
|
8
|
+
if response.success?
|
9
|
+
display(env, response.body, type)
|
10
|
+
else
|
11
|
+
puts 'Error connecting to habit api'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module HabiticaCli
|
2
|
+
# Functionality common to all commands
|
3
|
+
module Commands
|
4
|
+
def self.validate_type(type)
|
5
|
+
types = %w(todo habit daily)
|
6
|
+
fail "Not a valid type (#{types})" unless types.include?(type)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.filter_tasks(env, tasks, type = nil)
|
10
|
+
tasks.select do |task|
|
11
|
+
(type.nil? || task['type'] == type) &&
|
12
|
+
(env.options['show_completed'] == true || task['completed'] != true)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.select_attributes(tasks)
|
17
|
+
keys = %w(completed id text type)
|
18
|
+
tasks.map do |task|
|
19
|
+
task.select { |k, _| keys.include?(k) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.cache_tasks(env, tasks, type)
|
24
|
+
env.cache.store_tasks(
|
25
|
+
select_attributes(filter_tasks(env, tasks, type))
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.display(env, raw_tasks, type)
|
30
|
+
tasks = cache_tasks(env, raw_tasks, type)
|
31
|
+
puts type.capitalize unless type.nil?
|
32
|
+
tasks.each do |item|
|
33
|
+
output = type.nil? ? "(#{item['type']}) " : ''
|
34
|
+
output += "[#{item['cid']}] #{item['text']}"
|
35
|
+
puts output
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module HabiticaCli
|
2
|
+
# Responsible for displaying a "dashboard" of stats
|
3
|
+
# and tasks for a user as well as caching them
|
4
|
+
module Commands
|
5
|
+
def self.status(env)
|
6
|
+
response = env.api.get('user')
|
7
|
+
if response.success?
|
8
|
+
puts status_display(response.body)
|
9
|
+
display(env, response.body['todos'] + response.body['dailys'], nil)
|
10
|
+
else
|
11
|
+
puts "Error: #{response.error}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.status_display(body)
|
16
|
+
stats = body['stats']
|
17
|
+
puts [
|
18
|
+
"Gold: #{stats['gp'].round}",
|
19
|
+
"Health: #{stats['hp'].round}/#{stats['maxHealth']}"
|
20
|
+
].join(' | ')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module HabiticaCli
|
2
|
+
# At the moment this holds _all_ tasks
|
3
|
+
# until we can figure out a better way to split
|
4
|
+
# out top level tasks into individual files
|
5
|
+
# (thor's DSL makes that a little bit of a chore at the moment)
|
6
|
+
class Main < Thor
|
7
|
+
class_option :habit_user, hide: true, default: ENV['HABIT_USER']
|
8
|
+
class_option :habit_key, hide: true, default: ENV['HABIT_KEY']
|
9
|
+
|
10
|
+
def initialize(*args)
|
11
|
+
super(*args)
|
12
|
+
@api = api
|
13
|
+
@cache = cache
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
# TODO: consider using this inside display instead of select
|
18
|
+
desc 'list <type>', 'list tasks, optionally filterd by <type>'
|
19
|
+
method_option :show_completed, aliases: '-c', default: false, type: :boolean
|
20
|
+
def list(*args)
|
21
|
+
Commands.list(env, *args)
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'status', 'Get user stats, dailies, and todos'
|
25
|
+
def status
|
26
|
+
Commands.status(env)
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'add <habit | daily | todo> <text>', 'add a new task'
|
30
|
+
def add(type, text)
|
31
|
+
Commands.add(env, type, text)
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'do <id> (<id> <id>)', 'complete a todo, daily, or habit. Pass multiple ids in separated by a space' # rubocop:disable Metrics/LineLength
|
35
|
+
def do(*cache_ids)
|
36
|
+
Commands.do(env, cache_ids)
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'clear', 'clear completed todos'
|
40
|
+
def clear
|
41
|
+
Commands.clear(env)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def env
|
47
|
+
OpenStruct.new(
|
48
|
+
cache: @cache,
|
49
|
+
api: @api,
|
50
|
+
options: @options
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
def cache
|
55
|
+
@cache ||= Cache.new
|
56
|
+
end
|
57
|
+
|
58
|
+
def api
|
59
|
+
user = options[:habit_user]
|
60
|
+
key = options[:habit_key]
|
61
|
+
if user.empty? || key.empty?
|
62
|
+
fail "You must provide a habit user and api key \n\n do this via (HABIT_USER and HABIT_KEY) or the --habit_user --habit_key" # rubocop:disable Metrics/LineLength
|
63
|
+
end
|
64
|
+
Api.new(user, key)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/habitica_cli.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'pstore'
|
3
|
+
require 'faraday'
|
4
|
+
require 'faraday_middleware'
|
5
|
+
require 'habitica_cli/version'
|
6
|
+
require 'habitica_cli/main'
|
7
|
+
require 'habitica_cli/api'
|
8
|
+
require 'habitica_cli/commands/shared'
|
9
|
+
require 'habitica_cli/commands/list'
|
10
|
+
require 'habitica_cli/commands/status'
|
11
|
+
require 'habitica_cli/commands/do'
|
12
|
+
require 'habitica_cli/commands/add'
|
13
|
+
require 'habitica_cli/commands/clear'
|
14
|
+
require 'habitica_cli/cache'
|
15
|
+
|
16
|
+
# A command line interface to habitica
|
17
|
+
# built on thor with a faraday based api layer
|
18
|
+
# you can use it to
|
19
|
+
# * create, complete, and list todos, habits, and dailies
|
20
|
+
module HabiticaCli
|
21
|
+
def self.start(*args)
|
22
|
+
Main.start(*args)
|
23
|
+
end
|
24
|
+
end
|
data/spec/api_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'habitica_cli/api'
|
2
|
+
|
3
|
+
RSpec.describe HabiticaCli::Api do
|
4
|
+
def response_headers
|
5
|
+
{ 'content-type' => 'application/json' }
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'attaches user name and token to request' do
|
9
|
+
stub_request(:get, /.*habitica.com.*/)
|
10
|
+
api = HabiticaCli::Api.new('test_user', 'test_key')
|
11
|
+
|
12
|
+
api.get('test')
|
13
|
+
|
14
|
+
expect(WebMock).to have_requested(:get, 'https://habitica.com/api/v2/test')
|
15
|
+
.with(headers: { :'X-Api-Key' => 'test_key', :'X-Api-User' => 'test_user' }) # rubocop:disable Metrics/LineLength
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns json' do
|
19
|
+
stub_request(:get, /.*habitica.com.*/).to_return(
|
20
|
+
body: JSON.dump(key: 'value'),
|
21
|
+
headers: response_headers
|
22
|
+
)
|
23
|
+
api = HabiticaCli::Api.new('test_user', 'test_key')
|
24
|
+
|
25
|
+
response = api.get('test')
|
26
|
+
expect(response.body['key']).to eql('value')
|
27
|
+
end
|
28
|
+
end
|
data/spec/cache_spec.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
RSpec.describe HabiticaCli::Cache do
|
2
|
+
FILE_PATH = File.expand_path('./support/temp', __dir__)
|
3
|
+
|
4
|
+
let(:cache) { HabiticaCli::Cache.new(FILE_PATH) }
|
5
|
+
|
6
|
+
after(:each) do
|
7
|
+
File.delete(FILE_PATH)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#store_tasks' do
|
11
|
+
it 'returns an array of items with a cache-id' do
|
12
|
+
items = cache.store_tasks(
|
13
|
+
[
|
14
|
+
{ 'id' => 'long-id-1', text: 'text1' },
|
15
|
+
{ 'id' => 'long-id-2', text: 'text2' },
|
16
|
+
{ 'id' => 'long-id-3', text: 'text3' }
|
17
|
+
]
|
18
|
+
)
|
19
|
+
|
20
|
+
expect(items).to eq(
|
21
|
+
[
|
22
|
+
{ 'id' => 'long-id-1', text: 'text1', 'cid' => 'l1' },
|
23
|
+
{ 'id' => 'long-id-2', text: 'text2', 'cid' => 'l2' },
|
24
|
+
{ 'id' => 'long-id-3', text: 'text3', 'cid' => 'l3' }
|
25
|
+
]
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'enables items to be retrieved by short id' do
|
30
|
+
cache.store_tasks(
|
31
|
+
[
|
32
|
+
{ 'id' => 'long-id-1', text: 'text1' },
|
33
|
+
{ 'id' => 'long-id-2', text: 'text2' },
|
34
|
+
{ 'id' => 'long-id-3', text: 'text3' }
|
35
|
+
]
|
36
|
+
)
|
37
|
+
|
38
|
+
expect(cache.get('l1')).to eq(
|
39
|
+
'id' => 'long-id-1', text: 'text1', 'cid' => 'l1'
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#destroy!' do
|
45
|
+
it 'removes all items in cache' do
|
46
|
+
cache.store_tasks(
|
47
|
+
[
|
48
|
+
{ 'id' => 'long-id-1', text: 'text1' },
|
49
|
+
{ 'id' => 'long-id-2', text: 'text2' },
|
50
|
+
{ 'id' => 'long-id-3', text: 'text3' }
|
51
|
+
]
|
52
|
+
)
|
53
|
+
|
54
|
+
expect(cache.get('l1')).to eq(
|
55
|
+
'id' => 'long-id-1', text: 'text1', 'cid' => 'l1'
|
56
|
+
)
|
57
|
+
|
58
|
+
cache.destroy!
|
59
|
+
expect(cache.get('l1')).to be_nil
|
60
|
+
expect(cache.get('l2')).to be_nil
|
61
|
+
expect(cache.get('l3')).to be_nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'webmock/rspec'
|
2
|
+
require 'habitica_cli'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.expect_with :rspec do |expectations|
|
6
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
7
|
+
end
|
8
|
+
|
9
|
+
config.mock_with :rspec do |mocks|
|
10
|
+
mocks.verify_partial_doubles = true
|
11
|
+
end
|
12
|
+
|
13
|
+
config.disable_monkey_patching!
|
14
|
+
|
15
|
+
if config.files_to_run.one?
|
16
|
+
# Use the documentation formatter for detailed output,
|
17
|
+
# unless a formatter has already been configured
|
18
|
+
# (e.g. via a command-line flag).
|
19
|
+
config.default_formatter = 'doc'
|
20
|
+
end
|
21
|
+
|
22
|
+
config.order = :random
|
23
|
+
Kernel.srand config.seed
|
24
|
+
|
25
|
+
config.warnings = true
|
26
|
+
end
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: habitica_cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Tomlin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-27 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.9.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.10.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.10.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.19.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.19.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
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.36.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.36.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.4.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.4.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.22'
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 1.22.6
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - "~>"
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '1.22'
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 1.22.6
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: pry
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
description: Provides a minijmal highline based ruby cli for habitica
|
146
|
+
email:
|
147
|
+
- nick.tomlin@gmail.com
|
148
|
+
executables:
|
149
|
+
- habitica
|
150
|
+
extensions: []
|
151
|
+
extra_rdoc_files: []
|
152
|
+
files:
|
153
|
+
- ".gitignore"
|
154
|
+
- ".rspec"
|
155
|
+
- ".ruby-version"
|
156
|
+
- Gemfile
|
157
|
+
- LICENSE.txt
|
158
|
+
- README.md
|
159
|
+
- Rakefile
|
160
|
+
- bin/habitica
|
161
|
+
- habitica-cli.gemspec
|
162
|
+
- lib/habitica_cli.rb
|
163
|
+
- lib/habitica_cli/api.rb
|
164
|
+
- lib/habitica_cli/cache.rb
|
165
|
+
- lib/habitica_cli/commands/add.rb
|
166
|
+
- lib/habitica_cli/commands/clear.rb
|
167
|
+
- lib/habitica_cli/commands/do.rb
|
168
|
+
- lib/habitica_cli/commands/list.rb
|
169
|
+
- lib/habitica_cli/commands/shared.rb
|
170
|
+
- lib/habitica_cli/commands/status.rb
|
171
|
+
- lib/habitica_cli/constants.rb
|
172
|
+
- lib/habitica_cli/main.rb
|
173
|
+
- lib/habitica_cli/version.rb
|
174
|
+
- spec/api_spec.rb
|
175
|
+
- spec/cache_spec.rb
|
176
|
+
- spec/habitica_cli_spec.rb
|
177
|
+
- spec/spec_helper.rb
|
178
|
+
- spec/support/.gitkeep
|
179
|
+
homepage: https://github.com/nicktomlin/habitica-cli-ruby
|
180
|
+
licenses:
|
181
|
+
- MIT
|
182
|
+
metadata: {}
|
183
|
+
post_install_message:
|
184
|
+
rdoc_options: []
|
185
|
+
require_paths:
|
186
|
+
- lib
|
187
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
188
|
+
requirements:
|
189
|
+
- - ">="
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: '0'
|
192
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - ">="
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '0'
|
197
|
+
requirements: []
|
198
|
+
rubyforge_project:
|
199
|
+
rubygems_version: 2.4.5
|
200
|
+
signing_key:
|
201
|
+
specification_version: 4
|
202
|
+
summary: A minimal CLI for habitica
|
203
|
+
test_files:
|
204
|
+
- spec/api_spec.rb
|
205
|
+
- spec/cache_spec.rb
|
206
|
+
- spec/habitica_cli_spec.rb
|
207
|
+
- spec/spec_helper.rb
|
208
|
+
- spec/support/.gitkeep
|