fcoury-octopi 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,47 +4,55 @@ Octopi is a Ruby interface to GitHub API v2 (http://develop.github.com). It's un
4
4
 
5
5
  == Example
6
6
 
7
- include Octopi
7
+ === Users API
8
+
9
+ Getting user information
8
10
 
9
- # user information
10
11
  user = User.find("fcoury")
11
12
  puts "#{user.name} is being followed by #{user.followers.join(", ")} and following #{user.following.join(", ")}"
12
13
 
13
- # the bang version of followers and following
14
- # fetches user object for each user, but is
15
- # a lot more expensive
14
+ The bang methods `followers!` and `following!` retrieves a full User object for each user login returned, so it has to be used carefully.
15
+
16
16
  user.followers!.each do |u|
17
17
  puts " - #{u.name} (#{u.login}) has #{u.public_repo_count} repo(s)"
18
18
  end
19
+
20
+ Searching for user
19
21
 
20
- # search user
21
22
  users = User.find_all("silva")
22
23
  puts "#{users.size} users found for 'silva':"
23
24
  users.each do |u|
24
25
  puts " - #{u.name}"
25
26
  end
26
27
 
27
- # repository information
28
- # to get all repos for user: user.repositories
28
+ === Repositories API
29
+
29
30
  repo = user.repository("octopi") # same as: Repository.find("fcoury", "octopi")
30
31
  puts "Repository: #{repo.name} - #{repo.description} (by #{repo.owner}) - #{repo.url}"
31
32
  puts " Tags: #{repo.tags and repo.tags.map {|t| t.name}.join(", ")}"
33
+
34
+ Search:
32
35
 
33
- # commits of a the repository
34
- first_commit = repo.commits.first
35
- puts "First commit: #{first_commit.id} - #{first_commit.message} - by #{first_commit.author['name']}"
36
-
37
- # single commit information
38
- # details is the same as: Commit.find(commit)
39
- puts "Diff:"
40
- first_commit.details.modified.each {|m| puts "#{m['filename']} DIFF: #{m['diff']}" }
41
-
42
- # repository search
43
36
  repos = Repository.find_all("ruby", "git")
44
37
  puts "#{repos.size} repository(ies) with 'ruby' and 'git':"
45
38
  repos.each do |r|
46
39
  puts " - #{r.name}"
47
40
  end
41
+
42
+ Issues API integrated into the Repository object:
43
+
44
+ issue = repo.issues.first
45
+ puts "First open issue: #{issue.number} - #{issue.title} - Created at: #{issue.created_at}"
46
+
47
+ Commits API information from a Repository object:
48
+
49
+ first_commit = repo.commits.first
50
+ puts "First commit: #{first_commit.id} - #{first_commit.message} - by #{first_commit.author['name']}"
51
+
52
+ Single commit information:
53
+
54
+ puts "Diff:"
55
+ first_commit.details.modified.each {|m| puts "#{m['filename']} DIFF: #{m['diff']}" }
48
56
 
49
57
  == Author
50
58
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 0
3
- :patch: 4
4
2
  :major: 0
3
+ :minor: 0
4
+ :patch: 5
data/lib/octopi.rb CHANGED
@@ -51,6 +51,7 @@ module Octopi
51
51
  def find_all(path, result_key, query)
52
52
  get(path, { :query => query, :id => query })[result_key]
53
53
  end
54
+
54
55
  def get_raw(path, params)
55
56
  get(path, params, 'plain')
56
57
  end
@@ -75,7 +76,7 @@ module Octopi
75
76
  end
76
77
  end
77
78
 
78
- %w{base resource user tag repository file_object blob commit}.
79
+ %w{base resource user tag repository issue file_object blob commit}.
79
80
  each{|f| require "#{File.dirname(__FILE__)}/octopi/#{f}"}
80
81
 
81
82
  class FormatError < StandardError
data/lib/octopi/base.rb CHANGED
@@ -1,3 +1,4 @@
1
+ module Octopi
1
2
  class Base
2
3
  def initialize(api, hash)
3
4
  @api = api
@@ -24,9 +25,41 @@
24
25
  path = "#{self.class.path_for(:resource)}/#{p}"
25
26
  @api.find(path, self.class.resource_name(:singular), v)
26
27
  end
28
+
27
29
  def save
28
30
  hash = {}
29
31
  @keys.each { |k| hash[k] = send(k) }
30
32
  @api.save(self.path_for(:resource), hash)
31
33
  end
34
+
35
+ private
36
+ def self.extract_user_repository(*args)
37
+ opts = args.last.is_a?(Hash) ? args.pop : {}
38
+ if opts.empty?
39
+ user, repo = *args
40
+ else
41
+ opts[:repo] = opts[:repository] if opts[:repository]
42
+ repo = args.pop || opts[:repo]
43
+ user = opts[:user]
44
+ end
45
+
46
+ user ||= repo.owner if repo.is_a? Repository
47
+
48
+ if repo.is_a?(String) and !user
49
+ raise "Need user argument when repository is identified by name"
50
+ end
51
+
52
+ ret = extract_names(user, repo)
53
+ ret << opts
54
+ ret
55
+ end
56
+
57
+ def self.extract_names(*args)
58
+ args.map do |v|
59
+ v = v.name if v.is_a? Repository
60
+ v = v.login if v.is_a? User
61
+ v
62
+ end
63
+ end
32
64
  end
65
+ end
data/lib/octopi/commit.rb CHANGED
@@ -6,16 +6,32 @@ module Octopi
6
6
 
7
7
  attr_accessor :repository
8
8
 
9
- def self.find_all(user, name, branch = "master", repo = nil)
10
- repository = repo if repo.is_a? Repository
11
- user = user.login if user.is_a? User
12
- repo = repo.name if repo.is_a? Repository
13
- name = repo.name if name.is_a? Repository
14
- commits = super [user, name, branch]
15
- commits.each { |c| c.repository = repository } if repository
9
+ # Finds all commits for a given Repository's branch
10
+ #
11
+ # You can provide the user and repo parameters as
12
+ # String or as User and Repository objects. When repo
13
+ # is provided as a Repository object, user is superfluous.
14
+ #
15
+ # If no branch is given, "master" is assumed.
16
+ #
17
+ # Sample usage:
18
+ #
19
+ # find_all(repo, :branch => "develop") # repo must be an object
20
+ # find_all("octopi", :user => "fcoury") # user must be provided
21
+ # find_all(:user => "fcoury", :repo => "octopi") # branch defaults to master
22
+ #
23
+ def self.find_all(*args)
24
+ repo = args.first
25
+ user ||= repo.owner if repo.is_a? Repository
26
+ user, repo_name, opts = extract_user_repository(*args)
27
+ branch = opts[:branch] || "master"
28
+
29
+ commits = super user, repo_name, branch
30
+ commits.each { |c| c.repository = repo } if repo.is_a? Repository
16
31
  commits
17
32
  end
18
33
 
34
+ # TODO: Make find use hashes like find_all
19
35
  def self.find(*args)
20
36
  if args.last.is_a?(Commit)
21
37
  commit = args.pop
@@ -40,7 +56,6 @@ module Octopi
40
56
  parts = [url_parts[3], url_parts[4], url_parts[6]]
41
57
  end
42
58
 
43
- puts parts.join('/')
44
59
  parts.join('/')
45
60
  end
46
61
  end
@@ -0,0 +1,50 @@
1
+ module Octopi
2
+ class Issue < Base
3
+ include Resource
4
+
5
+ find_path "/issues/list/:query"
6
+ resource_path "/user/show/:id"
7
+
8
+ attr_accessor :repository
9
+
10
+ # Finds all issues for a given Repository
11
+ #
12
+ # You can provide the user and repo parameters as
13
+ # String or as User and Repository objects. When repo
14
+ # is provided as a Repository object, user is superfluous.
15
+ #
16
+ # If no state is given, "open" is assumed.
17
+ #
18
+ # Sample usage:
19
+ #
20
+ # find_all(repo, :state => "closed") # repo must be an object
21
+ # find_all("octopi", :user => "fcoury") # user must be provided
22
+ # find_all(:user => "fcoury", :repo => "octopi") # state defaults to open
23
+ #
24
+ def self.find_all(*args)
25
+ repo = args.first
26
+ user, repo_name, opts = extract_user_repository(*args)
27
+ state = opts[:state] || "open"
28
+ state.downcase! if state
29
+
30
+ raise "State should be either 'open' or 'closed'" unless ['open', 'closed'].include? state
31
+
32
+ issues = super user, repo_name, state
33
+ issues.each { |i| i.repository = repo } if repo.is_a? Repository
34
+ issues
35
+ end
36
+
37
+ # TODO: Make find use hashes like find_all
38
+ def self.find(*args)
39
+ if args.last.is_a?(Issue)
40
+ commit = args.pop
41
+ super "#{issue.number}"
42
+ else
43
+ user, name, number = *args
44
+ user = user.login if user.is_a? User
45
+ name = repo.name if name.is_a? Repository
46
+ super user, name, number
47
+ end
48
+ end
49
+ end
50
+ end
@@ -34,7 +34,11 @@ module Octopi
34
34
  end
35
35
 
36
36
  def commits(branch = "master")
37
- Commit.find_all(owner, name, branch, self)
37
+ Commit.find_all(self, :branch => branch)
38
+ end
39
+
40
+ def issues(state = "open")
41
+ Issue.find_all(self, :state => state)
38
42
  end
39
43
  end
40
44
  end
@@ -20,10 +20,6 @@ module Octopi
20
20
  @resource_name[key]
21
21
  end
22
22
 
23
- def declassify(s)
24
- (s.split('::').last || '').downcase if s
25
- end
26
-
27
23
  def find_path(path)
28
24
  (@path_spec||={})[:find] = path
29
25
  end
@@ -45,11 +41,11 @@ module Octopi
45
41
  end
46
42
  end
47
43
 
48
- def find_all(s)
44
+ def find_all(*s)
49
45
  find_plural(s, :find)
50
46
  end
51
47
 
52
- def find_plural(s,path)
48
+ def find_plural(s, path)
53
49
  s = s.join('/') if s.is_a? Array
54
50
  ANONYMOUS_API.find_all(path_for(path), @resource_name[:plural], s).
55
51
  map do |item|
@@ -58,6 +54,10 @@ module Octopi
58
54
  end
59
55
  end
60
56
 
57
+ def declassify(s)
58
+ (s.split('::').last || '').downcase if s
59
+ end
60
+
61
61
  def path_for(type)
62
62
  @path_spec[type]
63
63
  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.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Coury
@@ -30,6 +30,7 @@ files:
30
30
  - lib/octopi/blob.rb
31
31
  - lib/octopi/commit.rb
32
32
  - lib/octopi/file_object.rb
33
+ - lib/octopi/issue.rb
33
34
  - lib/octopi/repository.rb
34
35
  - lib/octopi/resource.rb
35
36
  - lib/octopi/tag.rb
@@ -63,7 +64,7 @@ requirements: []
63
64
  rubyforge_project:
64
65
  rubygems_version: 1.2.0
65
66
  signing_key:
66
- specification_version: 2
67
+ specification_version: 3
67
68
  summary: A Ruby interface to GitHub API v2
68
69
  test_files: []
69
70