nirvanahq 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +10 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +31 -0
- data/LICENSE +22 -0
- data/README.md +72 -0
- data/Rakefile +39 -0
- data/bin/nirv +7 -0
- data/lib/nirv.rb +142 -0
- data/lib/nirvanahq.rb +14 -0
- data/lib/nirvanahq/auth.rb +45 -0
- data/lib/nirvanahq/config.sample.rb +9 -0
- data/lib/nirvanahq/empty +0 -0
- data/lib/nirvanahq/task.rb +70 -0
- data/nirvanahq.gemspec +35 -0
- data/test/examples/task.yaml +4 -0
- data/test/helper.rb +20 -0
- data/test/test_auth.rb +31 -0
- data/test/test_console.rb +74 -0
- data/test/test_task.rb +116 -0
- metadata +171 -0
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
## 0.0.4 (December 23, 2010)
|
2
|
+
|
3
|
+
- more functionality added - backup, init
|
4
|
+
- things seem slow - not sure why. on the list is how to profile things. I have suspicions I'm loading more than I need to in some cases.
|
5
|
+
|
6
|
+
## 0.0.3 (December 21, 2010)
|
7
|
+
|
8
|
+
Features:
|
9
|
+
|
10
|
+
- add task
|
data/Gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nirvanahq (0.0.4)
|
5
|
+
json
|
6
|
+
simpleconsole
|
7
|
+
uuid
|
8
|
+
|
9
|
+
GEM
|
10
|
+
specs:
|
11
|
+
json (1.4.6)
|
12
|
+
macaddr (1.0.0)
|
13
|
+
mocha (0.9.10)
|
14
|
+
rake
|
15
|
+
rake (0.8.7)
|
16
|
+
redgreen (1.2.2)
|
17
|
+
simpleconsole (0.1.1)
|
18
|
+
uuid (2.3.1)
|
19
|
+
macaddr (~> 1.0)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
json
|
26
|
+
mocha
|
27
|
+
nirvanahq!
|
28
|
+
rake
|
29
|
+
redgreen
|
30
|
+
simpleconsole
|
31
|
+
uuid
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010 Mitchell Amihod
|
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,72 @@
|
|
1
|
+
NirvanaHQ Gem
|
2
|
+
=============
|
3
|
+
|
4
|
+
A gem for the [NirvanaHQ.com](http://nirvanahq.com) API.
|
5
|
+
|
6
|
+
Includes a command line tool, **nirv**
|
7
|
+
|
8
|
+
NirvanaHQ is an online todo/task manager, based around the GTD method.
|
9
|
+
|
10
|
+
Features
|
11
|
+
--------
|
12
|
+
|
13
|
+
Command Line Tool:
|
14
|
+
|
15
|
+
* Add a task via the CLI
|
16
|
+
* Backup
|
17
|
+
|
18
|
+
Gem / Library: (API docs coming - have to spend a few hours reading up on RDoc)
|
19
|
+
|
20
|
+
Have a look at the lib & tests for some example usage.
|
21
|
+
|
22
|
+
This is by no means a final version, so you know the deal.
|
23
|
+
|
24
|
+
|
25
|
+
Usage (CLI)
|
26
|
+
-----------
|
27
|
+
|
28
|
+
First thing: run **`nirv init`**
|
29
|
+
|
30
|
+
This will create **~/.nirvanahq/config.rb**. You need to edit that file - change the values for your username and password.
|
31
|
+
|
32
|
+
**Add Task**
|
33
|
+
|
34
|
+
basic:
|
35
|
+
|
36
|
+
**`nirv add "task name"`** adds a task to your inbox
|
37
|
+
|
38
|
+
with tags & a note:
|
39
|
+
|
40
|
+
**`nirv add "task name" -n "this will show up in the task note." -t "Tag 1,Tag 2"`**
|
41
|
+
|
42
|
+
**Backup**
|
43
|
+
|
44
|
+
**nirv backup**
|
45
|
+
|
46
|
+
Dumps a full copy of your account to ~/.nirvanahq/backup.json.
|
47
|
+
|
48
|
+
I added it just because. For the data loss paranoid, or those just wanting their data.
|
49
|
+
|
50
|
+
**Everything Else**
|
51
|
+
|
52
|
+
**nirv version** obvious.
|
53
|
+
|
54
|
+
**nirv help** pretty much the info in this section.
|
55
|
+
|
56
|
+
|
57
|
+
About
|
58
|
+
-----
|
59
|
+
|
60
|
+
Wanted a quick way to add tasks from the cli. Also learning ruby, so this seemed a good fit. So, started a gem with a cli tool.
|
61
|
+
|
62
|
+
Right now, just focused on adding a task easily.
|
63
|
+
|
64
|
+
You can examine the nirvanahq api in your browser - their web app uses it, so its pretty straight-forward to see whats going on.
|
65
|
+
|
66
|
+
**gems - what why and how** from [ruby learning blog](http://rubylearning.com/blog/2010/12/14/ruby-gems-%E2%80%94-what-why-and-how/) helped, as well as studying [boom](https://github.com/holman/boom). Was a good example to work & learn from initially. Seems to be doing something similar to what I wanted to do, so picked up some gem tips there. And just talking to some people :)
|
67
|
+
|
68
|
+
comments/examples how to improve it welcome.
|
69
|
+
|
70
|
+
no association with nirvanahq.com, so any problems you have, open ticket on the [github site](https://github.com/meeech/nirv/issues).
|
71
|
+
|
72
|
+
m.
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
begin
|
2
|
+
require "bundler"
|
3
|
+
Bundler.setup
|
4
|
+
rescue LoadError
|
5
|
+
$stderr.puts "You need to have Bundler installed to be able build this gem."
|
6
|
+
end
|
7
|
+
|
8
|
+
gemspec = eval(File.read(Dir["*.gemspec"].first))
|
9
|
+
|
10
|
+
task :default => :test
|
11
|
+
|
12
|
+
require 'rake/testtask'
|
13
|
+
Rake::TestTask.new(:test) do |test|
|
14
|
+
test.libs << "test"
|
15
|
+
test.test_files = FileList['test/test*.rb']
|
16
|
+
test.verbose = true
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "Validate the gemspec"
|
20
|
+
task :gemspec do
|
21
|
+
gemspec.validate
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Build gem locally"
|
25
|
+
task :build => :gemspec do
|
26
|
+
system "gem build #{gemspec.name}.gemspec"
|
27
|
+
FileUtils.mkdir_p "pkg"
|
28
|
+
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", "pkg"
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "Install gem locally"
|
32
|
+
task :install => :build do
|
33
|
+
system "gem install pkg/#{gemspec.name}-#{gemspec.version}"
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Clean automatically generated files"
|
37
|
+
task :clean do
|
38
|
+
FileUtils.rm_rf "pkg"
|
39
|
+
end
|
data/bin/nirv
ADDED
data/lib/nirv.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
# The Command Line tool for NirvanaHQ
|
2
|
+
require "rubygems"
|
3
|
+
require "simpleconsole"
|
4
|
+
|
5
|
+
# @q how to deal with problems - ie: missing params? tried raise but having an issues
|
6
|
+
# - the raise keeps bubbling up so need to play with those more to see what i'm doing wrong
|
7
|
+
# @todo How do you test a simpleconsole program? Ay advice would be appreciated tbd
|
8
|
+
|
9
|
+
class NirvController < SimpleConsole::Controller
|
10
|
+
|
11
|
+
attr_reader :nirvana
|
12
|
+
|
13
|
+
params :string => {
|
14
|
+
:a => :name,
|
15
|
+
:t => :tags
|
16
|
+
},
|
17
|
+
:text => {:n => :note}
|
18
|
+
|
19
|
+
BACKUP_FILE = "#{ENV['HOME']}/.nirvanahq/backup.json"
|
20
|
+
CONFIG_FILE = "#{ENV['HOME']}/.nirvanahq/config.rb"
|
21
|
+
CONFIG_SAMPLE_FILE = File.dirname(__FILE__)+"/nirvanahq/config.sample.rb"
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
super
|
25
|
+
@my_app_name = 'nirv'
|
26
|
+
#@todo move config into yaml, load from that.
|
27
|
+
if ARGV[0] != "init" && ARGV[0] != "help"
|
28
|
+
@nirvana = NirvanaHQ.new $nirvana_config
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def default
|
33
|
+
@message = "Hi. Try '#{@my_app_name} help' for a list of commands."
|
34
|
+
end
|
35
|
+
|
36
|
+
def method_missing name = "method_missing"
|
37
|
+
puts "Method #{name} does not exist. Try '#{@my_app_name} help'."
|
38
|
+
end
|
39
|
+
|
40
|
+
def add
|
41
|
+
# allow basic add action - nirv add "task name" without having
|
42
|
+
# to speicify the name explicitly
|
43
|
+
params[:name] = params[:name] || params[:id]
|
44
|
+
|
45
|
+
if params[:name]
|
46
|
+
|
47
|
+
#prepare payload
|
48
|
+
# @q: anyone know better way to do this? still new to rb
|
49
|
+
now = Time.now.to_i
|
50
|
+
task = {}
|
51
|
+
[:name, :tags, :note ].each do | key |
|
52
|
+
begin
|
53
|
+
task[key] = params[key]
|
54
|
+
task["_#{key}"] = now
|
55
|
+
end if params[key]
|
56
|
+
end
|
57
|
+
|
58
|
+
#obviously, need to rethink this, and how we handle errors
|
59
|
+
result = @nirvana.add task
|
60
|
+
@message = "Added task: #{params[:name]}"
|
61
|
+
|
62
|
+
else
|
63
|
+
@message = "Missing name of task, which is the bare minimum. Try '#{@my_app_name} help'."
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def backup
|
68
|
+
result = @nirvana.everything
|
69
|
+
# seems silly that we will go back to JSON format, but thats how I want to store the blobs,
|
70
|
+
# but I want nirvanahq lib to pass back hashes
|
71
|
+
if File.open(BACKUP_FILE, 'w').write(result.to_json)
|
72
|
+
@message = "Your account data has been downloaded and saved to #{BACKUP_FILE}"
|
73
|
+
end
|
74
|
+
rescue Exception => e:
|
75
|
+
@message = "There was a problem: #{e.to_s}"
|
76
|
+
end
|
77
|
+
|
78
|
+
def init
|
79
|
+
unless File.exists? CONFIG_FILE
|
80
|
+
|
81
|
+
FileUtils.mkdir File.dirname(CONFIG_FILE) unless File.exists?(File.dirname(CONFIG_FILE))
|
82
|
+
|
83
|
+
puts "Creating #{CONFIG_FILE}..."
|
84
|
+
FileUtils.copy(CONFIG_SAMPLE_FILE, CONFIG_FILE)
|
85
|
+
@message = "Edit #{CONFIG_FILE} and add your login info."
|
86
|
+
else
|
87
|
+
@message = "You already have a config file in: #{CONFIG_FILE}"
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
def trash
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
def version
|
97
|
+
# Issue: Was getting fatal .git errors in built version.
|
98
|
+
# Okay! Totally boneheaded, but basically, if you using things
|
99
|
+
# like `git` in your gemspec, then you can't access the file
|
100
|
+
# dynamically. I assumed its making a copy of the parsed gemspec., which I could access this info.
|
101
|
+
# was lifted from from UUID gem.
|
102
|
+
# version = Gem::Specification.load(File.expand_path("../nirvanahq.gemspec", File.dirname(__FILE__))).version.to_s.split(".").map { |i| i.to_i }
|
103
|
+
# @todo move to VERSION txt file
|
104
|
+
@message = NirvanaHQ::VERSION
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
class NirvView < SimpleConsole::View
|
110
|
+
|
111
|
+
def add
|
112
|
+
puts @message
|
113
|
+
end
|
114
|
+
|
115
|
+
def backup
|
116
|
+
puts @message
|
117
|
+
end
|
118
|
+
|
119
|
+
def init
|
120
|
+
puts @message
|
121
|
+
end
|
122
|
+
|
123
|
+
def version
|
124
|
+
puts @message
|
125
|
+
end
|
126
|
+
|
127
|
+
def default
|
128
|
+
puts @message
|
129
|
+
end
|
130
|
+
|
131
|
+
def help
|
132
|
+
puts "Run 'nirv init' if you want to plan to use the command line tool.\n" unless File.exists?(NirvController::CONFIG_FILE)
|
133
|
+
puts 'nirv add "task name"'
|
134
|
+
puts 'nirv add "task name" -n "this will show up in the task note." -t "Tag 1,Tag 2"'
|
135
|
+
puts "\nnirv backup : Dumps a full copy of your account to ~/.nirvanahq/backup.json"
|
136
|
+
puts "\nnirv version"
|
137
|
+
puts "nirv help"
|
138
|
+
puts "\nVisit https://github.com/meeech/nirv for more help"
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
data/lib/nirvanahq.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
class NirvanaHQ
|
2
|
+
|
3
|
+
attr_accessor :username
|
4
|
+
attr_accessor :password
|
5
|
+
|
6
|
+
TOKEN_FILE = "#{ENV['HOME']}/.nirvanahq/token"
|
7
|
+
|
8
|
+
def initialize config
|
9
|
+
|
10
|
+
if(nil == config)
|
11
|
+
return
|
12
|
+
end
|
13
|
+
|
14
|
+
@username= config[:username]
|
15
|
+
@password= config[:password]
|
16
|
+
|
17
|
+
begin
|
18
|
+
# is this the spot to check is the dir exists?
|
19
|
+
File.new(TOKEN_FILE, 'w').write('')
|
20
|
+
end unless File.exists?(TOKEN_FILE)
|
21
|
+
|
22
|
+
@token = File.open(TOKEN_FILE, 'r').read
|
23
|
+
|
24
|
+
if @token.empty? then
|
25
|
+
save_token!(fetch_token)
|
26
|
+
end
|
27
|
+
|
28
|
+
rescue "EmptyToken"
|
29
|
+
puts "Token Issues."
|
30
|
+
end
|
31
|
+
|
32
|
+
def fetch_token
|
33
|
+
puts "Fetching your token..."
|
34
|
+
result = `curl -sX POST 'https://api.nirvanahq.com/?api=rest' -d "method=auth.new&u=#{@username}&p=#{@password}"`
|
35
|
+
parser = JSON.parse(result)
|
36
|
+
parser['results'][0]['auth']['token'] || ''
|
37
|
+
end
|
38
|
+
|
39
|
+
def save_token! token
|
40
|
+
raise "EmptyToken" if token.nil? || token.empty?
|
41
|
+
File.open(TOKEN_FILE, 'w').write(token)
|
42
|
+
@token = token
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# @q whats best way to deal with configs in rb?
|
2
|
+
# I don't see a problem with this method. not too much pollution, and
|
3
|
+
# doesn't impact gem use in code
|
4
|
+
$nirvana_config = {
|
5
|
+
:username => 'Kryten',
|
6
|
+
|
7
|
+
#md5 of your password. I will need this to get your auth token
|
8
|
+
:password => 'THIS-IS-AN-MD5-OF-YOUR-PASSWORD'
|
9
|
+
}
|
data/lib/nirvanahq/empty
ADDED
File without changes
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'uuid'
|
2
|
+
|
3
|
+
class NirvanaHQ
|
4
|
+
|
5
|
+
def post payload
|
6
|
+
result = `curl -sX POST 'https://api.nirvanahq.com/?api=json&authtoken=#{@token}' -d '#{payload}'`
|
7
|
+
end
|
8
|
+
|
9
|
+
# final form tbd. For now, have it parse out the results of the request, and send that along as a hash obj
|
10
|
+
def everything
|
11
|
+
raw = JSON.parse(`curl -sX GET 'https://api.nirvanahq.com/?api=rest&authtoken=#{@token}&method=everything&since=0'`)
|
12
|
+
raw['results']
|
13
|
+
end
|
14
|
+
|
15
|
+
# task_details a hash with the task info
|
16
|
+
def add task_details
|
17
|
+
|
18
|
+
#prepare payload
|
19
|
+
now = Time.now.to_i
|
20
|
+
defaults = {
|
21
|
+
"method" => "task.save",
|
22
|
+
"id" => UUID.generate,
|
23
|
+
"type" => 0,
|
24
|
+
"_type" => now,
|
25
|
+
"state" => 0,
|
26
|
+
"_state" => now,
|
27
|
+
}
|
28
|
+
|
29
|
+
task = defaults.merge(task_details)
|
30
|
+
self.post [task].to_json
|
31
|
+
end
|
32
|
+
|
33
|
+
def trash task_id
|
34
|
+
|
35
|
+
task = {
|
36
|
+
"method" => "task.save",
|
37
|
+
"id" => task_id,
|
38
|
+
"state" => 6,
|
39
|
+
"_state" => Time.now.to_i
|
40
|
+
}
|
41
|
+
|
42
|
+
self.post [task].to_json
|
43
|
+
end
|
44
|
+
|
45
|
+
def delete task_id
|
46
|
+
|
47
|
+
task = {
|
48
|
+
"method" => "task.save",
|
49
|
+
"id" => task_id,
|
50
|
+
"deleted" => Time.now.to_i,
|
51
|
+
"_deleted" => Time.now.to_i
|
52
|
+
}
|
53
|
+
|
54
|
+
self.post [task].to_json
|
55
|
+
end
|
56
|
+
|
57
|
+
def undelete task_id
|
58
|
+
|
59
|
+
task = {
|
60
|
+
"method" => "task.save",
|
61
|
+
"id" => task_id,
|
62
|
+
"deleted" => 0,
|
63
|
+
"_deleted" => Time.now.to_i
|
64
|
+
}
|
65
|
+
|
66
|
+
self.post [task].to_json
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
end
|
data/nirvanahq.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "nirvanahq"
|
5
|
+
s.version = "0.0.4"
|
6
|
+
s.platform = Gem::Platform::RUBY
|
7
|
+
s.authors = ["Mitchell Amihod"]
|
8
|
+
s.email = ["mitchell.amihod@gmail.com"]
|
9
|
+
s.homepage = "http://github.com/meeech/nirvanahq"
|
10
|
+
s.summary = "Gem for NirvanaHQ.com"
|
11
|
+
s.description = "Gem for interacting with the NirvanaHQ API. Includes a CLI tool. Pretty alpha."
|
12
|
+
s.rubyforge_project = s.name
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
|
16
|
+
# If you have runtime dependencies, add them here
|
17
|
+
s.add_dependency "json", ">= 0"
|
18
|
+
s.add_dependency "simpleconsole"
|
19
|
+
s.add_dependency "uuid", ">= 0"
|
20
|
+
|
21
|
+
# If you have development dependencies, add them here
|
22
|
+
s.add_development_dependency "rake"
|
23
|
+
s.add_development_dependency "redgreen"
|
24
|
+
s.add_development_dependency "mocha"
|
25
|
+
|
26
|
+
# The list of files to be contained in the gem
|
27
|
+
s.files = `git ls-files`.split("\n")
|
28
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
29
|
+
# s.extensions = `git ls-files ext/extconf.rb`.split("\n")
|
30
|
+
|
31
|
+
s.require_path = 'lib'
|
32
|
+
|
33
|
+
# For C extensions
|
34
|
+
# s.extensions = "ext/extconf.rb"
|
35
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'redgreen' if ENV['TM_FILENAME'].nil?
|
4
|
+
require 'mocha'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
+
|
10
|
+
require 'nirvanahq'
|
11
|
+
|
12
|
+
#Refresh the Gemfile.lock
|
13
|
+
require 'bundler'
|
14
|
+
begin
|
15
|
+
Bundler.setup(:default, :development)
|
16
|
+
rescue Bundler::BundlerError => e
|
17
|
+
$stderr.puts e.message
|
18
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
19
|
+
exit e.status_code
|
20
|
+
end
|
data/test/test_auth.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/helper"
|
2
|
+
|
3
|
+
module NirvanaHQTests
|
4
|
+
|
5
|
+
class NirvanaHQAuthTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@nirv = NirvanaHQ.new $nirvana_config
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_token_file_exists
|
12
|
+
assert File.exists?(NirvanaHQ::TOKEN_FILE)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_fetch_token
|
16
|
+
token = @nirv.fetch_token
|
17
|
+
assert_equal 32, token.length
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_save_token_should_raise_empty_token_error
|
21
|
+
#@q not sure if this best way to handle a raise?
|
22
|
+
# since its runtime error, there could be some other RTE error
|
23
|
+
# how can i check the message?
|
24
|
+
assert_raise RuntimeError do
|
25
|
+
@nirv.save_token!(nil)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/helper"
|
2
|
+
require "nirv"
|
3
|
+
|
4
|
+
# Used to capture output, which we can then check against.
|
5
|
+
require 'stringio'
|
6
|
+
|
7
|
+
module Kernel
|
8
|
+
|
9
|
+
def capture_stdout
|
10
|
+
out = StringIO.new
|
11
|
+
$stdout = out
|
12
|
+
yield
|
13
|
+
return out
|
14
|
+
ensure
|
15
|
+
$stdout = STDOUT
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
# End Capture Output override
|
20
|
+
|
21
|
+
module NirvanaHQTests
|
22
|
+
|
23
|
+
class NirvanaHQConsoleDataTest < Test::Unit::TestCase
|
24
|
+
|
25
|
+
def test_init
|
26
|
+
out = capture_stdout do
|
27
|
+
SimpleConsole::Application.run([:init], NirvController, NirvView)
|
28
|
+
end
|
29
|
+
config_path = NirvController::CONFIG_FILE
|
30
|
+
assert File.exists?(config_path), "Missing Config File: #{config_path}"
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
class NirvanaHQConsoleTest < Test::Unit::TestCase
|
36
|
+
|
37
|
+
def test_method_missing
|
38
|
+
out = capture_stdout do
|
39
|
+
SimpleConsole::Application.run([:fakeaction], NirvController, NirvView)
|
40
|
+
end
|
41
|
+
assert out.string.include? "Method fakeaction does not exist"
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_nirvanahq_instance
|
45
|
+
console =NirvController.new
|
46
|
+
assert_instance_of NirvanaHQ, console.nirvana
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_version
|
50
|
+
out = capture_stdout do
|
51
|
+
SimpleConsole::Application.run([:version], NirvController, NirvView)
|
52
|
+
end
|
53
|
+
assert out.string.include? " - "
|
54
|
+
end
|
55
|
+
|
56
|
+
# @todo can we store the UUID to use in test_delete?
|
57
|
+
def test_add
|
58
|
+
task_name = "Test Task Add"
|
59
|
+
out = capture_stdout do
|
60
|
+
SimpleConsole::Application.run([:add, task_name], NirvController, NirvView)
|
61
|
+
end
|
62
|
+
|
63
|
+
assert_equal out.string, "Added task: #{task_name}\n"
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_backup
|
67
|
+
SimpleConsole::Application.run([:backup], NirvController, NirvView)
|
68
|
+
assert File.exists? NirvController::BACKUP_FILE
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
data/test/test_task.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/helper"
|
2
|
+
|
3
|
+
module NirvanaHQTests
|
4
|
+
|
5
|
+
TASK_YAML = File.dirname(__FILE__) + "/examples/task.yaml"
|
6
|
+
|
7
|
+
class NirvanaHQAddTrashTaskTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@task = YAML::load_file(TASK_YAML)
|
11
|
+
@nirvana = NirvanaHQ.new $nirvana_config
|
12
|
+
end
|
13
|
+
|
14
|
+
def new_task
|
15
|
+
task = {
|
16
|
+
"id" => UUID.generate,
|
17
|
+
"name" => "Test Task #{rand(100)}",
|
18
|
+
"_name" => Time.now.to_i
|
19
|
+
}
|
20
|
+
|
21
|
+
File.open( TASK_YAML, 'w' ) do |out|
|
22
|
+
YAML.dump( task, out )
|
23
|
+
end
|
24
|
+
|
25
|
+
task
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_add_task
|
29
|
+
task = self.new_task
|
30
|
+
puts "Creating #{task['name']}\n"
|
31
|
+
# task.add expects a hash
|
32
|
+
result = @nirvana.add task
|
33
|
+
result = JSON.parse(result)
|
34
|
+
|
35
|
+
assert result.keys.include?('results')
|
36
|
+
assert result['results'][0]
|
37
|
+
assert result['results'][0].keys.include?('task')
|
38
|
+
assert_equal task["id"], result['results'][0]['task']['id']
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_trash_task
|
42
|
+
result = @nirvana.trash @task['id']
|
43
|
+
result = JSON.parse(result)
|
44
|
+
|
45
|
+
assert result.keys.include?('results')
|
46
|
+
assert result['results'][0]
|
47
|
+
assert result['results'][0].keys.include?('task')
|
48
|
+
assert_equal "6", result['results'][0]['task']['state']
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
class NirvanaHQDeleteUndeleteTaskTest < Test::Unit::TestCase
|
54
|
+
|
55
|
+
def setup
|
56
|
+
@task = YAML::load_file(TASK_YAML)
|
57
|
+
@nirvana = NirvanaHQ.new $nirvana_config
|
58
|
+
end
|
59
|
+
|
60
|
+
# more destructive. No way to recover (afaik) via ui
|
61
|
+
# here more as an example than anything else.
|
62
|
+
def test_delete_task
|
63
|
+
result = @nirvana.delete @task['id']
|
64
|
+
result = JSON.parse(result)
|
65
|
+
|
66
|
+
assert result.keys.include?('results')
|
67
|
+
assert result['results'][0]
|
68
|
+
assert result['results'][0].keys.include?('task')
|
69
|
+
assert "0" != result['results'][0]['task']['deleted']
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_undelete_task
|
73
|
+
result = @nirvana.undelete @task['id']
|
74
|
+
result = JSON.parse(result)
|
75
|
+
|
76
|
+
assert result.keys.include?('results')
|
77
|
+
assert result['results'][0]
|
78
|
+
assert result['results'][0].keys.include?('task')
|
79
|
+
assert_equal "0", result['results'][0]['task']['deleted']
|
80
|
+
|
81
|
+
# pause for a sec, to make sure delete timestamp is later. clean up
|
82
|
+
|
83
|
+
@nirvana.delete @task['id']
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
class NirvanaHQTaskTest < Test::Unit::TestCase
|
89
|
+
|
90
|
+
def setup
|
91
|
+
@task = YAML::load_file(TASK_YAML)
|
92
|
+
@nirvana = NirvanaHQ.new $nirvana_config
|
93
|
+
end
|
94
|
+
|
95
|
+
# Will need to rethink this test, or need to get the hang of stubbin,
|
96
|
+
# since running against a live account will make it lag eventually as tasks get larger.
|
97
|
+
# Maybe speak with E for a new account special just for testing.
|
98
|
+
def test_everything
|
99
|
+
results = @nirvana.everything
|
100
|
+
keys = []
|
101
|
+
results.each do | obj |
|
102
|
+
keys << obj.keys.to_s
|
103
|
+
end
|
104
|
+
assert keys.include? "user"
|
105
|
+
assert keys.include? "task"
|
106
|
+
end
|
107
|
+
|
108
|
+
# def test_get_task
|
109
|
+
#
|
110
|
+
# assert false
|
111
|
+
# end
|
112
|
+
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nirvanahq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Mitchell Amihod
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-23 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
requirement: *id001
|
33
|
+
name: json
|
34
|
+
type: :runtime
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
requirement: *id002
|
47
|
+
name: simpleconsole
|
48
|
+
type: :runtime
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
requirement: *id003
|
61
|
+
name: uuid
|
62
|
+
type: :runtime
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
requirement: *id004
|
75
|
+
name: rake
|
76
|
+
type: :development
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
requirement: *id005
|
89
|
+
name: redgreen
|
90
|
+
type: :development
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
requirement: *id006
|
103
|
+
name: mocha
|
104
|
+
type: :development
|
105
|
+
description: Gem for interacting with the NirvanaHQ API. Includes a CLI tool. Pretty alpha.
|
106
|
+
email:
|
107
|
+
- mitchell.amihod@gmail.com
|
108
|
+
executables:
|
109
|
+
- nirv
|
110
|
+
extensions: []
|
111
|
+
|
112
|
+
extra_rdoc_files: []
|
113
|
+
|
114
|
+
files:
|
115
|
+
- CHANGELOG.md
|
116
|
+
- Gemfile
|
117
|
+
- Gemfile.lock
|
118
|
+
- LICENSE
|
119
|
+
- README.md
|
120
|
+
- Rakefile
|
121
|
+
- bin/nirv
|
122
|
+
- lib/nirv.rb
|
123
|
+
- lib/nirvanahq.rb
|
124
|
+
- lib/nirvanahq/auth.rb
|
125
|
+
- lib/nirvanahq/config.sample.rb
|
126
|
+
- lib/nirvanahq/empty
|
127
|
+
- lib/nirvanahq/task.rb
|
128
|
+
- nirvanahq.gemspec
|
129
|
+
- test/examples/task.yaml
|
130
|
+
- test/helper.rb
|
131
|
+
- test/test_auth.rb
|
132
|
+
- test/test_console.rb
|
133
|
+
- test/test_task.rb
|
134
|
+
has_rdoc: true
|
135
|
+
homepage: http://github.com/meeech/nirvanahq
|
136
|
+
licenses: []
|
137
|
+
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
none: false
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
hash: 3
|
149
|
+
segments:
|
150
|
+
- 0
|
151
|
+
version: "0"
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
hash: 23
|
158
|
+
segments:
|
159
|
+
- 1
|
160
|
+
- 3
|
161
|
+
- 6
|
162
|
+
version: 1.3.6
|
163
|
+
requirements: []
|
164
|
+
|
165
|
+
rubyforge_project: nirvanahq
|
166
|
+
rubygems_version: 1.3.7
|
167
|
+
signing_key:
|
168
|
+
specification_version: 3
|
169
|
+
summary: Gem for NirvanaHQ.com
|
170
|
+
test_files: []
|
171
|
+
|