Skip to content
Browse files

issues and labels added

  • Loading branch information...
1 parent 6719088 commit 041db89357fa47c80c67e8de72c86028071488eb @martinciu committed Apr 3, 2012
Showing with 87 additions and 7 deletions.
  1. +3 −1 bin/issues
  2. +2 −0 lib/issues.rb
  3. +1 −0 lib/issues/github.rb
  4. +17 −6 lib/issues/github/resource.rb
  5. +36 −0 lib/issues/github/response.rb
  6. +21 −0 lib/issues/issue.rb
  7. +7 −0 lib/issues/label.rb
View
4 bin/issues
@@ -54,7 +54,9 @@ command :list do |c|
c.flag [:s, :state]
c.action do |global_options,options,args|
- puts '[TODO] Implement Issues List'
+ Issues::Issue.all.each do |issue|
+ p issue
+ end
end
end
View
2 lib/issues.rb
@@ -8,6 +8,8 @@
require 'issues/user'
require 'issues/repo'
require 'issues/milestone'
+require 'issues/label'
+require 'issues/issue'
module Issues
View
1 lib/issues/github.rb
@@ -1,4 +1,5 @@
require 'issues/github/connection'
+require 'issues/github/response'
require 'issues/github/resource'
module Issues
View
23 lib/issues/github/resource.rb
@@ -12,20 +12,31 @@ def repo
module ClassMethods
def all
- JSON.parse(github.get(all_url).body).map { |attributes| new(attributes) }
+ fetch_all.map { |attributes| new(attributes) }
end
def repo
Issues.repo
end
- def github
- Github.connection
- end
-
protected
def all_url
- "/repos/#{repo}/#{resources}"
+ "/repos/#{repo}/#{resources}?per_page=100"
+ end
+
+ def get(url)
+ Issues::Github::Response.new Github.connection.get(url)
+ end
+
+ def fetch_all
+ url = all_url
+ resources = []
+ begin
+ response = get(url)
+ resources += response.body
+ end while url = response.next_url
+
+ resources
end
def resource
View
36 lib/issues/github/response.rb
@@ -0,0 +1,36 @@
+module Issues
+ module Github
+ class Response
+ extend Forwardable
+ def_delegators :@response, :headers
+
+ def initialize(response)
+ @response = response
+ end
+
+ def next_url
+ links[:next]
+ end
+
+ def body
+ JSON.parse @response.body
+ end
+
+ private
+ def links
+ link.split(',').inject({}) do |links, link|
+ matches = /\<(.*?)\>; rel=\"(.*?)\"/.match(link.strip)
+ links[matches[2].to_sym] = matches[1] if matches
+ links
+ end
+ end
+
+ def link
+ headers.fetch("link") {""}
+ end
+ end
+ end
+end
+
+
+
View
21 lib/issues/issue.rb
@@ -0,0 +1,21 @@
+module Issues
+ class Issue
+ include Virtus
+ include Github::Resource
+
+ attribute :number, Integer
+ attribute :state, String
+ attribute :assignee, User
+ attribute :milestone, Milestone
+ attribute :title, String
+ attribute :body, String
+ attribute :html_url, String
+ attribute :labels, Set[Label]
+
+ def to_s
+ "##{number} - #{title}"
+ end
+
+ end
+
+end
View
7 lib/issues/label.rb
@@ -0,0 +1,7 @@
+module Issues
+ class Label
+ include Virtus
+
+ attribute :name, String
+ end
+end

0 comments on commit 041db89

Please sign in to comment.
Something went wrong with that request. Please try again.