gyunyu 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +26 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +35 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/bin/gyunyu +11 -0
- data/gyunyu.gemspec +92 -0
- data/lib/gyunyu.rb +9 -0
- data/lib/gyunyu/app.rb +4 -0
- data/lib/gyunyu/command.rb +21 -0
- data/lib/gyunyu/command/export/app.rb +150 -0
- data/lib/gyunyu/command/export/format/csv.rb +27 -0
- data/lib/gyunyu/command/export/format/json.rb +16 -0
- data/lib/gyunyu/command/export/format/yaml.rb +16 -0
- data/lib/gyunyu/command/export/option.rb +63 -0
- data/lib/gyunyu/expander.rb +40 -0
- data/lib/gyunyu/token.rb +89 -0
- data/spec/app/.gitkeep +0 -0
- data/spec/app/command/export/option_spec.rb +137 -0
- data/spec/app/command_spec.rb +62 -0
- data/spec/app/expander_spec.rb +140 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/token/token_spec.rb +87 -0
- data/tasks/git.rake +7 -0
- data/tasks/spec.rake +11 -0
- data/tmp/.gitkeep +0 -0
- metadata +178 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color -f d
|
data/Gemfile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
# Add dependencies required to use your gem here.
|
5
|
+
# Example:
|
6
|
+
# gem "activesupport", ">= 2.3.5"
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
|
11
|
+
gem 'rtmilk'
|
12
|
+
gem 'xml-simple'
|
13
|
+
gem 'rtm-time', '>= 0.2.0'
|
14
|
+
if RUBY_VERSION < '1.9'
|
15
|
+
gem 'fastercsv'
|
16
|
+
gem 'json'
|
17
|
+
end
|
18
|
+
|
19
|
+
group :development do
|
20
|
+
gem "rspec", "~> 2.3.0"
|
21
|
+
gem "bundler", "~> 1.0.0"
|
22
|
+
gem "jeweler", "~> 1.6.4"
|
23
|
+
gem "yard"
|
24
|
+
gem "rcov", ">= 0"
|
25
|
+
gem 'rr'
|
26
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 wtnabe
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
= gyunyu
|
2
|
+
|
3
|
+
simple RTM app for CLI made with Ruby
|
4
|
+
|
5
|
+
== Required
|
6
|
+
|
7
|
+
* Ruby ( tested with Ruby 1.9.2 )
|
8
|
+
* read permission of RTM API
|
9
|
+
|
10
|
+
== Supported
|
11
|
+
|
12
|
+
* store API token ( and reuse )
|
13
|
+
* only `export' command. supported formats are CSV, JSON, YAML.
|
14
|
+
|
15
|
+
== Not Supported
|
16
|
+
|
17
|
+
* Tags and notes for csv exporting
|
18
|
+
* Convert Date to (ISO 8601 + UTC) in search filter. Currently search results are out of alignment.
|
19
|
+
* Default filter
|
20
|
+
|
21
|
+
== Contributing to gyunyu
|
22
|
+
|
23
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
24
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
25
|
+
* Fork the project
|
26
|
+
* Start a feature/bugfix branch
|
27
|
+
* Commit and push until you are happy with your contribution
|
28
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
29
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
30
|
+
|
31
|
+
== Copyright
|
32
|
+
|
33
|
+
Copyright (c) 2011 wtnabe. See LICENSE.txt for
|
34
|
+
further details.
|
35
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- mode: ruby; encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "gyunyu"
|
18
|
+
gem.homepage = "http://github.com/wtnabe/gyunyu"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Simple RTM app for CLI}
|
21
|
+
gem.description = %Q{now available export command}
|
22
|
+
gem.email = "wtnabe@gmail.com"
|
23
|
+
gem.authors = ["wtnabe"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'yard'
|
42
|
+
YARD::Rake::YardocTask.new
|
43
|
+
|
44
|
+
Dir.glob('tasks/**/*.rake') { |f|
|
45
|
+
load File.join(File.dirname(__FILE__), f)
|
46
|
+
}
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/gyunyu
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
unless ( ENV['PATH'].split(
|
4
|
+
File::PATH_SEPARATOR
|
5
|
+
).include?( File.dirname( __FILE__ ) ) )
|
6
|
+
$LOAD_PATH.unshift( File.expand_path( "../lib", File.dirname( __FILE__ ) ) )
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'gyunyu'
|
10
|
+
|
11
|
+
Gyunyu::Command.dispatch( 'export' )
|
data/gyunyu.gemspec
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{gyunyu}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{wtnabe}]
|
12
|
+
s.date = %q{2012-01-04}
|
13
|
+
s.description = %q{now available export command}
|
14
|
+
s.email = %q{wtnabe@gmail.com}
|
15
|
+
s.executables = [%q{gyunyu}]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/gyunyu",
|
29
|
+
"gyunyu.gemspec",
|
30
|
+
"lib/gyunyu.rb",
|
31
|
+
"lib/gyunyu/app.rb",
|
32
|
+
"lib/gyunyu/command.rb",
|
33
|
+
"lib/gyunyu/command/export/app.rb",
|
34
|
+
"lib/gyunyu/command/export/format/csv.rb",
|
35
|
+
"lib/gyunyu/command/export/format/json.rb",
|
36
|
+
"lib/gyunyu/command/export/format/yaml.rb",
|
37
|
+
"lib/gyunyu/command/export/option.rb",
|
38
|
+
"lib/gyunyu/expander.rb",
|
39
|
+
"lib/gyunyu/token.rb",
|
40
|
+
"spec/app/.gitkeep",
|
41
|
+
"spec/app/command/export/option_spec.rb",
|
42
|
+
"spec/app/command_spec.rb",
|
43
|
+
"spec/app/expander_spec.rb",
|
44
|
+
"spec/spec_helper.rb",
|
45
|
+
"spec/token/token_spec.rb",
|
46
|
+
"tasks/git.rake",
|
47
|
+
"tasks/spec.rake",
|
48
|
+
"tmp/.gitkeep"
|
49
|
+
]
|
50
|
+
s.homepage = %q{http://github.com/wtnabe/gyunyu}
|
51
|
+
s.licenses = [%q{MIT}]
|
52
|
+
s.require_paths = [%q{lib}]
|
53
|
+
s.rubygems_version = %q{1.8.6}
|
54
|
+
s.summary = %q{Simple RTM app for CLI}
|
55
|
+
|
56
|
+
if s.respond_to? :specification_version then
|
57
|
+
s.specification_version = 3
|
58
|
+
|
59
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
60
|
+
s.add_runtime_dependency(%q<rtmilk>, [">= 0"])
|
61
|
+
s.add_runtime_dependency(%q<xml-simple>, [">= 0"])
|
62
|
+
s.add_runtime_dependency(%q<rtm-time>, [">= 0.2.0"])
|
63
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
64
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
66
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
67
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
68
|
+
s.add_development_dependency(%q<rr>, [">= 0"])
|
69
|
+
else
|
70
|
+
s.add_dependency(%q<rtmilk>, [">= 0"])
|
71
|
+
s.add_dependency(%q<xml-simple>, [">= 0"])
|
72
|
+
s.add_dependency(%q<rtm-time>, [">= 0.2.0"])
|
73
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
74
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
75
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
76
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
77
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
78
|
+
s.add_dependency(%q<rr>, [">= 0"])
|
79
|
+
end
|
80
|
+
else
|
81
|
+
s.add_dependency(%q<rtmilk>, [">= 0"])
|
82
|
+
s.add_dependency(%q<xml-simple>, [">= 0"])
|
83
|
+
s.add_dependency(%q<rtm-time>, [">= 0.2.0"])
|
84
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
85
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
86
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
87
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
88
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
89
|
+
s.add_dependency(%q<rr>, [">= 0"])
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
data/lib/gyunyu.rb
ADDED
data/lib/gyunyu/app.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Gyunyu
|
2
|
+
module Command
|
3
|
+
class NotFound < StandardError; end
|
4
|
+
|
5
|
+
def self.commands
|
6
|
+
constants.map { |e| e.to_s.downcase }
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.dispatch( command )
|
10
|
+
if commands.include?( command )
|
11
|
+
app_const( command ).new.run
|
12
|
+
else
|
13
|
+
raise NotFound, command
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.app_const( command )
|
18
|
+
Gyunyu::Command.const_get(command.capitalize).const_get('App')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Gyunyu
|
4
|
+
module Command
|
5
|
+
module Export
|
6
|
+
class App
|
7
|
+
TIME_FIELDS = %w( created modified due added completed deleted )
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@argv ||= ARGV
|
11
|
+
@token ||= Gyunyu::Token.get
|
12
|
+
@lists ||= RTM::List.alive_all
|
13
|
+
|
14
|
+
_init_option( @argv )
|
15
|
+
end
|
16
|
+
attr_reader :option, :token, :lists
|
17
|
+
|
18
|
+
#
|
19
|
+
# [return] Array
|
20
|
+
#
|
21
|
+
def fields
|
22
|
+
['list'] + option.fields.map { |f|
|
23
|
+
if f == 'estimate'
|
24
|
+
%w( estimate(d) estimate(h) estimate(m) )
|
25
|
+
else
|
26
|
+
f
|
27
|
+
end
|
28
|
+
}.flatten
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# [return] Module
|
33
|
+
#
|
34
|
+
def format_module
|
35
|
+
format = option.format.to_s.capitalize
|
36
|
+
Module.nesting[1].const_get('Format').const_get(format)
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# [param] Array argv
|
41
|
+
# [return] Option
|
42
|
+
#
|
43
|
+
def _init_option( argv = nil )
|
44
|
+
@option = Option.new( argv )
|
45
|
+
end
|
46
|
+
|
47
|
+
def run
|
48
|
+
if @argv.size > 0
|
49
|
+
export( build_filter )
|
50
|
+
else
|
51
|
+
puts option.parser
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# [param] String filter
|
57
|
+
# [return] String
|
58
|
+
#
|
59
|
+
def build_filter( filter = nil )
|
60
|
+
filters = []
|
61
|
+
|
62
|
+
filters << option.lists.map { |l| "list:#{l}" }.join(' and ') if option.lists.size > 0
|
63
|
+
filters << option.filter if option.filter
|
64
|
+
filters << filter if filter
|
65
|
+
|
66
|
+
'(' + filters.join(') and (') + ')'
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# [param] String filter
|
71
|
+
# [return] RTM::Tasks::GetList
|
72
|
+
#
|
73
|
+
def task_list( filter = nil )
|
74
|
+
RTM::Tasks::GetList.new( token,
|
75
|
+
nil,
|
76
|
+
build_filter( filter ) ).invoke
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# [param] String id
|
81
|
+
# [return] RTM::List
|
82
|
+
#
|
83
|
+
def find_list( id )
|
84
|
+
@lists.find { |list|
|
85
|
+
list.id == id
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# [param] String filter
|
91
|
+
# [return] Array
|
92
|
+
#
|
93
|
+
def pickup_fields( filter = nil )
|
94
|
+
tasks = []
|
95
|
+
task_list( filter ).each { |l|
|
96
|
+
list_name = find_list( l['id'] ).name
|
97
|
+
tasks += Gyunyu::Expander.taskseries( l['taskseries'] ).map { |t|
|
98
|
+
record = {'list' => list_name}
|
99
|
+
option.fields.each { |f|
|
100
|
+
val = if TIME_FIELDS.include?( f )
|
101
|
+
localtime( t[f] )
|
102
|
+
else
|
103
|
+
t[f]
|
104
|
+
end
|
105
|
+
if f == 'estimate'
|
106
|
+
e = split_estimate( t[f] )
|
107
|
+
record['estimate(d)'] = e.day
|
108
|
+
record['estimate(h)'] = e.hour
|
109
|
+
record['estimate(m)'] = e.min
|
110
|
+
else
|
111
|
+
record[f] = val
|
112
|
+
end
|
113
|
+
}
|
114
|
+
record
|
115
|
+
}
|
116
|
+
}
|
117
|
+
tasks
|
118
|
+
end
|
119
|
+
|
120
|
+
#
|
121
|
+
# [param] String filter
|
122
|
+
# [return] Object
|
123
|
+
#
|
124
|
+
def export( filter = nil )
|
125
|
+
puts format_module.export( pickup_fields( filter ), fields )
|
126
|
+
end
|
127
|
+
|
128
|
+
#
|
129
|
+
# [param] String estimate
|
130
|
+
# [return] RtmTime
|
131
|
+
#
|
132
|
+
def split_estimate( estimate )
|
133
|
+
::RtmTime::Ja.parse(estimate)
|
134
|
+
end
|
135
|
+
|
136
|
+
#
|
137
|
+
# [param] String
|
138
|
+
# [return] Time
|
139
|
+
#
|
140
|
+
def localtime( time )
|
141
|
+
if time.size > 0
|
142
|
+
Time.parse( time ).localtime
|
143
|
+
else
|
144
|
+
time
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
if RUBY_VERSION < '1.9'
|
3
|
+
require 'fastercsv'
|
4
|
+
else
|
5
|
+
require 'csv'
|
6
|
+
FasterCSV = CSV
|
7
|
+
end
|
8
|
+
|
9
|
+
module Gyunyu
|
10
|
+
module Command
|
11
|
+
module Export
|
12
|
+
module Format
|
13
|
+
module Csv
|
14
|
+
def self.export( tasks, fields )
|
15
|
+
FasterCSV.generate { |csv|
|
16
|
+
csv << fields
|
17
|
+
tasks.each { |t|
|
18
|
+
csv << fields.map { |f| t[f] }
|
19
|
+
}
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|