devver-octopi 0.2.13 → 0.2.14
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/VERSION.yml +2 -0
- data/lib/octopi.rb +1 -1
- data/lib/octopi/base.rb +2 -2
- data/lib/octopi/repository.rb +1 -1
- data/lib/octopi/user.rb +11 -3
- data/test/base_test.rb +20 -0
- metadata +46 -24
- data/README.rdoc +0 -144
- data/lib/ext/hash_ext.rb +0 -5
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/VERSION.yml
CHANGED
data/lib/octopi.rb
CHANGED
data/lib/octopi/base.rb
CHANGED
@@ -26,8 +26,8 @@ module Octopi
|
|
26
26
|
# puts caller.first.inspect
|
27
27
|
# puts "#{self.class.inspect} #{attributes.keys.map { |s| s.to_sym }.inspect}"
|
28
28
|
attributes.each do |key, value|
|
29
|
-
|
30
|
-
self.send(
|
29
|
+
method = "#{key}="
|
30
|
+
self.send(method, value) if respond_to? method
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
data/lib/octopi/repository.rb
CHANGED
@@ -109,7 +109,7 @@ module Octopi
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def collaborators
|
112
|
-
property('collaborators', [self.owner, self.name].join('/')).values.map { |v| User.find(v) }
|
112
|
+
property('collaborators', [self.owner, self.name].join('/')).values.map { |v| User.find(v.join) }
|
113
113
|
end
|
114
114
|
|
115
115
|
def self.create(options={})
|
data/lib/octopi/user.rb
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
module Octopi
|
2
2
|
class User < Base
|
3
3
|
include Resource
|
4
|
-
attr_accessor :company, :name, :following_count, :
|
5
|
-
|
6
|
-
|
4
|
+
attr_accessor :company, :name, :following_count, :gravatar_id,
|
5
|
+
:blog, :public_repo_count, :public_gist_count,
|
6
|
+
:id, :login, :followers_count, :created_at,
|
7
|
+
:email, :location, :disk_usage, :private_repo_count,
|
8
|
+
:private_gist_count, :collaborators, :plan,
|
9
|
+
:owned_private_repo_count, :total_private_repo_count,
|
10
|
+
|
11
|
+
# These come from search results, which doesn't
|
12
|
+
# contain the above information.
|
13
|
+
:actions, :score, :language, :followers, :following,
|
14
|
+
:fullname, :type, :username, :repos, :pushed, :created
|
7
15
|
|
8
16
|
def plan=(attributes={})
|
9
17
|
@plan = Plan.new(attributes)
|
data/test/base_test.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class BaseTest < Test::Unit::TestCase
|
4
|
+
class SparseUser < Octopi::Base
|
5
|
+
include Octopi::Resource
|
6
|
+
|
7
|
+
attr_accessor :some_attribute
|
8
|
+
|
9
|
+
find_path "/user/search/:query"
|
10
|
+
resource_path "/user/show/:id"
|
11
|
+
end
|
12
|
+
|
13
|
+
def setup
|
14
|
+
fake_everything
|
15
|
+
end
|
16
|
+
|
17
|
+
should "not raise an error if it doesn't know about the attributes that GitHub API provides" do
|
18
|
+
assert_nothing_raised { SparseUser.find("radar") }
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devver-octopi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 14
|
9
|
+
version: 0.2.14
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Felipe Coury
|
@@ -9,49 +14,63 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-04-05 00:00:00 -06:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: nokogiri
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 3
|
30
|
+
- 1
|
23
31
|
version: 1.3.1
|
24
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: httparty
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ">="
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 4
|
44
|
+
- 5
|
33
45
|
version: 0.4.5
|
34
|
-
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
35
48
|
- !ruby/object:Gem::Dependency
|
36
49
|
name: mechanize
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
52
|
requirements:
|
41
53
|
- - ">="
|
42
54
|
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
- 9
|
58
|
+
- 3
|
43
59
|
version: 0.9.3
|
44
|
-
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
45
62
|
- !ruby/object:Gem::Dependency
|
46
63
|
name: api_cache
|
47
|
-
|
48
|
-
|
49
|
-
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
50
66
|
requirements:
|
51
67
|
- - ">="
|
52
68
|
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
53
71
|
version: "0"
|
54
|
-
|
72
|
+
type: :runtime
|
73
|
+
version_requirements: *id004
|
55
74
|
description: |
|
56
75
|
This is a gem of the Devver fork of Octopi (a Github API library), which can be
|
57
76
|
found at http://github.com/fcoury/octopi. This gem exists solely to enable us
|
@@ -65,17 +84,16 @@ extensions: []
|
|
65
84
|
|
66
85
|
extra_rdoc_files:
|
67
86
|
- LICENSE
|
68
|
-
- README.
|
87
|
+
- README.markdown
|
69
88
|
files:
|
70
89
|
- .gitignore
|
71
90
|
- .yardoc
|
72
91
|
- CHANGELOG.md
|
73
92
|
- LICENSE
|
74
|
-
- README.
|
93
|
+
- README.markdown
|
75
94
|
- Rakefile
|
76
95
|
- VERSION.yml
|
77
96
|
- contrib/backup.rb
|
78
|
-
- lib/ext/hash_ext.rb
|
79
97
|
- lib/ext/string_ext.rb
|
80
98
|
- lib/octopi.rb
|
81
99
|
- lib/octopi/api.rb
|
@@ -100,6 +118,7 @@ files:
|
|
100
118
|
- lib/octopi/self.rb
|
101
119
|
- lib/octopi/tag.rb
|
102
120
|
- lib/octopi/user.rb
|
121
|
+
- octopi.gemspec
|
103
122
|
has_rdoc: true
|
104
123
|
homepage: http://github.com/devver/octopi
|
105
124
|
licenses: []
|
@@ -113,24 +132,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
132
|
requirements:
|
114
133
|
- - ">="
|
115
134
|
- !ruby/object:Gem::Version
|
135
|
+
segments:
|
136
|
+
- 0
|
116
137
|
version: "0"
|
117
|
-
version:
|
118
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
139
|
requirements:
|
120
140
|
- - ">="
|
121
141
|
- !ruby/object:Gem::Version
|
142
|
+
segments:
|
143
|
+
- 0
|
122
144
|
version: "0"
|
123
|
-
version:
|
124
145
|
requirements: []
|
125
146
|
|
126
147
|
rubyforge_project: octopi
|
127
|
-
rubygems_version: 1.3.
|
148
|
+
rubygems_version: 1.3.6
|
128
149
|
signing_key:
|
129
150
|
specification_version: 3
|
130
151
|
summary: A Ruby interface to GitHub API v2 (Devver Fork)
|
131
152
|
test_files:
|
132
153
|
- test/api_test.rb
|
133
154
|
- test/authenticated_test.rb
|
155
|
+
- test/base_test.rb
|
134
156
|
- test/blob_test.rb
|
135
157
|
- test/branch_test.rb
|
136
158
|
- test/commit_test.rb
|
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.
|