fcoury-octopi 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +13 -9
  2. data/VERSION.yml +1 -1
  3. data/lib/octopi.rb +80 -19
  4. metadata +3 -12
data/README.rdoc CHANGED
@@ -4,8 +4,6 @@ Octopi is a Ruby interface to GitHub API v2 (http://develop.github.com). It's un
4
4
 
5
5
  == Example
6
6
 
7
- require 'octopi'
8
-
9
7
  include Octopi
10
8
 
11
9
  # user information
@@ -27,9 +25,19 @@ Octopi is a Ruby interface to GitHub API v2 (http://develop.github.com). It's un
27
25
  end
28
26
 
29
27
  # repository information
30
- repo = Repository.find("fcoury", "octopi")
28
+ # to get all repos for user: user.repositories
29
+ repo = user.repository("octopi") # same as: Repository.find("fcoury", "octopi")
31
30
  puts "Repository: #{repo.name} - #{repo.description} (by #{repo.owner}) - #{repo.url}"
32
31
 
32
+ # commits of a the repository
33
+ first_commit = repo.commits.first
34
+ puts "First commit: #{first_commit.id} - #{first_commit.message} - by #{first_commit.author['name']}"
35
+
36
+ # single commit information
37
+ # details is the same as: Commit.find(commit)
38
+ puts "Diff:"
39
+ first_commit.details.modified.each {|m| puts "#{m['filename']} DIFF: #{m['diff']}" }
40
+
33
41
  # repository search
34
42
  repos = Repository.find_all("ruby", "git")
35
43
  puts "#{repos.size} repository(ies) with 'ruby' and 'git':"
@@ -37,17 +45,13 @@ Octopi is a Ruby interface to GitHub API v2 (http://develop.github.com). It's un
37
45
  puts " - #{r.name}"
38
46
  end
39
47
 
40
- # connect "user", "<<token>>" do |github|
41
- # puts github.user.name
42
- # end
43
-
44
48
  == Author
45
49
 
46
- Felipe Coury - http://felipecoury.com
50
+ Felipe Coury - http://felipecoury.com<br/>
47
51
  HasMany.info blog - http://hasmany.info
48
52
 
49
53
  == Copyright
50
54
 
51
- DISCLAIMER: The name of this library is pronounced _octo-pie_ but no Octocats were harmed during its creation. It's not really an Octo Pie, but a contraction of the words Octocat and API.
55
+ DISCLAIMER: The name of this library is pronounced <i>octo-pie</i> but no Octocats were harmed during its creation. It's not really an Octo Pie, but a contraction of the words Octocat and API.
52
56
 
53
57
  Copyright (c) 2009 Felipe Coury. See LICENSE for details.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 0
3
- :patch: 2
3
+ :patch: 3
4
4
  :major: 0
data/lib/octopi.rb CHANGED
@@ -44,7 +44,7 @@ module Octopi
44
44
  end
45
45
 
46
46
  def find_all(path, result_key, query)
47
- get(path, { :query => query })[result_key]
47
+ get(path, { :query => query, :id => query })[result_key]
48
48
  end
49
49
 
50
50
  private
@@ -53,7 +53,7 @@ module Octopi
53
53
  path = path.gsub(":#{k.to_s}", v)
54
54
  end
55
55
  # puts "GET: /#{format}#{path}"
56
- self.class.get("/#{format}#{path}")
56
+ self.class.get("/#{format}#{path}")
57
57
  end
58
58
  end
59
59
 
@@ -130,14 +130,18 @@ module Octopi
130
130
  end
131
131
 
132
132
  def find_all(s)
133
+ find_plural(s, :find)
134
+ end
135
+
136
+ def find_plural(s,path)
133
137
  all = []
134
- result = ANONYMOUS_API.find_all(path_for(:find), @resource_name[:plural], s)
138
+ result = ANONYMOUS_API.find_all(path_for(path), @resource_name[:plural], s)
135
139
  result.each do |item|
136
140
  all << new(ANONYMOUS_API, item)
137
141
  end
138
142
  all
139
143
  end
140
-
144
+
141
145
  def path_for(type)
142
146
  @path_spec[type]
143
147
  end
@@ -150,15 +154,12 @@ module Octopi
150
154
  find_path "/user/search/:query"
151
155
  resource_path "/user/show/:id"
152
156
 
153
- def user_property(property, deep)
154
- users = []
155
- property(property, login).each_pair do |k,v|
156
- return v unless deep
157
-
158
- v.each { |u| users << User.find(u) }
159
- end
160
-
161
- users
157
+ def repositories
158
+ Repository.find_by_user(login)
159
+ end
160
+
161
+ def repository(name)
162
+ Repository.find(login, name)
162
163
  end
163
164
 
164
165
  # takes one param, deep that indicates if returns
@@ -171,21 +172,81 @@ module Octopi
171
172
  user_property(method, true)
172
173
  end
173
174
  end
175
+
176
+ def user_property(property, deep)
177
+ users = []
178
+ property(property, login).each_pair do |k,v|
179
+ return v unless deep
180
+
181
+ v.each { |u| users << User.find(u) }
182
+ end
183
+
184
+ users
185
+ end
174
186
  end
175
187
 
176
188
  class Repository < Base
177
189
  include Resource
178
190
  set_resource_name "repository", "repositories"
179
-
191
+
192
+ find_path "/repos/search/:query"
193
+ resource_path "/repos/show/:id"
194
+
195
+ def self.find_by_user(user)
196
+ find_plural(user, :resource)
197
+ end
198
+
180
199
  def self.find(user, name)
181
200
  super "#{user}/#{name}"
182
201
  end
183
-
202
+
184
203
  def self.find_all(*args)
185
204
  super args.join("+")
186
205
  end
187
-
188
- find_path "/repos/search/:query"
189
- resource_path "/repos/show/:id"
206
+
207
+ def commits(branch = "master")
208
+ Commit.find_all(owner, name, branch, self)
209
+ end
210
+ end
211
+
212
+ class Commit < Base
213
+ include Resource
214
+ find_path "/commits/list/:query"
215
+ resource_path "/commits/show/:id"
216
+
217
+ attr_accessor :repository
218
+
219
+ def self.find_all(user, name, branch = "master", repo = nil)
220
+ commits = super("#{user}/#{name}/#{branch}")
221
+ commits.each { |c| c.repository = repo } if repo
222
+ commits
223
+ end
224
+
225
+ def self.find(*args)
226
+ if args.last.is_a?(Commit)
227
+ commit = args.pop
228
+ super "#{commit.repo_identifier}"
229
+ else
230
+ user, name, sha = *args
231
+ super "#{user}/#{name}/#{sha}"
232
+ end
233
+ end
234
+
235
+ def details
236
+ self.class.find(self)
237
+ end
238
+
239
+ def repo_identifier
240
+ url_parts = url.split('/')
241
+ if @repository
242
+ parts = [@repository.owner, @repository.name, url_parts[6]]
243
+ else
244
+ parts = [url_parts[3], url_parts[4], url_parts[6]]
245
+ end
246
+
247
+ puts parts.join('/')
248
+ parts.join('/')
249
+ end
190
250
  end
191
- end
251
+ class APIError < StandardError; end
252
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fcoury-octopi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Coury
@@ -11,17 +11,8 @@ cert_chain: []
11
11
 
12
12
  date: 2009-04-19 00:00:00 -07:00
13
13
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: httparty
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 0.4.2
24
- version:
14
+ dependencies: []
15
+
25
16
  description:
26
17
  email: felipe.coury@gmail.com
27
18
  executables: []