habitica_client 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rubocop.yml +19 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/.yardopts +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +106 -0
- data/Rakefile +18 -0
- data/habitica_client.gemspec +30 -0
- data/lib/habitica_client.rb +17 -0
- data/lib/habitica_client/api_base.rb +17 -0
- data/lib/habitica_client/client.rb +28 -0
- data/lib/habitica_client/restful.rb +96 -0
- data/lib/habitica_client/user.rb +27 -0
- data/lib/habitica_client/user/stats.rb +37 -0
- data/lib/habitica_client/user/task.rb +43 -0
- data/lib/habitica_client/user/task/date_accessor.rb +21 -0
- data/lib/habitica_client/user/task/status.rb +11 -0
- data/lib/habitica_client/user/task/type.rb +19 -0
- data/lib/habitica_client/user/tasks.rb +38 -0
- data/lib/habitica_client/user/tasks/status.rb +15 -0
- data/lib/habitica_client/user/tasks/types.rb +23 -0
- data/lib/habitica_client/version.rb +3 -0
- data/lib/hashup.rb +14 -0
- data/spec/habit_client/user/stats_spec.rb +38 -0
- data/spec/habit_client/user/task_spec.rb +104 -0
- data/spec/habit_client/user/tasks_spec.rb +82 -0
- data/spec/habit_client/user_spec.rb +32 -0
- data/spec/habit_client_spec.rb +21 -0
- data/spec/spec_helper.rb +20 -0
- data/utils/console.rb +13 -0
- metadata +253 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bc30d20c07e3c6080844554c2cc94e3ff7c4edd7
|
4
|
+
data.tar.gz: 77b5d94876785015859720c6362f7034cc617e27
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 36ed2def94d025fe54261204a2fa6f170b35a7c029295d85599625b617ac3ba1694066450d8cd0036cc84cbde61ab42e53b3d0ad67ec5939a2f764741b6a17ba
|
7
|
+
data.tar.gz: d08db6ac1a0ddfffc9c0ba0a5cc5d2db5eac2311597280d22803d42b5f7308508eaf963b427211d171950030d49d0ee1612d80fee20bf4942b74c6de128ce5b5
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# inherit_from: ../.rubocop.yml
|
2
|
+
|
3
|
+
Style/EmptyLinesAroundBlockBody:
|
4
|
+
Enabled: false
|
5
|
+
|
6
|
+
Style/EmptyLinesAroundClassBody:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Style/EmptyLinesAroundModuleBody:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Documentation:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Style/ClassAndModuleChildren:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Style/ClassVars:
|
19
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.2
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-m markdown
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Stephen Mckellar
|
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,106 @@
|
|
1
|
+
HabiticaClient [![Build Status](https://travis-ci.org/steeeve/habitica_client.svg?branch=master)](https://travis-ci.org/steeeve/habitica_client) [![Code Climate](https://codeclimate.com/github/steeeve/habitica_client/badges/gpa.svg)](https://codeclimate.com/github/steeeve/habitica_client)
|
2
|
+
==============
|
3
|
+
|
4
|
+
A Habitica client gem.
|
5
|
+
|
6
|
+
Full documentation at [http://www.rubydoc.info/gems/habitica_client/](http://www.rubydoc.info/gems/habitica_client/)
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'habitica_client'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install habitica_client
|
24
|
+
|
25
|
+
Usage
|
26
|
+
-----
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'habitica_client'
|
30
|
+
|
31
|
+
habit = HabiticaClient.new(ENV['USER_ID'], ENV['API_TOKEN'])
|
32
|
+
|
33
|
+
# User stats
|
34
|
+
habit.user.stats.hp
|
35
|
+
# 50
|
36
|
+
|
37
|
+
# Get tasks
|
38
|
+
habit.user.tasks.each do |task|
|
39
|
+
puts task.text
|
40
|
+
end
|
41
|
+
|
42
|
+
# Create task
|
43
|
+
task = habit.user.tasks.create(
|
44
|
+
text: 'Do the dishes',
|
45
|
+
type: 'todo'
|
46
|
+
)
|
47
|
+
|
48
|
+
# Update task (from previous)
|
49
|
+
task.notes = 'Make sure to clean the drip pan'
|
50
|
+
task.save
|
51
|
+
```
|
52
|
+
|
53
|
+
### Stats
|
54
|
+
```ruby
|
55
|
+
stats = habitica_client.user.stats
|
56
|
+
|
57
|
+
puts stats.training
|
58
|
+
puts stats.buffs
|
59
|
+
puts stats.per
|
60
|
+
puts stats.int
|
61
|
+
puts stats.con
|
62
|
+
puts stats.str
|
63
|
+
puts stats.points
|
64
|
+
puts stats.lvl
|
65
|
+
puts stats.gp
|
66
|
+
puts stats.exp
|
67
|
+
puts stats.mp
|
68
|
+
puts stats.hp
|
69
|
+
puts stats.to_next_level
|
70
|
+
puts stats.max_health
|
71
|
+
puts stats.max_mp
|
72
|
+
puts stats.player_class
|
73
|
+
```
|
74
|
+
|
75
|
+
### Task
|
76
|
+
```ruby
|
77
|
+
stats = habitica_client.user.tasks
|
78
|
+
|
79
|
+
tasks.each do |task|
|
80
|
+
puts task.daily?
|
81
|
+
puts task.todo?
|
82
|
+
puts task.habit?
|
83
|
+
puts task.id
|
84
|
+
puts task.text
|
85
|
+
puts task.notes
|
86
|
+
puts task.value
|
87
|
+
puts task.priority
|
88
|
+
puts task.attribute
|
89
|
+
puts task.tags
|
90
|
+
end
|
91
|
+
|
92
|
+
tasks.habits.each do |habit|
|
93
|
+
...
|
94
|
+
end
|
95
|
+
|
96
|
+
tasks.dailies.each do |habit|
|
97
|
+
...
|
98
|
+
end
|
99
|
+
|
100
|
+
tasks.todos.each do |completed|
|
101
|
+
puts todo.completed?
|
102
|
+
puts task.checklist
|
103
|
+
puts task.date_created
|
104
|
+
puts todo.date_completed
|
105
|
+
end
|
106
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubocop/rake_task'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
RuboCop::RakeTask.new
|
7
|
+
|
8
|
+
desc 'Open a PRY console with an instance of `HabiticaClient` from ENV vars'
|
9
|
+
task :console do
|
10
|
+
|
11
|
+
ruby 'utils/console.rb'
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Run linting and specs'
|
16
|
+
task test: [:rubocop, :spec]
|
17
|
+
|
18
|
+
task default: [:test]
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'habitica_client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'habitica_client'
|
8
|
+
spec.version = HabiticaClient::VERSION
|
9
|
+
spec.authors = ['Stephen Mckellar']
|
10
|
+
spec.email = ['stephen@thingmaker.io']
|
11
|
+
spec.summary = 'Another Habitica client'
|
12
|
+
# spec.description = %q{}
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
19
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
20
|
+
spec.add_development_dependency 'rspec', '~> 3.2'
|
21
|
+
spec.add_development_dependency 'dotenv', '~> 2.0'
|
22
|
+
spec.add_development_dependency 'webmock', '~> 1.2'
|
23
|
+
spec.add_development_dependency 'vcr', '~> 2.9'
|
24
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
25
|
+
spec.add_development_dependency 'rubocop', '~> 0.32'
|
26
|
+
spec.add_development_dependency 'byebug', '~> 5.0'
|
27
|
+
spec.add_development_dependency 'yard', '~> 0.8'
|
28
|
+
spec.add_development_dependency 'redcarpet', '~> 3.3'
|
29
|
+
spec.add_runtime_dependency 'httparty', '~> 0.13'
|
30
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class HabiticaClient
|
2
|
+
|
3
|
+
require 'habitica_client/version'
|
4
|
+
require 'habitica_client/client'
|
5
|
+
require 'habitica_client/user'
|
6
|
+
|
7
|
+
attr_accessor :client
|
8
|
+
|
9
|
+
def initialize(user_id, api_token)
|
10
|
+
self.client = Client.new(user_id, api_token)
|
11
|
+
end
|
12
|
+
|
13
|
+
def user
|
14
|
+
@user ||= User.new(client)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class HabiticaClient
|
2
|
+
|
3
|
+
# The basis of all HabiticaClient endpoint objects.
|
4
|
+
#
|
5
|
+
# All HabiticaClient endpoint objects need a reference to the http
|
6
|
+
# client so that we can make the API work using the dot syntax.
|
7
|
+
class ApiBase
|
8
|
+
|
9
|
+
attr_reader :client
|
10
|
+
|
11
|
+
def initialize(client)
|
12
|
+
@client = client
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class HabiticaClient
|
5
|
+
|
6
|
+
# This wraps up httparty functionality in a habitrpg
|
7
|
+
# specific class.
|
8
|
+
#
|
9
|
+
# Not intented to be accessed directly.
|
10
|
+
class Client
|
11
|
+
|
12
|
+
include HTTParty
|
13
|
+
|
14
|
+
base_uri 'https://habitrpg.com:443/api/v2/'
|
15
|
+
|
16
|
+
def initialize(user_id, api_token)
|
17
|
+
@user_id = user_id
|
18
|
+
@api_token = api_token
|
19
|
+
|
20
|
+
self.class.headers('User-Agent' => 'habitapi-rpg',
|
21
|
+
'Content-Type' => 'application/json',
|
22
|
+
'x-api-key' => @api_token,
|
23
|
+
'x-api-user' => @user_id)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
class HabiticaClient
|
4
|
+
|
5
|
+
class Restful < ApiBase
|
6
|
+
|
7
|
+
class ServerError < IOError; end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
|
11
|
+
def parse(client, attributes)
|
12
|
+
new(client, remap(attributes))
|
13
|
+
end
|
14
|
+
|
15
|
+
def remap(attributes)
|
16
|
+
remapped = attributes.map do |k, v|
|
17
|
+
[k.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase, v]
|
18
|
+
end
|
19
|
+
|
20
|
+
remapped.delete_if do |k, _v|
|
21
|
+
k.match(/^_/)
|
22
|
+
end
|
23
|
+
|
24
|
+
Hash[remapped]
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
extend ClassMethods
|
30
|
+
|
31
|
+
def initialize(client, attributes = {})
|
32
|
+
self.attributes = attributes
|
33
|
+
super(client)
|
34
|
+
end
|
35
|
+
|
36
|
+
def attributes=(attributes)
|
37
|
+
attributes.each { |k, v| send("#{k}=", v) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def new?
|
41
|
+
id.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
def save
|
45
|
+
response = put || post
|
46
|
+
|
47
|
+
self.attributes = self.class.remap(response)
|
48
|
+
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete
|
53
|
+
return nil if new?
|
54
|
+
|
55
|
+
response = client.class.delete(url)
|
56
|
+
|
57
|
+
response.ok?
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_json
|
61
|
+
to_h.to_json
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def url
|
67
|
+
return "#{endpoint}/#{id}" unless new?
|
68
|
+
|
69
|
+
endpoint
|
70
|
+
end
|
71
|
+
|
72
|
+
def request(method)
|
73
|
+
response = client.class.send(method,
|
74
|
+
url,
|
75
|
+
body: to_json)
|
76
|
+
|
77
|
+
fail ServerError, "#{response['err']}" unless response.ok?
|
78
|
+
|
79
|
+
response.parsed_response
|
80
|
+
end
|
81
|
+
|
82
|
+
def post
|
83
|
+
return nil unless new?
|
84
|
+
|
85
|
+
request(:post)
|
86
|
+
end
|
87
|
+
|
88
|
+
def put
|
89
|
+
return nil if new?
|
90
|
+
|
91
|
+
request(:put)
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'habitica_client/api_base'
|
2
|
+
|
3
|
+
class HabiticaClient
|
4
|
+
|
5
|
+
# The authed user.
|
6
|
+
class User < HabiticaClient::ApiBase
|
7
|
+
|
8
|
+
require 'habitica_client/user/stats'
|
9
|
+
require 'habitica_client/user/tasks'
|
10
|
+
|
11
|
+
# Returns user's stats.
|
12
|
+
#
|
13
|
+
# @return [HabiticaClient::Stats]
|
14
|
+
def stats
|
15
|
+
@stats ||= Stats.new(client)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns user's tasks.
|
19
|
+
#
|
20
|
+
# @return [HabiticaClient::Tasks]
|
21
|
+
def tasks
|
22
|
+
@tasks ||= Tasks.new(client)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'forwardable'
|
3
|
+
require 'hashup'
|
4
|
+
|
5
|
+
class HabiticaClient::User
|
6
|
+
|
7
|
+
class Stats < HabiticaClient::ApiBase
|
8
|
+
|
9
|
+
extend Forwardable
|
10
|
+
extend Hashup
|
11
|
+
|
12
|
+
def_delegators :stats, :training, :buffs, :per, :int, :con, :str,
|
13
|
+
:points, :lvl, :gp, :exp, :mp, :hp, :player_class
|
14
|
+
|
15
|
+
def_delegator :stats, :toNextLevel, :to_next_level
|
16
|
+
def_delegator :stats, :maxHealth, :max_health
|
17
|
+
def_delegator :stats, :maxMP, :max_mp
|
18
|
+
|
19
|
+
hashup :training, :buffs, :per, :int, :con, :str, :points, :lvl,
|
20
|
+
:gp, :exp, :mp, :hp, :player_class, :to_next_level,
|
21
|
+
:max_health, :max_mp
|
22
|
+
|
23
|
+
def self.parse(stats)
|
24
|
+
stats.tap do |s|
|
25
|
+
s['player_class'] = s['class']
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def stats
|
32
|
+
@stats ||= OpenStruct.new(Stats.parse(client.class.get('/user')['stats']))
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'forwardable'
|
3
|
+
require 'time'
|
4
|
+
require 'hashup'
|
5
|
+
require 'habitica_client/restful'
|
6
|
+
|
7
|
+
class HabiticaClient::User
|
8
|
+
|
9
|
+
# A user task, which can be a habit, daily, or todo.
|
10
|
+
class Task < HabiticaClient::Restful
|
11
|
+
|
12
|
+
require 'habitica_client/user/task/date_accessor'
|
13
|
+
require 'habitica_client/user/task/status'
|
14
|
+
require 'habitica_client/user/task/type'
|
15
|
+
|
16
|
+
extend DateAccessor
|
17
|
+
include Status
|
18
|
+
include Type
|
19
|
+
extend Hashup
|
20
|
+
|
21
|
+
attr_accessor :id, :text, :notes, :value, :priority, :attribute,
|
22
|
+
:type, :tags, :checklist, :value, :priority,
|
23
|
+
:challenge, :down, :up, :history, :streak,
|
24
|
+
:frequency, :history, :completed, :every_x, :repeat,
|
25
|
+
:collapse_checklist
|
26
|
+
|
27
|
+
date_accessor :date_created, :date_completed, :start_date, :date
|
28
|
+
|
29
|
+
hashup :id, :text, :notes, :value, :priority, :attribute, :type,
|
30
|
+
:tags, :checklist, :value, :priority, :challenge, :down,
|
31
|
+
:up, :history, :streak, :frequency, :history, :completed,
|
32
|
+
:every_x, :repeat, :collapse_checklist, :date_created,
|
33
|
+
:date_completed, :start_date, :date
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def endpoint
|
38
|
+
'/user/tasks'
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class HabiticaClient::User::Task
|
2
|
+
|
3
|
+
module DateAccessor
|
4
|
+
|
5
|
+
def date_accessor(*attributes)
|
6
|
+
attributes.each do |attribute|
|
7
|
+
define_method("#{attribute}=") do |date|
|
8
|
+
unless date.nil?
|
9
|
+
instance_variable_set("@#{attribute}", DateTime.parse(date))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
define_method("#{attribute}") do
|
14
|
+
instance_variable_get("@#{attribute}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class HabiticaClient::User
|
2
|
+
|
3
|
+
# An enumerable object of all the user's tasks.
|
4
|
+
#
|
5
|
+
# Also contains the endpoint for creating new tasks.
|
6
|
+
class Tasks < HabiticaClient::ApiBase
|
7
|
+
|
8
|
+
require 'habitica_client/user/tasks/types'
|
9
|
+
require 'habitica_client/user/tasks/status'
|
10
|
+
require 'habitica_client/user/task'
|
11
|
+
|
12
|
+
include Enumerable
|
13
|
+
include Types
|
14
|
+
include Status
|
15
|
+
|
16
|
+
# Iterate over user tasks
|
17
|
+
def each(&block)
|
18
|
+
tasks.each do |task|
|
19
|
+
block.call Task.parse(client, task)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Create a new task (and save it to habitrpg.com)
|
24
|
+
#
|
25
|
+
# @param attributes [Hash] a hash of attributes for the new task.
|
26
|
+
def create(attributes = {})
|
27
|
+
Task.new(client, attributes).save
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def tasks
|
33
|
+
@tasks ||= client.class.get('/user/tasks')
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class HabiticaClient::User::Tasks
|
2
|
+
|
3
|
+
module Types
|
4
|
+
|
5
|
+
def habits
|
6
|
+
by_type('habit')
|
7
|
+
end
|
8
|
+
|
9
|
+
def dailies
|
10
|
+
by_type('daily')
|
11
|
+
end
|
12
|
+
|
13
|
+
def todos
|
14
|
+
by_type('todo')
|
15
|
+
end
|
16
|
+
|
17
|
+
def by_type(type)
|
18
|
+
select { |task| task.type == type }
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/hashup.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Stats', vcr: { cassette_name: 'stats' } do
|
4
|
+
|
5
|
+
let(:habitrpg) { HabiticaClient.new(USER_ID, API_TOKEN) }
|
6
|
+
let(:stats) { habitrpg.user.stats }
|
7
|
+
|
8
|
+
let(:object_stats) { [:training, :buffs] }
|
9
|
+
let(:numeric_stats) do
|
10
|
+
[:per, :int, :con, :str, :points, :lvl, :gp, :exp, :mp, :hp,
|
11
|
+
:to_next_level, :max_health, :max_mp]
|
12
|
+
end
|
13
|
+
let(:text_stats) { [:player_class] }
|
14
|
+
let(:fake_stat) { :foobar }
|
15
|
+
|
16
|
+
it 'has object stats' do
|
17
|
+
object_stats.each do |stat|
|
18
|
+
expect(stats.send(stat)).not_to be_nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'has numeric stats' do
|
23
|
+
numeric_stats.each do |stat|
|
24
|
+
expect(stats.send(stat)).not_to be_nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'has text stats' do
|
29
|
+
text_stats.each do |stat|
|
30
|
+
expect(stats.send(stat)).not_to be_nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "doesn't have stats" do
|
35
|
+
expect { stats.send(fake_stat) }.to raise_error(NoMethodError)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
properties = [:id, :text, :notes, :value, :checklist, :priority,
|
4
|
+
:attribute, :tags]
|
5
|
+
|
6
|
+
date_properties = [:date_completed, :date_created]
|
7
|
+
|
8
|
+
describe 'Task', vcr: { cassette_name: 'task' } do
|
9
|
+
|
10
|
+
let(:habitrpg) { HabiticaClient.new(USER_ID, API_TOKEN) }
|
11
|
+
let(:tasks) { habitrpg.user.tasks }
|
12
|
+
let(:todo) { tasks.todos.last }
|
13
|
+
let(:habit) { tasks.habits.last }
|
14
|
+
let(:daily) { tasks.dailies.last }
|
15
|
+
|
16
|
+
describe '#completed?' do
|
17
|
+
it 'is the completed status' do
|
18
|
+
expect(todo).to respond_to(:completed?)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'Task properties' do
|
23
|
+
|
24
|
+
properties.each do |property|
|
25
|
+
describe "##{property}" do
|
26
|
+
it 'is not nil' do
|
27
|
+
expect(todo).to respond_to(property)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
date_properties.each do |property|
|
32
|
+
describe "##{property}" do
|
33
|
+
it 'is a DateTime' do
|
34
|
+
expect(todo.send(property)).to be_a(DateTime)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'is a habit' do
|
41
|
+
describe '#habit?' do
|
42
|
+
it 'is true' do
|
43
|
+
expect(habit.habit?).to eq(true)
|
44
|
+
expect(habit.daily?).to eq(false)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'is a daily' do
|
50
|
+
describe '#daily?' do
|
51
|
+
it 'is true' do
|
52
|
+
expect(daily.daily?).to eq(true)
|
53
|
+
expect(daily.todo?).to eq(false)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'is a todo' do
|
59
|
+
describe '#todo?' do
|
60
|
+
it 'is true' do
|
61
|
+
expect(todo.todo?).to eq(true)
|
62
|
+
expect(todo.habit?).to eq(false)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'Deleting tasks', vcr: { cassette_name: 'delete_task' } do
|
68
|
+
|
69
|
+
describe '#delete' do
|
70
|
+
|
71
|
+
it 'can delete a task' do
|
72
|
+
task = tasks.create(text: 'Delete me', type: 'todo')
|
73
|
+
expect(task.delete).to eq(true)
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'Updating tasks', vcr: { cassette_name: 'update_task' } do
|
81
|
+
|
82
|
+
describe '#save' do
|
83
|
+
|
84
|
+
let(:original_text) { 'Testing 123' }
|
85
|
+
let(:updated_text) { 'Testing 456' }
|
86
|
+
|
87
|
+
it 'can update an existing task' do
|
88
|
+
task = tasks.create(text: original_text, type: 'todo')
|
89
|
+
|
90
|
+
expect(task.text).to eq(original_text)
|
91
|
+
|
92
|
+
task.text = 'Testing 456'
|
93
|
+
task.save
|
94
|
+
|
95
|
+
expect(task.text).to eq(updated_text)
|
96
|
+
|
97
|
+
task.delete # Don't leave tasks in my todo list!
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Tasks', vcr: { cassette_name: 'tasks' } do
|
4
|
+
|
5
|
+
let(:habitrpg) { HabiticaClient.new(USER_ID, API_TOKEN) }
|
6
|
+
let(:tasks) { habitrpg.user.tasks }
|
7
|
+
|
8
|
+
describe '.each' do
|
9
|
+
|
10
|
+
it 'can be iterated' do
|
11
|
+
tasks.each do |task|
|
12
|
+
expect(task).to be_a(HabiticaClient::User::Task)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '.habits' do
|
19
|
+
|
20
|
+
it 'returns all the habits' do
|
21
|
+
tasks.habits.each do |task|
|
22
|
+
expect(task.habit?).to be(true)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '.todos' do
|
29
|
+
|
30
|
+
it 'returns all the todos' do
|
31
|
+
tasks.todos.each do |task|
|
32
|
+
expect(task.todo?).to be(true)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '.dailies' do
|
39
|
+
|
40
|
+
it 'returns all the dailies' do
|
41
|
+
tasks.dailies.each do |task|
|
42
|
+
expect(task.daily?).to be(true)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '.completed' do
|
49
|
+
|
50
|
+
it 'returns all the completed tasks' do
|
51
|
+
tasks.completed.each do |task|
|
52
|
+
expect(task.completed?).to be(true)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '.uncompleted' do
|
59
|
+
|
60
|
+
it 'returns all the uncompleted tasks' do
|
61
|
+
tasks.uncompleted.each do |task|
|
62
|
+
expect(task.completed?).to be(false)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'Creating tasks', vcr: { cassette_name: 'create_task' } do
|
69
|
+
|
70
|
+
describe '#create' do
|
71
|
+
|
72
|
+
it 'can create a new task' do
|
73
|
+
task = tasks.create(text: 'Testing 123', type: 'todo')
|
74
|
+
expect(task.id).not_to be_nil
|
75
|
+
task.delete # Don't leave tasks in my todo list!
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'User', :vcr do
|
4
|
+
|
5
|
+
let(:habitrpg) { HabiticaClient.new(USER_ID, API_TOKEN) }
|
6
|
+
let(:user) { habitrpg.user }
|
7
|
+
|
8
|
+
it 'is a user object' do
|
9
|
+
expect(user).to be_a(HabiticaClient::User)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#stats' do
|
13
|
+
|
14
|
+
subject { user.stats }
|
15
|
+
|
16
|
+
it 'returns Stats' do
|
17
|
+
expect(subject).to be_a(HabiticaClient::User::Stats)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#tasks' do
|
23
|
+
|
24
|
+
subject { user.tasks }
|
25
|
+
|
26
|
+
it 'returns Tasks' do
|
27
|
+
expect(subject).to be_a(HabiticaClient::User::Tasks)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'HabiticaClient' do
|
4
|
+
|
5
|
+
let(:habitrpg) { HabiticaClient.new(USER_ID, API_TOKEN) }
|
6
|
+
|
7
|
+
it 'can be initialized' do
|
8
|
+
|
9
|
+
expect(habitrpg).to be_a(HabiticaClient)
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#user' do
|
14
|
+
|
15
|
+
it 'returns a user' do
|
16
|
+
expect(habitrpg.user).to be_a(HabiticaClient::User)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative '../lib/habitica_client'
|
2
|
+
|
3
|
+
require 'byebug'
|
4
|
+
require 'vcr'
|
5
|
+
require 'dotenv'
|
6
|
+
|
7
|
+
Dotenv.load
|
8
|
+
|
9
|
+
USER_ID = ENV['TEST_USER_ID']
|
10
|
+
API_TOKEN = ENV['TEST_API_TOKEN']
|
11
|
+
|
12
|
+
VCR.configure do |c|
|
13
|
+
c.cassette_library_dir = 'spec/cassettes'
|
14
|
+
c.hook_into :webmock
|
15
|
+
c.default_cassette_options = { record: :new_episodes }
|
16
|
+
c.configure_rspec_metadata!
|
17
|
+
end
|
18
|
+
|
19
|
+
# RSpec.configure do |c|
|
20
|
+
# end
|
data/utils/console.rb
ADDED
metadata
ADDED
@@ -0,0 +1,253 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: habitica_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stephen Mckellar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-30 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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dotenv
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.9'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.9'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.10'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.10'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.32'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.32'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: byebug
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '5.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '5.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: yard
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.8'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.8'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: redcarpet
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '3.3'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '3.3'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: httparty
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0.13'
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0.13'
|
181
|
+
description:
|
182
|
+
email:
|
183
|
+
- stephen@thingmaker.io
|
184
|
+
executables: []
|
185
|
+
extensions: []
|
186
|
+
extra_rdoc_files: []
|
187
|
+
files:
|
188
|
+
- ".gitignore"
|
189
|
+
- ".rubocop.yml"
|
190
|
+
- ".ruby-version"
|
191
|
+
- ".travis.yml"
|
192
|
+
- ".yardopts"
|
193
|
+
- Gemfile
|
194
|
+
- LICENSE.txt
|
195
|
+
- README.md
|
196
|
+
- Rakefile
|
197
|
+
- habitica_client.gemspec
|
198
|
+
- lib/habitica_client.rb
|
199
|
+
- lib/habitica_client/api_base.rb
|
200
|
+
- lib/habitica_client/client.rb
|
201
|
+
- lib/habitica_client/restful.rb
|
202
|
+
- lib/habitica_client/user.rb
|
203
|
+
- lib/habitica_client/user/stats.rb
|
204
|
+
- lib/habitica_client/user/task.rb
|
205
|
+
- lib/habitica_client/user/task/date_accessor.rb
|
206
|
+
- lib/habitica_client/user/task/status.rb
|
207
|
+
- lib/habitica_client/user/task/type.rb
|
208
|
+
- lib/habitica_client/user/tasks.rb
|
209
|
+
- lib/habitica_client/user/tasks/status.rb
|
210
|
+
- lib/habitica_client/user/tasks/types.rb
|
211
|
+
- lib/habitica_client/version.rb
|
212
|
+
- lib/hashup.rb
|
213
|
+
- spec/cassettes/.keep
|
214
|
+
- spec/habit_client/user/stats_spec.rb
|
215
|
+
- spec/habit_client/user/task_spec.rb
|
216
|
+
- spec/habit_client/user/tasks_spec.rb
|
217
|
+
- spec/habit_client/user_spec.rb
|
218
|
+
- spec/habit_client_spec.rb
|
219
|
+
- spec/spec_helper.rb
|
220
|
+
- utils/console.rb
|
221
|
+
homepage: ''
|
222
|
+
licenses:
|
223
|
+
- MIT
|
224
|
+
metadata: {}
|
225
|
+
post_install_message:
|
226
|
+
rdoc_options: []
|
227
|
+
require_paths:
|
228
|
+
- lib
|
229
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
230
|
+
requirements:
|
231
|
+
- - ">="
|
232
|
+
- !ruby/object:Gem::Version
|
233
|
+
version: '0'
|
234
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
235
|
+
requirements:
|
236
|
+
- - ">="
|
237
|
+
- !ruby/object:Gem::Version
|
238
|
+
version: '0'
|
239
|
+
requirements: []
|
240
|
+
rubyforge_project:
|
241
|
+
rubygems_version: 2.2.2
|
242
|
+
signing_key:
|
243
|
+
specification_version: 4
|
244
|
+
summary: Another Habitica client
|
245
|
+
test_files:
|
246
|
+
- spec/cassettes/.keep
|
247
|
+
- spec/habit_client/user/stats_spec.rb
|
248
|
+
- spec/habit_client/user/task_spec.rb
|
249
|
+
- spec/habit_client/user/tasks_spec.rb
|
250
|
+
- spec/habit_client/user_spec.rb
|
251
|
+
- spec/habit_client_spec.rb
|
252
|
+
- spec/spec_helper.rb
|
253
|
+
has_rdoc:
|