octopi 0.2.8 → 0.3.0
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.markdown +144 -0
- data/Rakefile +1 -0
- data/VERSION.yml +3 -2
- data/lib/octopi.rb +7 -8
- data/lib/octopi/api.rb +2 -1
- data/lib/octopi/repository.rb +5 -1
- data/octopi.gemspec +9 -8
- data/test/issue_test.rb +1 -1
- data/test/repository_test.rb +6 -0
- data/test/tag_test.rb +1 -1
- data/test/test_helper.rb +1 -0
- metadata +79 -23
- data/README.rdoc +0 -144
data/README.markdown
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
# octopi
|
2
|
+
|
3
|
+
Octopi is a Ruby interface to GitHub API v2 (http://develop.github.com).
|
4
|
+
|
5
|
+
To install it as a Gem, just run:
|
6
|
+
|
7
|
+
$ sudo gem install octopi
|
8
|
+
|
9
|
+
Get notifications via Twitter, following @octopi_gem:
|
10
|
+
http://twitter.com/octopi_gem
|
11
|
+
|
12
|
+
## Authenticated Usage
|
13
|
+
|
14
|
+
### Seamless authentication using .gitconfig defaults
|
15
|
+
|
16
|
+
If you have your <tt>~/.gitconfig</tt> file in place, and you have a [github] section (if you don't, take a look at this [GitHub Guides entry][http://github.com/guides/tell-git-your-user-name-and-email-address], you can use seamless authentication using this method:
|
17
|
+
|
18
|
+
authenticated do
|
19
|
+
repo = Repository.find(:name => "api-labrat", :user => "fcoury")
|
20
|
+
end
|
21
|
+
|
22
|
+
### Explicit authentication
|
23
|
+
|
24
|
+
Sometimes, you may not want to get authentication data from _~/.gitconfig_. You want to use GitHub API authenticated as a third party. For this use case, you have a couple of options too.
|
25
|
+
|
26
|
+
**1. Providing login and token inline:**
|
27
|
+
|
28
|
+
authenticated_with :login => "mylogin", :token => "mytoken" do
|
29
|
+
repo = Repository.find(:name => "api-labrat", :user => "fcoury")
|
30
|
+
issue = repo.open_issue :title => "Sample issue",
|
31
|
+
:body => "This issue was opened using GitHub API and Octopi"
|
32
|
+
puts issue.number
|
33
|
+
end
|
34
|
+
|
35
|
+
**2. Providing login and password inline:**
|
36
|
+
|
37
|
+
authenticated_with :login => "mylogin", :password => "password" do
|
38
|
+
repo = Repository.find(:name => "api-labrat", :user => "fcoury")
|
39
|
+
issue = repo.open_issue :title => "Sample issue",
|
40
|
+
:body => "This issue was opened using GitHub API and Octopi"
|
41
|
+
puts issue.number
|
42
|
+
end
|
43
|
+
|
44
|
+
**3. Providing a YAML file with authentication information:**
|
45
|
+
|
46
|
+
Use the following format:
|
47
|
+
|
48
|
+
#
|
49
|
+
# Octopi GitHub API configuration file
|
50
|
+
#
|
51
|
+
|
52
|
+
# GitHub user login and token
|
53
|
+
login: github-username
|
54
|
+
token: github-token
|
55
|
+
|
56
|
+
# Trace level
|
57
|
+
# Possible values:
|
58
|
+
# false - no tracing, same as if the param is ommited
|
59
|
+
# true - will output each POST or GET operation to the stdout
|
60
|
+
# curl - same as true, but in addition will output the curl equivalent of each command (for debugging)
|
61
|
+
trace: curl
|
62
|
+
|
63
|
+
And change the way you connect to:
|
64
|
+
|
65
|
+
authenticated_with :config => "github.yml" do
|
66
|
+
(...)
|
67
|
+
end
|
68
|
+
|
69
|
+
## Anonymous Usage
|
70
|
+
|
71
|
+
This reflects the usage of the API to retrieve information on a read-only fashion, where the user doesn't have to be authenticated.
|
72
|
+
|
73
|
+
### Users API
|
74
|
+
|
75
|
+
Getting user information
|
76
|
+
|
77
|
+
user = User.find("fcoury")
|
78
|
+
puts "#{user.name} is being followed by #{user.followers.join(", ")} and following #{user.following.join(", ")}"
|
79
|
+
|
80
|
+
The bang methods `followers!` and `following!` retrieves a full User object for each user login returned, so it has to be used carefully.
|
81
|
+
|
82
|
+
user.followers!.each do |u|
|
83
|
+
puts " - #{u.name} (#{u.login}) has #{u.public_repo_count} repo(s)"
|
84
|
+
end
|
85
|
+
|
86
|
+
Searching for user
|
87
|
+
|
88
|
+
users = User.find_all("silva")
|
89
|
+
puts "#{users.size} users found for 'silva':"
|
90
|
+
users.each do |u|
|
91
|
+
puts " - #{u.name}"
|
92
|
+
end
|
93
|
+
|
94
|
+
### Repositories API
|
95
|
+
|
96
|
+
repo = user.repository("octopi") # same as: Repository.find("fcoury", "octopi")
|
97
|
+
puts "Repository: #{repo.name} - #{repo.description} (by #{repo.owner}) - #{repo.url}"
|
98
|
+
puts " Tags: #{repo.tags and repo.tags.map {|t| t.name}.join(", ")}"
|
99
|
+
|
100
|
+
Search:
|
101
|
+
|
102
|
+
repos = Repository.find_all("ruby", "git")
|
103
|
+
puts "#{repos.size} repository(ies) with 'ruby' and 'git':"
|
104
|
+
repos.each do |r|
|
105
|
+
puts " - #{r.name}"
|
106
|
+
end
|
107
|
+
|
108
|
+
Issues API integrated into the Repository object:
|
109
|
+
|
110
|
+
issue = repo.issues.first
|
111
|
+
puts "First open issue: #{issue.number} - #{issue.title} - Created at: #{issue.created_at}"
|
112
|
+
|
113
|
+
Single issue information:
|
114
|
+
|
115
|
+
issue = repo.issue(11)
|
116
|
+
|
117
|
+
Commits API information from a Repository object:
|
118
|
+
|
119
|
+
first_commit = repo.commits.first
|
120
|
+
puts "First commit: #{first_commit.id} - #{first_commit.message} - by #{first_commit.author['name']}"
|
121
|
+
|
122
|
+
Single commit information:
|
123
|
+
|
124
|
+
puts "Diff:"
|
125
|
+
first_commit.details.modified.each {|m| puts "#{m['filename']} DIFF: #{m['diff']}" }
|
126
|
+
|
127
|
+
## Author
|
128
|
+
|
129
|
+
* Felipe Coury - http://felipecoury.com
|
130
|
+
* HasMany.info blog - http://hasmany.info
|
131
|
+
|
132
|
+
## Contributors
|
133
|
+
|
134
|
+
In alphabetical order:
|
135
|
+
|
136
|
+
* Ryan Bigg - http://ryanbigg.net
|
137
|
+
* Brandon Calloway - http://github.com/bcalloway
|
138
|
+
* runpaint - http://github.com/runpaint
|
139
|
+
|
140
|
+
Thanks guys!
|
141
|
+
|
142
|
+
## Copyright
|
143
|
+
|
144
|
+
Copyright (c) 2009 Felipe Coury. See LICENSE for details.
|
data/Rakefile
CHANGED
data/VERSION.yml
CHANGED
data/lib/octopi.rb
CHANGED
@@ -42,8 +42,6 @@ module Octopi
|
|
42
42
|
def authenticated_with(options, &block)
|
43
43
|
begin
|
44
44
|
|
45
|
-
Api.api.trace_level = options[:trace] if options[:trace]
|
46
|
-
|
47
45
|
if options[:token].nil? && !options[:password].nil?
|
48
46
|
options[:token] = grab_token(options[:login], options[:password])
|
49
47
|
end
|
@@ -53,13 +51,14 @@ module Octopi
|
|
53
51
|
rescue Octopi::NotFound
|
54
52
|
raise Octopi::InvalidLogin
|
55
53
|
end
|
56
|
-
|
57
|
-
trace("=> Trace on: #{options[:trace]}")
|
58
|
-
|
54
|
+
|
59
55
|
Api.api = AuthApi.instance
|
56
|
+
Api.api.trace_level = options[:trace] if options[:trace]
|
60
57
|
Api.api.login = options[:login]
|
61
58
|
Api.api.token = options[:token]
|
62
|
-
|
59
|
+
|
60
|
+
trace("=> Trace on: #{options[:trace]}")
|
61
|
+
|
63
62
|
yield
|
64
63
|
ensure
|
65
64
|
# Reset authenticated so if we were to do an anonymous call it would Just Work(tm)
|
@@ -71,7 +70,7 @@ module Octopi
|
|
71
70
|
private
|
72
71
|
|
73
72
|
def grab_token(username, password)
|
74
|
-
a =
|
73
|
+
a = Mechanize.new { |agent|
|
75
74
|
# Fake out the agent
|
76
75
|
agent.user_agent_alias = 'Mac Safari'
|
77
76
|
}
|
@@ -130,7 +129,7 @@ module Octopi
|
|
130
129
|
|
131
130
|
def trace(text)
|
132
131
|
if Api.api.trace_level
|
133
|
-
puts
|
132
|
+
puts text
|
134
133
|
end
|
135
134
|
end
|
136
135
|
end
|
data/lib/octopi/api.rb
CHANGED
@@ -195,7 +195,8 @@ module Octopi
|
|
195
195
|
|
196
196
|
# It happens, in tests.
|
197
197
|
return resp if resp.headers.empty?
|
198
|
-
|
198
|
+
content_type = Array === resp.headers['content-type'] ? resp.headers['content-type'] : [resp.headers['content-type']]
|
199
|
+
ctype = content_type.first.split(";").first
|
199
200
|
raise FormatError, [ctype, format] unless CONTENT_TYPE[format.to_s].include?(ctype)
|
200
201
|
if format == 'yaml' && resp['error']
|
201
202
|
raise APIError, resp['error']
|
data/lib/octopi/repository.rb
CHANGED
@@ -111,11 +111,15 @@ module Octopi
|
|
111
111
|
def collaborators
|
112
112
|
property('collaborators', [self.owner, self.name].join('/')).values.map { |v| User.find(v.join) }
|
113
113
|
end
|
114
|
+
|
115
|
+
def languages
|
116
|
+
property('languages', [self.owner, self.name].join('/')).values.inject({}){|sum,map| map.each{|k,v| sum[k] = v}}
|
117
|
+
end
|
114
118
|
|
115
119
|
def self.create(options={})
|
116
120
|
raise AuthenticationRequired, "To create a repository you must be authenticated." if Api.api.read_only?
|
117
121
|
self.validate_args(options[:name] => :repo)
|
118
|
-
new(Api.api.post(path_for(:create), options)["repository"])
|
122
|
+
new(Api.api.post(path_for(:create), options.merge( :cache => false ))["repository"])
|
119
123
|
end
|
120
124
|
|
121
125
|
def delete!
|
data/octopi.gemspec
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{octopi}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Felipe Coury"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-09-22}
|
13
13
|
s.email = %q{felipe.coury@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
16
|
-
"README.
|
16
|
+
"README.markdown"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
19
|
".gitignore",
|
20
20
|
".yardoc",
|
21
21
|
"CHANGELOG.md",
|
22
22
|
"LICENSE",
|
23
|
-
"README.
|
23
|
+
"README.markdown",
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION.yml",
|
26
26
|
"contrib/backup.rb",
|
@@ -54,7 +54,7 @@ Gem::Specification.new do |s|
|
|
54
54
|
s.rdoc_options = ["--charset=UTF-8"]
|
55
55
|
s.require_paths = ["lib"]
|
56
56
|
s.rubyforge_project = %q{octopi}
|
57
|
-
s.rubygems_version = %q{1.3.
|
57
|
+
s.rubygems_version = %q{1.3.7}
|
58
58
|
s.summary = %q{A Ruby interface to GitHub API v2}
|
59
59
|
s.test_files = [
|
60
60
|
"test/api_test.rb",
|
@@ -85,7 +85,7 @@ Gem::Specification.new do |s|
|
|
85
85
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
86
86
|
s.specification_version = 3
|
87
87
|
|
88
|
-
if Gem::Version.new(Gem::
|
88
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
89
89
|
s.add_runtime_dependency(%q<nokogiri>, [">= 1.3.1"])
|
90
90
|
s.add_runtime_dependency(%q<httparty>, [">= 0.4.5"])
|
91
91
|
s.add_runtime_dependency(%q<mechanize>, [">= 0.9.3"])
|
@@ -103,3 +103,4 @@ Gem::Specification.new do |s|
|
|
103
103
|
s.add_dependency(%q<api_cache>, [">= 0"])
|
104
104
|
end
|
105
105
|
end
|
106
|
+
|
data/test/issue_test.rb
CHANGED
@@ -90,7 +90,7 @@ class IssueTest < Test::Unit::TestCase
|
|
90
90
|
assert @issue.labels.empty?
|
91
91
|
@issue.add_label("one-point-oh", "maybe-two-point-oh")
|
92
92
|
assert !@issue.labels.empty?
|
93
|
-
|
93
|
+
assert_equal 2, @issue.labels.size
|
94
94
|
end
|
95
95
|
|
96
96
|
should "removing a label" do
|
data/test/repository_test.rb
CHANGED
@@ -100,6 +100,12 @@ class RepositoryTest < Test::Unit::TestCase
|
|
100
100
|
assert_equal 1, @collaborators.size
|
101
101
|
assert @collaborators.first.is_a?(User)
|
102
102
|
end
|
103
|
+
|
104
|
+
should "be able to find all languages" do
|
105
|
+
@languages = @repository.languages
|
106
|
+
assert_equal 2, @languages.size
|
107
|
+
assert_equal 111555, @languages["Ruby"]
|
108
|
+
end
|
103
109
|
|
104
110
|
should "be able to create a repository" do
|
105
111
|
auth do
|
data/test/tag_test.rb
CHANGED
@@ -12,7 +12,7 @@ class TagTest < Test::Unit::TestCase
|
|
12
12
|
should "be able to find all tags" do
|
13
13
|
tags = Tag.all(:user => "fcoury", :repository => "octopi")
|
14
14
|
assert_not_nil tags
|
15
|
-
|
15
|
+
assert_equal 9, tags.size
|
16
16
|
assert tags.first.is_a?(Tag)
|
17
17
|
end
|
18
18
|
end
|
data/test/test_helper.rb
CHANGED
@@ -71,6 +71,7 @@ def fake_everything
|
|
71
71
|
"issues/show/fcoury/octopi/28" => issues("28"),
|
72
72
|
|
73
73
|
"repos/show/fcoury/octopi/collaborators" => File.join("repos", "fcoury", "octopi", "collaborators"),
|
74
|
+
"repos/show/fcoury/octopi/languages" => File.join("repos", "fcoury", "octopi", "languages"),
|
74
75
|
"repos/show/fcoury" => File.join("repos", "show", "fcoury"),
|
75
76
|
"repos/search/ruby+testing" => File.join("repos", "search"),
|
76
77
|
"repos/show/fcoury/octopi" => repos("master"),
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octopi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 19
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Felipe Coury
|
@@ -9,49 +15,71 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-09-22 00:00:00 -04:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: nokogiri
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 25
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 3
|
33
|
+
- 1
|
23
34
|
version: 1.3.1
|
24
|
-
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
25
37
|
- !ruby/object:Gem::Dependency
|
26
38
|
name: httparty
|
27
|
-
|
28
|
-
|
29
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
30
42
|
requirements:
|
31
43
|
- - ">="
|
32
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 5
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 4
|
49
|
+
- 5
|
33
50
|
version: 0.4.5
|
34
|
-
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
35
53
|
- !ruby/object:Gem::Dependency
|
36
54
|
name: mechanize
|
37
|
-
|
38
|
-
|
39
|
-
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
40
58
|
requirements:
|
41
59
|
- - ">="
|
42
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 61
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
- 9
|
65
|
+
- 3
|
43
66
|
version: 0.9.3
|
44
|
-
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id003
|
45
69
|
- !ruby/object:Gem::Dependency
|
46
70
|
name: api_cache
|
47
|
-
|
48
|
-
|
49
|
-
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
50
74
|
requirements:
|
51
75
|
- - ">="
|
52
76
|
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
53
80
|
version: "0"
|
54
|
-
|
81
|
+
type: :runtime
|
82
|
+
version_requirements: *id004
|
55
83
|
description:
|
56
84
|
email: felipe.coury@gmail.com
|
57
85
|
executables: []
|
@@ -60,13 +88,13 @@ extensions: []
|
|
60
88
|
|
61
89
|
extra_rdoc_files:
|
62
90
|
- LICENSE
|
63
|
-
- README.
|
91
|
+
- README.markdown
|
64
92
|
files:
|
65
93
|
- .gitignore
|
66
94
|
- .yardoc
|
67
95
|
- CHANGELOG.md
|
68
96
|
- LICENSE
|
69
|
-
- README.
|
97
|
+
- README.markdown
|
70
98
|
- Rakefile
|
71
99
|
- VERSION.yml
|
72
100
|
- contrib/backup.rb
|
@@ -95,6 +123,28 @@ files:
|
|
95
123
|
- lib/octopi/tag.rb
|
96
124
|
- lib/octopi/user.rb
|
97
125
|
- octopi.gemspec
|
126
|
+
- test/api_test.rb
|
127
|
+
- test/authenticated_test.rb
|
128
|
+
- test/base_test.rb
|
129
|
+
- test/blob_test.rb
|
130
|
+
- test/branch_test.rb
|
131
|
+
- test/commit_test.rb
|
132
|
+
- test/file_object_test.rb
|
133
|
+
- test/gist_test.rb
|
134
|
+
- test/issue_comment.rb
|
135
|
+
- test/issue_set_test.rb
|
136
|
+
- test/issue_test.rb
|
137
|
+
- test/key_set_test.rb
|
138
|
+
- test/key_test.rb
|
139
|
+
- test/repository_set_test.rb
|
140
|
+
- test/repository_test.rb
|
141
|
+
- test/stubs/commits/fcoury/octopi/octopi.rb
|
142
|
+
- test/tag_test.rb
|
143
|
+
- test/test_helper.rb
|
144
|
+
- test/user_test.rb
|
145
|
+
- examples/authenticated.rb
|
146
|
+
- examples/issues.rb
|
147
|
+
- examples/overall.rb
|
98
148
|
has_rdoc: true
|
99
149
|
homepage: http://github.com/fcoury/octopi
|
100
150
|
licenses: []
|
@@ -105,21 +155,27 @@ rdoc_options:
|
|
105
155
|
require_paths:
|
106
156
|
- lib
|
107
157
|
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
108
159
|
requirements:
|
109
160
|
- - ">="
|
110
161
|
- !ruby/object:Gem::Version
|
162
|
+
hash: 3
|
163
|
+
segments:
|
164
|
+
- 0
|
111
165
|
version: "0"
|
112
|
-
version:
|
113
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
none: false
|
114
168
|
requirements:
|
115
169
|
- - ">="
|
116
170
|
- !ruby/object:Gem::Version
|
171
|
+
hash: 3
|
172
|
+
segments:
|
173
|
+
- 0
|
117
174
|
version: "0"
|
118
|
-
version:
|
119
175
|
requirements: []
|
120
176
|
|
121
177
|
rubyforge_project: octopi
|
122
|
-
rubygems_version: 1.3.
|
178
|
+
rubygems_version: 1.3.7
|
123
179
|
signing_key:
|
124
180
|
specification_version: 3
|
125
181
|
summary: A Ruby interface to GitHub API v2
|
data/README.rdoc
DELETED
@@ -1,144 +0,0 @@
|
|
1
|
-
= octopi
|
2
|
-
|
3
|
-
Octopi is a Ruby interface to GitHub API v2 (http://develop.github.com).
|
4
|
-
|
5
|
-
To install it as a Gem, just run:
|
6
|
-
|
7
|
-
$ sudo gem install octopi
|
8
|
-
|
9
|
-
Get notifications via Twitter, following @octopi_gem:
|
10
|
-
http://twitter.com/octopi_gem
|
11
|
-
|
12
|
-
== Authenticated Usage
|
13
|
-
|
14
|
-
=== Seamless authentication using .gitconfig defaults
|
15
|
-
|
16
|
-
If you have your <tt>~/.gitconfig</tt> file in place, and you have a [github] section (if you don't, take a look at this GitHub Guides entry: http://github.com/guides/tell-git-your-user-name-and-email-address), you can use seamless authentication using this method:
|
17
|
-
|
18
|
-
authenticated do
|
19
|
-
repo = Repository.find(:name => "api-labrat", :user => "fcoury")
|
20
|
-
end
|
21
|
-
|
22
|
-
=== Explicit authentication
|
23
|
-
|
24
|
-
Sometimes, you may not want to get authentication data from <tt>~/.gitconfig</tt>. You want to use GitHub API authenticated as a third party. For this use case, you have a couple of options too.
|
25
|
-
|
26
|
-
<b>1. Providing login and token inline:</b>
|
27
|
-
|
28
|
-
authenticated_with "mylogin", "mytoken" do
|
29
|
-
repo = Repository.find(:name => "api-labrat", :user => "fcoury")
|
30
|
-
issue = repo.open_issue :title => "Sample issue",
|
31
|
-
:body => "This issue was opened using GitHub API and Octopi"
|
32
|
-
puts issue.number
|
33
|
-
end
|
34
|
-
|
35
|
-
<b>2. Providing login and password inline:</b>
|
36
|
-
|
37
|
-
authenticated_with "mylogin", "password" do
|
38
|
-
repo = Repository.find(:name => "api-labrat", :user => "fcoury")
|
39
|
-
issue = repo.open_issue :title => "Sample issue",
|
40
|
-
:body => "This issue was opened using GitHub API and Octopi"
|
41
|
-
puts issue.number
|
42
|
-
end
|
43
|
-
|
44
|
-
<b>3. Providing a YAML file with authentication information:</b>
|
45
|
-
|
46
|
-
Use the following format:
|
47
|
-
|
48
|
-
#
|
49
|
-
# Octopi GitHub API configuration file
|
50
|
-
#
|
51
|
-
|
52
|
-
# GitHub user login and token
|
53
|
-
login: github-username
|
54
|
-
token: github-token
|
55
|
-
|
56
|
-
# Trace level
|
57
|
-
# Possible values:
|
58
|
-
# false - no tracing, same as if the param is ommited
|
59
|
-
# true - will output each POST or GET operation to the stdout
|
60
|
-
# curl - same as true, but in addition will output the curl equivalent of each command (for debugging)
|
61
|
-
trace: curl
|
62
|
-
|
63
|
-
And change the way you connect to:
|
64
|
-
|
65
|
-
authenticated_with :config => "github.yml" do |g|
|
66
|
-
(...)
|
67
|
-
end
|
68
|
-
|
69
|
-
== Anonymous Usage
|
70
|
-
|
71
|
-
This reflects the usage of the API to retrieve information on a read-only fashion, where the user doesn't have to be authenticated.
|
72
|
-
|
73
|
-
=== Users API
|
74
|
-
|
75
|
-
Getting user information
|
76
|
-
|
77
|
-
user = User.find("fcoury")
|
78
|
-
puts "#{user.name} is being followed by #{user.followers.join(", ")} and following #{user.following.join(", ")}"
|
79
|
-
|
80
|
-
The bang methods `followers!` and `following!` retrieves a full User object for each user login returned, so it has to be used carefully.
|
81
|
-
|
82
|
-
user.followers!.each do |u|
|
83
|
-
puts " - #{u.name} (#{u.login}) has #{u.public_repo_count} repo(s)"
|
84
|
-
end
|
85
|
-
|
86
|
-
Searching for user
|
87
|
-
|
88
|
-
users = User.find_all("silva")
|
89
|
-
puts "#{users.size} users found for 'silva':"
|
90
|
-
users.each do |u|
|
91
|
-
puts " - #{u.name}"
|
92
|
-
end
|
93
|
-
|
94
|
-
=== Repositories API
|
95
|
-
|
96
|
-
repo = user.repository("octopi") # same as: Repository.find("fcoury", "octopi")
|
97
|
-
puts "Repository: #{repo.name} - #{repo.description} (by #{repo.owner}) - #{repo.url}"
|
98
|
-
puts " Tags: #{repo.tags and repo.tags.map {|t| t.name}.join(", ")}"
|
99
|
-
|
100
|
-
Search:
|
101
|
-
|
102
|
-
repos = Repository.find_all("ruby", "git")
|
103
|
-
puts "#{repos.size} repository(ies) with 'ruby' and 'git':"
|
104
|
-
repos.each do |r|
|
105
|
-
puts " - #{r.name}"
|
106
|
-
end
|
107
|
-
|
108
|
-
Issues API integrated into the Repository object:
|
109
|
-
|
110
|
-
issue = repo.issues.first
|
111
|
-
puts "First open issue: #{issue.number} - #{issue.title} - Created at: #{issue.created_at}"
|
112
|
-
|
113
|
-
Single issue information:
|
114
|
-
|
115
|
-
issue = repo.issue(11)
|
116
|
-
|
117
|
-
Commits API information from a Repository object:
|
118
|
-
|
119
|
-
first_commit = repo.commits.first
|
120
|
-
puts "First commit: #{first_commit.id} - #{first_commit.message} - by #{first_commit.author['name']}"
|
121
|
-
|
122
|
-
Single commit information:
|
123
|
-
|
124
|
-
puts "Diff:"
|
125
|
-
first_commit.details.modified.each {|m| puts "#{m['filename']} DIFF: #{m['diff']}" }
|
126
|
-
|
127
|
-
== Author
|
128
|
-
|
129
|
-
* Felipe Coury - http://felipecoury.com
|
130
|
-
* HasMany.info blog - http://hasmany.info
|
131
|
-
|
132
|
-
== Contributors
|
133
|
-
|
134
|
-
In alphabetical order:
|
135
|
-
|
136
|
-
* Ryan Bigg - http://frozenplague.net
|
137
|
-
* Brandon Calloway - http://github.com/bcalloway
|
138
|
-
* runpaint - http://github.com/runpaint
|
139
|
-
|
140
|
-
Thanks guys!
|
141
|
-
|
142
|
-
== Copyright
|
143
|
-
|
144
|
-
Copyright (c) 2009 Felipe Coury. See LICENSE for details.
|