Sixeight-giic 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.
- data/README.rdoc +43 -0
- data/Rakefile +52 -0
- data/bin/giic +66 -0
- data/lib/giic.rb +206 -0
- data/spec/giic_spec.rb +42 -0
- data/spec/spec_helper.rb +2 -0
- metadata +70 -0
data/README.rdoc
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
= Giic
|
2
|
+
|
3
|
+
== DESCRIPTION:
|
4
|
+
|
5
|
+
Giic is a client of the github-issues API interface.
|
6
|
+
|
7
|
+
== FEATURES:
|
8
|
+
|
9
|
+
search, list, show, open, clone, reopen, edit, label, comment
|
10
|
+
|
11
|
+
== USAGE:
|
12
|
+
|
13
|
+
require 'giic'
|
14
|
+
|
15
|
+
giic = Giic.new('Sixeight', 'giic')
|
16
|
+
giic.list.each do |issue|
|
17
|
+
puts issue.title
|
18
|
+
end
|
19
|
+
|
20
|
+
giic.login!('login name', 'api token')
|
21
|
+
|
22
|
+
res = giic.login.open('awsome idea', 'I found that an awsome idea ...')
|
23
|
+
p res.number
|
24
|
+
|
25
|
+
giic.login.with_project(onother) do |user|
|
26
|
+
p user.add_label('bug', 5)
|
27
|
+
end
|
28
|
+
|
29
|
+
== REQUIREMENTS:
|
30
|
+
|
31
|
+
* Typhoeus
|
32
|
+
|
33
|
+
Install:
|
34
|
+
|
35
|
+
gem install pauldix-typhoeus -s http://gems.github.com
|
36
|
+
|
37
|
+
== TODO:
|
38
|
+
|
39
|
+
* Write a test
|
40
|
+
* Write a document
|
41
|
+
* Error handling
|
42
|
+
* and more more more
|
43
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec/rake/spectask'
|
2
|
+
|
3
|
+
Spec::Rake::SpecTask.new do |t|
|
4
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
5
|
+
t.spec_opts = ['-c']
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Run specs(default)'
|
9
|
+
task :default => :spec
|
10
|
+
|
11
|
+
namespace :gem do
|
12
|
+
desc 'Generate gemspec'
|
13
|
+
task :gemspec do |t|
|
14
|
+
require 'lib/giic'
|
15
|
+
File.open('giic.gemspec', "wb" ) do |file|
|
16
|
+
file << <<-EOS.gsub(/^ {8}/, '')
|
17
|
+
|
18
|
+
Gem::Specification.new do |s|
|
19
|
+
s.name = 'giic'
|
20
|
+
s.version = '#{Giic::VERSION}'
|
21
|
+
|
22
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
23
|
+
s.authors = ['Tomohiro Nishimura']
|
24
|
+
s.date = #{Time.now.strftime('%Y-%m-%d')}
|
25
|
+
s.email = 'tomohiro68@gmail.com'
|
26
|
+
s.files = %w( #{FileList['lib/**/*.rb'].join(' ')}
|
27
|
+
#{FileList['bin/*'].join(' ')}
|
28
|
+
#{FileList['spec/**/*.rb'].join(' ')}
|
29
|
+
README.rdoc
|
30
|
+
Rakefile )
|
31
|
+
s.executable = 'giic'
|
32
|
+
s.add_dependency('pauldix-typhoeus', '>= 0.0.8')
|
33
|
+
s.homepage = 'http://wiki.github.com/Sixeigh/giic'
|
34
|
+
s.has_rdoc = true
|
35
|
+
s.rdoc_options = ['--main', 'README.rdoc', '--exclude', 'spec']
|
36
|
+
s.extra_rdoc_files = ['README.rdoc']
|
37
|
+
s.summary = 'A github-issues API interface client.'
|
38
|
+
s.description = 'Giic is a client of github-issues API interface'
|
39
|
+
s.rubygems_version = '#{`gem --version`.chomp}'
|
40
|
+
end
|
41
|
+
|
42
|
+
EOS
|
43
|
+
end
|
44
|
+
puts "Generate gemspec"
|
45
|
+
end
|
46
|
+
|
47
|
+
desc 'Build the gem'
|
48
|
+
task :build => :gemspec do |t|
|
49
|
+
system 'gem', 'build', 'giic.gemspec'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
data/bin/giic
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
$KCODE = 'utf-8' unless ''.respond_to? :chr
|
5
|
+
|
6
|
+
require File.dirname(__FILE__) + '/../lib/giic'
|
7
|
+
require 'pp'
|
8
|
+
|
9
|
+
puts "iGiic version 0.0.1 (Giic #{Giic::VERSION})"
|
10
|
+
loop do
|
11
|
+
begin
|
12
|
+
print '> '
|
13
|
+
case command = gets.chomp
|
14
|
+
when /^set/
|
15
|
+
_, user, repo = command.split
|
16
|
+
user or (print('user = '); user = gets.chomp)
|
17
|
+
repo or (print('repo = '); repo = gets.chomp)
|
18
|
+
@giic = Giic.new(user, repo)
|
19
|
+
puts 'done'
|
20
|
+
when /^login/
|
21
|
+
unless @giic
|
22
|
+
warn 'you have to call "set"'
|
23
|
+
next
|
24
|
+
end
|
25
|
+
_, login, token = command.split
|
26
|
+
login or (print('login = '); login = gets.chomp)
|
27
|
+
token or (print('token = '); token = gets.chomp)
|
28
|
+
@giic.login!(login, token)
|
29
|
+
@__login = true
|
30
|
+
puts 'done'
|
31
|
+
when 'exit', 'e', 'quit', 'q'
|
32
|
+
break
|
33
|
+
when /^list/, /^show/, /^search/
|
34
|
+
unless @giic
|
35
|
+
warn 'you have to call "set"'
|
36
|
+
next
|
37
|
+
end
|
38
|
+
action, *args = command.split
|
39
|
+
pp @giic.__send__(action, *args)
|
40
|
+
when 'help'
|
41
|
+
@help ||= %w[
|
42
|
+
set login help exit quit
|
43
|
+
search list show open close
|
44
|
+
reopen edit label add_label
|
45
|
+
remove_label comment
|
46
|
+
]
|
47
|
+
puts @help
|
48
|
+
when /^open/, /^close/, /^reopen/, /^edit/, /^label/, /^add_label/, /^remove_label/, /^comment/
|
49
|
+
unless @__login
|
50
|
+
warn 'you have to call "set"' unless @giic
|
51
|
+
warn 'you have to call "login"'
|
52
|
+
next
|
53
|
+
end
|
54
|
+
action, *args = command.split
|
55
|
+
pp @giic.login.__send__(action, *args)
|
56
|
+
else
|
57
|
+
warn "no such command: #{command}"
|
58
|
+
end
|
59
|
+
rescue Giic::APIError => e
|
60
|
+
warn e
|
61
|
+
rescue => e
|
62
|
+
warn e
|
63
|
+
end
|
64
|
+
end
|
65
|
+
puts 'bye'
|
66
|
+
|
data/lib/giic.rb
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'typhoeus'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
# TODO: must find a better way to get same result
|
9
|
+
class Hash # :nodoc:
|
10
|
+
module CoreExt # :nodoc
|
11
|
+
def method_missing(meth, *args)
|
12
|
+
if value = self[meth] || self[meth.to_s]
|
13
|
+
return value
|
14
|
+
end
|
15
|
+
super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
include CoreExt
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# == Giic
|
23
|
+
#
|
24
|
+
# Giic is a client of the github-issues API interface.
|
25
|
+
#
|
26
|
+
class Giic
|
27
|
+
|
28
|
+
VERSION = '0.0.1'
|
29
|
+
|
30
|
+
attr_reader :user, :repo
|
31
|
+
|
32
|
+
class APIError < Exception
|
33
|
+
attr_reader :responce, :backtrace
|
34
|
+
def initialize(responce, backtrace)
|
35
|
+
@responce, @backtrace = responce, backtrace
|
36
|
+
super responce['error'].first['error']
|
37
|
+
end
|
38
|
+
def inspect; message end
|
39
|
+
end
|
40
|
+
|
41
|
+
def initialize(user, repo)
|
42
|
+
@user, @repo = user, repo
|
43
|
+
end
|
44
|
+
|
45
|
+
# search issue
|
46
|
+
# #=> issues
|
47
|
+
def search(query, state = 'open')
|
48
|
+
back :issues, Core.search(:user => @user, :repo => @repo, :state => state, :search_term => query)
|
49
|
+
end
|
50
|
+
|
51
|
+
# list issues
|
52
|
+
# #=> issues
|
53
|
+
def list(state = 'open')
|
54
|
+
back :issues, Core.list(:user => @user, :repo => @repo, :state => state)
|
55
|
+
end
|
56
|
+
|
57
|
+
# show specific issue
|
58
|
+
# #=> issue
|
59
|
+
def show(number)
|
60
|
+
back :issue, Core.show(:user => @user, :repo => @repo, :number => number)
|
61
|
+
end
|
62
|
+
|
63
|
+
# get user instance for POST request
|
64
|
+
# #=> Instance of Giic::User
|
65
|
+
def login(login = nil, token = nil)
|
66
|
+
unless [login, token].all?
|
67
|
+
raise 'You must login at least onece' unless @login_user
|
68
|
+
return @login_user
|
69
|
+
end
|
70
|
+
User.new login, token, self
|
71
|
+
end
|
72
|
+
|
73
|
+
# login github
|
74
|
+
def login!(login, token)
|
75
|
+
@login_user = login(login, token)
|
76
|
+
end
|
77
|
+
|
78
|
+
def back(default, result) # :nodoc:
|
79
|
+
if result.has_key? 'error'
|
80
|
+
raise APIError.new(result, caller)
|
81
|
+
end
|
82
|
+
result[default.to_s]
|
83
|
+
end
|
84
|
+
|
85
|
+
class User
|
86
|
+
def initialize(login, token, project)
|
87
|
+
@login, @token = login, token
|
88
|
+
@project = project
|
89
|
+
end
|
90
|
+
|
91
|
+
# open new issue
|
92
|
+
# #=> issue
|
93
|
+
def open(title, body)
|
94
|
+
back :issue, Giic::Core.open(:user => @project.user, :repo => @project.repo,
|
95
|
+
:params => { :title => title, :body => body }.merge(authentication_data))
|
96
|
+
end
|
97
|
+
|
98
|
+
# close issue
|
99
|
+
# #=> issue
|
100
|
+
def close(number)
|
101
|
+
back :issue, Giic::Core.close(:user => @project.user, :repo => @project.repo, :number => number,
|
102
|
+
:params => authentication_data)
|
103
|
+
end
|
104
|
+
|
105
|
+
# reopen issue
|
106
|
+
# #=> issue
|
107
|
+
def reopen(number)
|
108
|
+
back :issue, Giic::Core.reopen(:user => @project.user, :repo => @project.repo, :number => number,
|
109
|
+
:params => authentication_data)
|
110
|
+
end
|
111
|
+
|
112
|
+
# edit issue
|
113
|
+
# #=> issue
|
114
|
+
def edit(number, body, title = nil)
|
115
|
+
edit_data = { :body => body }
|
116
|
+
edit_data.merge!(:title => title) if title
|
117
|
+
back :issue, Giic::Core.edit(:user => @project.user, :repo => @project.repo, :number => number,
|
118
|
+
:params => edit_data.merge(authentication_data))
|
119
|
+
end
|
120
|
+
|
121
|
+
# to operate label for issue
|
122
|
+
# #=> labels
|
123
|
+
def label(operate, label, number)
|
124
|
+
back :labels, Giic::Core.label(:user => @project.user, :repo => @project.repo, :number => number,
|
125
|
+
:operate => operate, :label => label,
|
126
|
+
:params => authentication_data)
|
127
|
+
end
|
128
|
+
|
129
|
+
# add label to issue
|
130
|
+
# #=> labels
|
131
|
+
def add_label(label, number)
|
132
|
+
label 'add', label, number
|
133
|
+
end
|
134
|
+
|
135
|
+
# remove label from issue
|
136
|
+
# #=> labels
|
137
|
+
def remove_label(label, number)
|
138
|
+
label 'remove', label, number
|
139
|
+
end
|
140
|
+
|
141
|
+
# post comment to issue
|
142
|
+
# #=> comment
|
143
|
+
def comment(number, comment)
|
144
|
+
back :comment, Giic::Core.comment(:user => @project.user, :repo => @project.repo, :number => number,
|
145
|
+
:params => { :comment => comment }.merge(authentication_data))
|
146
|
+
end
|
147
|
+
|
148
|
+
def change_project!(project)
|
149
|
+
raise 'project must be instance of Giic' unless project.instance_of? Giic
|
150
|
+
@project = project
|
151
|
+
end
|
152
|
+
|
153
|
+
# swap using project temporarily. e.g.)
|
154
|
+
#
|
155
|
+
# proj.login.with_project({:repo => 'other'}) do |user|
|
156
|
+
# user.open('new issue', 'I have a lot of bugs')
|
157
|
+
# end
|
158
|
+
def with_project(project)
|
159
|
+
original = @project
|
160
|
+
@project = case project
|
161
|
+
when Giic
|
162
|
+
project
|
163
|
+
when Hash
|
164
|
+
user = project[:user] || original.user
|
165
|
+
repo = project[:repo] || original.repo
|
166
|
+
Giic.new user, repo
|
167
|
+
else
|
168
|
+
raise 'project must be instance of Giic or Hash'
|
169
|
+
end
|
170
|
+
yield self
|
171
|
+
ensure
|
172
|
+
@project = original
|
173
|
+
end
|
174
|
+
|
175
|
+
private
|
176
|
+
|
177
|
+
def authentication_data # :nodoc:
|
178
|
+
{ :login => @login, :token => @token }
|
179
|
+
end
|
180
|
+
|
181
|
+
def back(default, result) # :nodoc:
|
182
|
+
@project.back default, result
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
# Core class is the Giic core that using Typhoeus library
|
187
|
+
class Core
|
188
|
+
include Typhoeus
|
189
|
+
remote_defaults :base_uri => 'http://github.com/api/v2/yaml/issues',
|
190
|
+
:on_success => lambda {|responce| YAML.load(responce.body) },
|
191
|
+
:on_failure => lambda {|responce| { 'error' => { 'error' => 'connection error',
|
192
|
+
'responce' => responce,
|
193
|
+
'code' => responce.code }}}
|
194
|
+
|
195
|
+
define_remote_method :search, :path => '/search/:user/:repo/:state/:search_term'
|
196
|
+
define_remote_method :list, :path => '/list/:user/:repo/:state'
|
197
|
+
define_remote_method :show, :path => '/show/:user/:repo/:number'
|
198
|
+
define_remote_method :open, :path => '/open/:user/:repo', :method => 'post'
|
199
|
+
define_remote_method :close, :path => '/close/:user/:repo/:number', :method => 'post'
|
200
|
+
define_remote_method :reopen, :path => '/reopen/:user/:repo/:number', :method => 'post'
|
201
|
+
define_remote_method :edit, :path => '/edit/:user/:repo/:number', :method => 'post'
|
202
|
+
define_remote_method :label, :path => '/label/:operate/:user/:repo/:label/:number', :method => 'post'
|
203
|
+
define_remote_method :comment, :path => '/comment/:user/:repo/:number', :method => 'post'
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
data/spec/giic_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
# TODO: need more test code
|
4
|
+
class Giic
|
5
|
+
|
6
|
+
describe Giic do
|
7
|
+
%w[ search list show ].each do |meth|
|
8
|
+
instance_eval <<-EOS
|
9
|
+
it "has #{meth} method" do
|
10
|
+
Giic.instance_methods.should be_include('#{meth}')
|
11
|
+
end
|
12
|
+
EOS
|
13
|
+
end
|
14
|
+
|
15
|
+
describe User do
|
16
|
+
%w[
|
17
|
+
open close reopen edit label
|
18
|
+
comment add_label remove_label
|
19
|
+
].each do |meth|
|
20
|
+
instance_eval <<-EOS
|
21
|
+
it "has #{meth} method" do
|
22
|
+
User.instance_methods.should be_include('#{meth}')
|
23
|
+
end
|
24
|
+
EOS
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe Core do
|
29
|
+
%w[
|
30
|
+
search list show open close
|
31
|
+
reopen edit label comment
|
32
|
+
].each do |meth|
|
33
|
+
instance_eval <<-EOS
|
34
|
+
it "ihas #{meth} method" do
|
35
|
+
Core.should respond_to :#{meth}
|
36
|
+
end
|
37
|
+
EOS
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Sixeight-giic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomohiro Nishimura
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-08 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: pauldix-typhoeus
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.8
|
24
|
+
version:
|
25
|
+
description: Giic is a client of github-issues API interface
|
26
|
+
email: tomohiro68@gmail.com
|
27
|
+
executables:
|
28
|
+
- giic
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
files:
|
34
|
+
- lib/giic.rb
|
35
|
+
- bin/giic
|
36
|
+
- spec/giic_spec.rb
|
37
|
+
- spec/spec_helper.rb
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://wiki.github.com/Sixeigh/giic
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options:
|
44
|
+
- --main
|
45
|
+
- README.rdoc
|
46
|
+
- --exclude
|
47
|
+
- spec
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.2.0
|
66
|
+
signing_key:
|
67
|
+
specification_version: 2
|
68
|
+
summary: A github-issues API interface client.
|
69
|
+
test_files: []
|
70
|
+
|