githu3 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -2
- data/Gemfile +5 -0
- data/{README.rdoc → README.md} +12 -4
- data/lib/faraday/response/raise_githu3_error.rb +40 -0
- data/lib/githu3/client.rb +34 -14
- data/lib/githu3/error.rb +35 -0
- data/lib/githu3/org.rb +10 -2
- data/lib/githu3/relations.rb +18 -0
- data/lib/githu3/resource.rb +5 -37
- data/lib/githu3/resource_collection.rb +80 -0
- data/lib/githu3/store.rb +16 -0
- data/lib/githu3/team.rb +5 -1
- data/lib/githu3/version.rb +1 -1
- data/lib/githu3.rb +7 -5
- data/spec/fixtures/error.json +1 -0
- data/spec/githu3/client_spec.rb +2 -2
- data/spec/githu3/error_spec.rb +0 -0
- data/spec/githu3/issue_spec.rb +1 -1
- data/spec/githu3/org_spec.rb +4 -4
- data/spec/githu3/resource_collection_spec.rb +64 -0
- data/spec/githu3/team_spec.rb +2 -2
- data/spec/helper.rb +1 -1
- metadata +17 -67
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/{README.rdoc → README.md}
RENAMED
@@ -1,8 +1,16 @@
|
|
1
|
-
|
1
|
+
# githu3 [![Build Status](http://travis-ci.org/sbellity/githu3.png)](http://travis-ci.org/sbellity/githu3)
|
2
2
|
|
3
|
-
Description goes here.
|
4
3
|
|
5
|
-
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
gem install githu3
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
## Contributing to githu3
|
6
14
|
|
7
15
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
16
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
@@ -13,7 +21,7 @@ Description goes here.
|
|
13
21
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
22
|
|
15
23
|
|
16
|
-
|
24
|
+
## Copyright
|
17
25
|
|
18
26
|
Copyright (c) 2011 Stephane Bellity. See LICENSE.txt for
|
19
27
|
further details.
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
# @api private
|
5
|
+
module Faraday
|
6
|
+
class Response::RaiseGithu3Error < Response::Middleware
|
7
|
+
def on_complete(response)
|
8
|
+
case response[:status].to_i
|
9
|
+
when 400
|
10
|
+
raise Githu3::BadRequest, error_message(response)
|
11
|
+
when 401
|
12
|
+
raise Githu3::Unauthorized, error_message(response)
|
13
|
+
when 403
|
14
|
+
raise Githu3::Forbidden, error_message(response)
|
15
|
+
when 404
|
16
|
+
raise Githu3::NotFound, error_message(response)
|
17
|
+
when 406
|
18
|
+
raise Githu3::NotAcceptable, error_message(response)
|
19
|
+
when 422
|
20
|
+
raise Githu3::UnprocessableEntity, error_message(response)
|
21
|
+
when 500
|
22
|
+
raise Githu3::InternalServerError, error_message(response)
|
23
|
+
when 501
|
24
|
+
raise Githu3::NotImplemented, error_message(response)
|
25
|
+
when 502
|
26
|
+
raise Githu3::BadGateway, error_message(response)
|
27
|
+
when 503
|
28
|
+
raise Githu3::ServiceUnavailable, error_message(response)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def error_message(response)
|
33
|
+
if !response[:body].blank?
|
34
|
+
body = ::MultiJson.decode(response[:body])
|
35
|
+
message = body["error"] || body["message"]
|
36
|
+
end
|
37
|
+
"#{response[:method].to_s.upcase} #{response[:url].to_s} [#{response[:status]}]: #{message}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/githu3/client.rb
CHANGED
@@ -1,39 +1,55 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'faraday/response/raise_githu3_error'
|
4
|
+
require 'uri'
|
5
|
+
require 'active_support/core_ext/hash'
|
1
6
|
|
2
7
|
module Githu3
|
3
8
|
|
4
9
|
class Client
|
5
|
-
|
10
|
+
|
11
|
+
BaseUrl = "https://api.github.com"
|
12
|
+
|
6
13
|
attr_reader :conn, :rate_limit
|
7
14
|
|
8
15
|
def initialize(oauth_token=nil)
|
9
16
|
headers = {}
|
10
17
|
headers["Authorization"] = "token #{oauth_token}" if oauth_token
|
11
18
|
@conn = Faraday.new({
|
12
|
-
:url =>
|
19
|
+
:url => Githu3::Client::BaseUrl,
|
13
20
|
:headers => headers
|
14
21
|
})
|
22
|
+
|
15
23
|
@conn.use Faraday::Response::ParseJson
|
24
|
+
@conn.use Faraday::Response::RaiseGithu3Error
|
25
|
+
|
16
26
|
@rate_limit = {}
|
17
27
|
@conn
|
18
28
|
end
|
19
29
|
|
20
30
|
def get *args
|
21
31
|
opts = args.extract_options!
|
32
|
+
uri = URI.parse(args.shift)
|
33
|
+
uri_params = (opts[:params] || {}).stringify_keys
|
34
|
+
unless uri.query.nil?
|
35
|
+
uri_params.merge(uri.query.split("&").inject({}) { |m,p| k,v=p.split("=", 2); m.merge(k => v) } )
|
36
|
+
end
|
37
|
+
args.unshift uri.path
|
22
38
|
res = @conn.get(*args) do |req|
|
39
|
+
req.params = uri_params
|
23
40
|
if opts[:params].is_a?(Hash)
|
24
|
-
req.params ||= {}
|
25
41
|
opts[:params].each { |k,v| req.params[k.to_s] = v.to_s }
|
26
42
|
end
|
27
43
|
end
|
28
44
|
@rate_limit[:limit] = res.headers["x-ratelimit-limit"]
|
29
45
|
@rate_limit[:remaining] = res.headers["x-ratelimit-remaining"]
|
30
|
-
res
|
46
|
+
res
|
31
47
|
end
|
32
48
|
|
33
49
|
# Top level resources...
|
34
50
|
%w{ org repo team user }.each do |r|
|
35
51
|
define_method r do |ident|
|
36
|
-
Githu3.const_get(r.camelize).new(get("/#{r.pluralize}/#{ident}"), self)
|
52
|
+
Githu3.const_get(r.camelize).new(get("/#{r.pluralize}/#{ident}").body, self)
|
37
53
|
end
|
38
54
|
end
|
39
55
|
|
@@ -43,24 +59,28 @@ module Githu3
|
|
43
59
|
Githu3::User.new "/user", self
|
44
60
|
end
|
45
61
|
|
46
|
-
def orgs
|
47
|
-
|
62
|
+
def orgs params={}
|
63
|
+
Githu3::ResourceCollection.new(self, Githu3::Org, "/user/orgs", params)
|
48
64
|
end
|
49
65
|
|
50
|
-
def repos
|
51
|
-
|
66
|
+
def repos params={}
|
67
|
+
Githu3::ResourceCollection.new(self, Githu3::Repo, "/user/repos", params)
|
52
68
|
end
|
53
69
|
|
54
|
-
def followers
|
55
|
-
|
70
|
+
def followers params={}
|
71
|
+
Githu3::ResourceCollection.new(self, Githu3::User, "/user/followers", params)
|
56
72
|
end
|
57
73
|
|
58
|
-
def following
|
59
|
-
|
74
|
+
def following params={}
|
75
|
+
Githu3::ResourceCollection.new(self, Githu3::User, "/user/following", params)
|
60
76
|
end
|
61
77
|
|
62
78
|
def following?(other_user)
|
63
|
-
|
79
|
+
begin
|
80
|
+
get("/user/following/#{other_user}").status == 204
|
81
|
+
rescue Githu3::NotFound
|
82
|
+
false
|
83
|
+
end
|
64
84
|
end
|
65
85
|
|
66
86
|
end
|
data/lib/githu3/error.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Shamelessly stealed from Octokit
|
2
|
+
module Githu3
|
3
|
+
# Custom error class for rescuing from all GitHub errors
|
4
|
+
class Error < StandardError; end
|
5
|
+
|
6
|
+
# Raised when GitHub returns a 400 HTTP status code
|
7
|
+
class BadRequest < Error; end
|
8
|
+
|
9
|
+
# Raised when GitHub returns a 401 HTTP status code
|
10
|
+
class Unauthorized < Error; end
|
11
|
+
|
12
|
+
# Raised when GitHub returns a 403 HTTP status code
|
13
|
+
class Forbidden < Error; end
|
14
|
+
|
15
|
+
# Raised when GitHub returns a 404 HTTP status code
|
16
|
+
class NotFound < Error; end
|
17
|
+
|
18
|
+
# Raised when GitHub returns a 406 HTTP status code
|
19
|
+
class NotAcceptable < Error; end
|
20
|
+
|
21
|
+
# Raised when GitHub returns a 422 HTTP status code
|
22
|
+
class UnprocessableEntity < Error; end
|
23
|
+
|
24
|
+
# Raised when GitHub returns a 500 HTTP status code
|
25
|
+
class InternalServerError < Error; end
|
26
|
+
|
27
|
+
# Raised when GitHub returns a 501 HTTP status code
|
28
|
+
class NotImplemented < Error; end
|
29
|
+
|
30
|
+
# Raised when GitHub returns a 502 HTTP status code
|
31
|
+
class BadGateway < Error; end
|
32
|
+
|
33
|
+
# Raised when GitHub returns a 503 HTTP status code
|
34
|
+
class ServiceUnavailable < Error; end
|
35
|
+
end
|
data/lib/githu3/org.rb
CHANGED
@@ -9,11 +9,19 @@ module Githu3
|
|
9
9
|
has_many :public_members, :class_name => :user
|
10
10
|
|
11
11
|
def member?(user_login)
|
12
|
-
|
12
|
+
begin
|
13
|
+
_client.conn.get("/orgs/#{login}/members/#{user_login}").status == 204
|
14
|
+
rescue Githu3::NotFound
|
15
|
+
false
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
def public_member?(user_login)
|
16
|
-
|
20
|
+
begin
|
21
|
+
_client.conn.get("/orgs/#{login}/public_members/#{user_login}").status == 204
|
22
|
+
rescue Githu3::NotFound
|
23
|
+
false
|
24
|
+
end
|
17
25
|
end
|
18
26
|
|
19
27
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Githu3
|
2
|
+
|
3
|
+
module Relations
|
4
|
+
def has_many m, opts={}
|
5
|
+
opts[:class_name] ||= m.to_s.singularize
|
6
|
+
define_method(m) do |*args|
|
7
|
+
params = args.extract_options!
|
8
|
+
klass = Githu3.const_get(opts[:class_name].to_s.camelize)
|
9
|
+
_resource_path = [opts[:nested_in], m].compact.join("/")
|
10
|
+
if args.length == 1
|
11
|
+
klass.new([path, _resource_path, args.first].join("/"), @client)
|
12
|
+
else
|
13
|
+
Githu3::ResourceCollection.new(@client, klass, [path, _resource_path].join("/"), params)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/githu3/resource.rb
CHANGED
@@ -1,54 +1,22 @@
|
|
1
1
|
module Githu3
|
2
|
-
|
3
|
-
module Relations
|
4
|
-
|
5
|
-
def has_many m, opts={}
|
6
|
-
opts[:class_name] ||= m.to_s.singularize
|
7
|
-
define_method(m) do |*args|
|
8
|
-
params = args.extract_options!
|
9
|
-
klass = Githu3.const_get(opts[:class_name].to_s.camelize)
|
10
|
-
_resource_path = [opts[:nested_in], m].compact.join("/")
|
11
|
-
if args.length == 1
|
12
|
-
klass.new([path, _resource_path, args.first].join("/"), @client)
|
13
|
-
else
|
14
|
-
get([path, _resource_path].join("/"), :params => params).map { |o| klass.new(o, @client) }
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
2
|
|
20
|
-
class Store
|
21
|
-
|
22
|
-
attr_reader :id
|
23
|
-
|
24
|
-
def initialize data
|
25
|
-
@id = data[:id] || data["id"]
|
26
|
-
@attributes = OpenStruct.new(data)
|
27
|
-
end
|
28
|
-
|
29
|
-
def method_missing m, *args
|
30
|
-
@attributes.send m, *args
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
class Resource < Store
|
3
|
+
class Resource < Githu3::Store
|
36
4
|
|
37
5
|
extend Githu3::Relations
|
38
|
-
|
6
|
+
|
39
7
|
def initialize(d, client)
|
40
8
|
@client = client
|
41
9
|
if d.is_a?(String)
|
42
|
-
super(client.get(d))
|
10
|
+
super(client.get(d).body)
|
43
11
|
else
|
44
12
|
super(d)
|
45
13
|
end
|
46
14
|
end
|
47
|
-
|
15
|
+
|
48
16
|
def get *args
|
49
17
|
@client.get(*args)
|
50
18
|
end
|
51
|
-
|
19
|
+
|
52
20
|
def path
|
53
21
|
return if url.nil?
|
54
22
|
URI.parse(url).path
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module Githu3
|
4
|
+
class ResourceCollection
|
5
|
+
|
6
|
+
include Enumerable
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def_delegators :@resources, :each, :map, :<<, :length, :sort_by, :select, :detect, :find, :collect
|
10
|
+
|
11
|
+
attr_reader :url, :fetch_error, :pagination
|
12
|
+
|
13
|
+
def initialize client, resource_klass, url, params={}, opts={}
|
14
|
+
@resource_klass = resource_klass
|
15
|
+
@url = url
|
16
|
+
@params = params
|
17
|
+
@client = client
|
18
|
+
@params = params.stringify_keys
|
19
|
+
@pagination = {}
|
20
|
+
@current_page = (@params["page"] || 1).to_i
|
21
|
+
@resources = []
|
22
|
+
@fetch_error = false
|
23
|
+
fetch
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def fetch(page=nil)
|
28
|
+
begin
|
29
|
+
params = @params.dup.stringify_keys
|
30
|
+
params["page"] = page unless page.nil?
|
31
|
+
res = @client.get(@url, :params => params)
|
32
|
+
update_pagination(res, params)
|
33
|
+
fetched_resources = []
|
34
|
+
res.body.map do |r|
|
35
|
+
resource = @resource_klass.new(r, @client)
|
36
|
+
fetched_resources << resource
|
37
|
+
@resources << resource unless @resources.include?(resource)
|
38
|
+
end if res.body.is_a?(Array)
|
39
|
+
fetched_resources
|
40
|
+
rescue => err
|
41
|
+
@fetch_error = err
|
42
|
+
raise err
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def update_pagination(res, params)
|
47
|
+
@pagination = parse_link_header(res.headers['link'])
|
48
|
+
@current_page = params["page"].to_i
|
49
|
+
end
|
50
|
+
|
51
|
+
def fetch_next
|
52
|
+
return [] unless @pagination["next"]
|
53
|
+
fetch(@pagination["next"])
|
54
|
+
end
|
55
|
+
|
56
|
+
def fetch_prev
|
57
|
+
return [] unless @pagination["prev"]
|
58
|
+
fetch(@pagination["prev"])
|
59
|
+
end
|
60
|
+
|
61
|
+
def fetch_last
|
62
|
+
return false unless @pagination["last"]
|
63
|
+
fetch(@pagination["last"])
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def parse_link_header src
|
68
|
+
return {} if src.nil?
|
69
|
+
links = src.scan(/<http[^<]+/i)
|
70
|
+
return [] if links.nil?
|
71
|
+
links.inject({}) do |ll,l|
|
72
|
+
m = /<(.*)>;(.*)rel=["|']([^"']*)["|'](.*)/i.match(l)
|
73
|
+
uri = URI.parse(m[1])
|
74
|
+
query = uri.query.split("&").inject({}) { |q,a| k,v=a.split("="); q.merge(k => v.to_i) }
|
75
|
+
ll.merge(m[3] => query["page"])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
data/lib/githu3/store.rb
ADDED
data/lib/githu3/team.rb
CHANGED
@@ -6,7 +6,11 @@ module Githu3
|
|
6
6
|
has_many :repos
|
7
7
|
|
8
8
|
def member?(user_login)
|
9
|
-
|
9
|
+
begin
|
10
|
+
_client.conn.get("/teams/#{id}/members/#{user_login}").status == 204
|
11
|
+
rescue Githu3::NotFound
|
12
|
+
false
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
end
|
data/lib/githu3/version.rb
CHANGED
data/lib/githu3.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'ostruct'
|
2
|
-
require 'faraday'
|
3
|
-
require 'faraday_middleware'
|
4
2
|
require "uri"
|
5
3
|
require 'active_support'
|
6
4
|
require 'githu3/version'
|
@@ -10,12 +8,16 @@ require 'active_support/core_ext/string/inflections'
|
|
10
8
|
require 'active_support/inflections'
|
11
9
|
|
12
10
|
module Githu3
|
11
|
+
|
12
|
+
require 'githu3/error'
|
13
|
+
require 'githu3/store'
|
14
|
+
require 'githu3/relations'
|
15
|
+
require 'githu3/resource'
|
16
|
+
require 'githu3/resource_collection'
|
17
|
+
require 'githu3/client'
|
13
18
|
|
14
19
|
Resources = %w{ issue org team user tag branch repo key event comment label milestone }
|
15
20
|
|
16
|
-
autoload :Resource, 'githu3/resource'
|
17
|
-
autoload :Client, 'githu3/client'
|
18
|
-
|
19
21
|
Resources.each do |r|
|
20
22
|
autoload r.camelize.to_sym, "githu3/#{r}"
|
21
23
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"message":"You just hit a wall"}
|
data/spec/githu3/client_spec.rb
CHANGED
@@ -42,12 +42,12 @@ describe Githu3::Client do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should tell me if i am following someone else...' do
|
45
|
-
stub_request(:get, "
|
45
|
+
stub_request(:get, "#{Githu3::Client::BaseUrl}/user/following/billevans").to_return(:status => 204)
|
46
46
|
@client.following?('billevans').should be_true
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'should tell me if i am NOT following someone else...' do
|
50
|
-
stub_request(:get, "
|
50
|
+
stub_request(:get, "#{Githu3::Client::BaseUrl}/user/following/mildesdavis").to_return(:status => 404)
|
51
51
|
@client.following?('mildesdavis').should be_false
|
52
52
|
end
|
53
53
|
|
File without changes
|
data/spec/githu3/issue_spec.rb
CHANGED
data/spec/githu3/org_spec.rb
CHANGED
@@ -24,12 +24,12 @@ describe Githu3::Org do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should tell me if a user IS a member of the team' do
|
27
|
-
stub_request(:get, "
|
27
|
+
stub_request(:get, "#{Githu3::Client::BaseUrl}/orgs/github/members/octocat").to_return(:status => 204)
|
28
28
|
github.member?('octocat').should be_true
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'should tell me if a user IS NOT a member of the org' do
|
32
|
-
stub_request(:get, "
|
32
|
+
stub_request(:get, "#{Githu3::Client::BaseUrl}/orgs/github/members/billevans").to_return(:status => 404)
|
33
33
|
github.member?('billevans').should be_false
|
34
34
|
end
|
35
35
|
|
@@ -50,12 +50,12 @@ describe Githu3::Org do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'should tell me if a user IS a public_member of the team' do
|
53
|
-
stub_request(:get, "
|
53
|
+
stub_request(:get, "#{Githu3::Client::BaseUrl}/orgs/github/public_members/octocat").to_return(:status => 204)
|
54
54
|
github.public_member?('octocat').should be_true
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'should tell me if a user IS NOT a public_member of the team' do
|
58
|
-
stub_request(:get, "
|
58
|
+
stub_request(:get, "#{Githu3::Client::BaseUrl}/orgs/github/public_members/billevans").to_return(:status => 404)
|
59
59
|
github.public_member?('billevans').should be_false
|
60
60
|
end
|
61
61
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Githu3::ResourceCollection do
|
4
|
+
|
5
|
+
def collection
|
6
|
+
stub_get "/user/orgs", "orgs"
|
7
|
+
Githu3::ResourceCollection.new(@client, Githu3::Org, "/user/orgs")
|
8
|
+
end
|
9
|
+
|
10
|
+
before do
|
11
|
+
@client = Githu3::Client.new("myvalidtoken")
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "Enumerable behaviour" do
|
15
|
+
|
16
|
+
it "sould forward enumerable methods to @resource" do
|
17
|
+
collection.length.should == 2
|
18
|
+
collection.map { |o| o.login }.sort.should == ['nuvoli', 'sixdegrees']
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "Pagination" do
|
24
|
+
|
25
|
+
it "should paginate correctly" do
|
26
|
+
stub_get "/user/repos?type=public", "public_repos"
|
27
|
+
public_repos = Githu3::ResourceCollection.new(@client, Githu3::Org, "/user/repos", :type => "public")
|
28
|
+
public_repos.length.should == 5
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should set pagination options correctly" do
|
32
|
+
stub_get "/user/repos?per_page=5&type=public", "public_repos"
|
33
|
+
paginated = Githu3::ResourceCollection.new(@client, Githu3::Org, "/user/repos", :type => "public", :per_page => 5)
|
34
|
+
paginated.length.should == 5
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should correctly set pagination info" do
|
38
|
+
link_header = <<-EOL
|
39
|
+
<https://api.github.com/resource?page=2>; rel="next",
|
40
|
+
<https://api.github.com/resource?page=5>; rel="last"
|
41
|
+
EOL
|
42
|
+
|
43
|
+
stub_request(:get, "https://api.github.com/user/repos?page=1&per_page=5&type=public").
|
44
|
+
to_return(:headers => { "Link" => link_header })
|
45
|
+
|
46
|
+
paginated = Githu3::ResourceCollection.new(@client, Githu3::Org, "/user/repos", :type => "public", :per_page => 5, :page => 1)
|
47
|
+
paginated.pagination["next"].should == 2
|
48
|
+
paginated.pagination["last"].should == 5
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "Error Handling" do
|
54
|
+
|
55
|
+
it "should record an error... it one occurs" do
|
56
|
+
stub_request(:get, "#{Githu3::Client::BaseUrl}/user/repos").to_return(:status => 401, :body => fixture('error.json'))
|
57
|
+
lambda {
|
58
|
+
Githu3::ResourceCollection.new(@client, Githu3::Org, "/user/repos")
|
59
|
+
}.should raise_error(Githu3::Unauthorized)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
data/spec/githu3/team_spec.rb
CHANGED
@@ -25,12 +25,12 @@ describe Githu3::Team do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'should tell me if a user IS a member of the team' do
|
28
|
-
stub_request(:get, "
|
28
|
+
stub_request(:get, "#{Githu3::Client::BaseUrl}/teams/1/members/octocat").to_return(:status => 204)
|
29
29
|
team.member?('octocat').should be_true
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'should tell me if a user IS NOT a member of the team' do
|
33
|
-
stub_request(:get, "
|
33
|
+
stub_request(:get, "#{Githu3::Client::BaseUrl}/teams/1/members/billevans").to_return(:status => 404)
|
34
34
|
team.member?('billevans').should be_false
|
35
35
|
end
|
36
36
|
end
|
data/spec/helper.rb
CHANGED
@@ -15,7 +15,7 @@ def fixture(file)
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def stub_get url, fixture_name, headers={ 'Authorization'=>'token myvalidtoken' }
|
18
|
-
stub_request(:get, "
|
18
|
+
stub_request(:get, "#{Githu3::Client::BaseUrl}#{url}").
|
19
19
|
with(:headers => headers).
|
20
20
|
to_return(:status => 200, :body => fixture("#{fixture_name}.json"))
|
21
21
|
end
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: githu3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 27
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 2
|
10
|
-
version: 0.0.2
|
5
|
+
version: 0.0.3
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Stephane Bellity
|
@@ -15,7 +10,8 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-27 00:00:00 +02:00
|
14
|
+
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
21
17
|
name: activesupport
|
@@ -25,11 +21,6 @@ dependencies:
|
|
25
21
|
requirements:
|
26
22
|
- - ~>
|
27
23
|
- !ruby/object:Gem::Version
|
28
|
-
hash: 7
|
29
|
-
segments:
|
30
|
-
- 3
|
31
|
-
- 0
|
32
|
-
- 0
|
33
24
|
version: 3.0.0
|
34
25
|
type: :runtime
|
35
26
|
version_requirements: *id001
|
@@ -41,11 +32,6 @@ dependencies:
|
|
41
32
|
requirements:
|
42
33
|
- - ~>
|
43
34
|
- !ruby/object:Gem::Version
|
44
|
-
hash: 11
|
45
|
-
segments:
|
46
|
-
- 0
|
47
|
-
- 5
|
48
|
-
- 0
|
49
35
|
version: 0.5.0
|
50
36
|
type: :runtime
|
51
37
|
version_requirements: *id002
|
@@ -57,11 +43,6 @@ dependencies:
|
|
57
43
|
requirements:
|
58
44
|
- - ~>
|
59
45
|
- !ruby/object:Gem::Version
|
60
|
-
hash: 7
|
61
|
-
segments:
|
62
|
-
- 0
|
63
|
-
- 6
|
64
|
-
- 0
|
65
46
|
version: 0.6.0
|
66
47
|
type: :runtime
|
67
48
|
version_requirements: *id003
|
@@ -73,11 +54,6 @@ dependencies:
|
|
73
54
|
requirements:
|
74
55
|
- - ~>
|
75
56
|
- !ruby/object:Gem::Version
|
76
|
-
hash: 7
|
77
|
-
segments:
|
78
|
-
- 0
|
79
|
-
- 6
|
80
|
-
- 0
|
81
57
|
version: 0.6.0
|
82
58
|
type: :runtime
|
83
59
|
version_requirements: *id004
|
@@ -89,11 +65,6 @@ dependencies:
|
|
89
65
|
requirements:
|
90
66
|
- - ~>
|
91
67
|
- !ruby/object:Gem::Version
|
92
|
-
hash: 19
|
93
|
-
segments:
|
94
|
-
- 1
|
95
|
-
- 0
|
96
|
-
- 2
|
97
68
|
version: 1.0.2
|
98
69
|
type: :runtime
|
99
70
|
version_requirements: *id005
|
@@ -105,10 +76,6 @@ dependencies:
|
|
105
76
|
requirements:
|
106
77
|
- - ~>
|
107
78
|
- !ruby/object:Gem::Version
|
108
|
-
hash: 17
|
109
|
-
segments:
|
110
|
-
- 4
|
111
|
-
- 5
|
112
79
|
version: "4.5"
|
113
80
|
type: :development
|
114
81
|
version_requirements: *id006
|
@@ -120,10 +87,6 @@ dependencies:
|
|
120
87
|
requirements:
|
121
88
|
- - ~>
|
122
89
|
- !ruby/object:Gem::Version
|
123
|
-
hash: 25
|
124
|
-
segments:
|
125
|
-
- 0
|
126
|
-
- 9
|
127
90
|
version: "0.9"
|
128
91
|
type: :development
|
129
92
|
version_requirements: *id007
|
@@ -135,10 +98,6 @@ dependencies:
|
|
135
98
|
requirements:
|
136
99
|
- - ~>
|
137
100
|
- !ruby/object:Gem::Version
|
138
|
-
hash: 15
|
139
|
-
segments:
|
140
|
-
- 2
|
141
|
-
- 6
|
142
101
|
version: "2.6"
|
143
102
|
type: :development
|
144
103
|
version_requirements: *id008
|
@@ -150,10 +109,6 @@ dependencies:
|
|
150
109
|
requirements:
|
151
110
|
- - ~>
|
152
111
|
- !ruby/object:Gem::Version
|
153
|
-
hash: 3
|
154
|
-
segments:
|
155
|
-
- 0
|
156
|
-
- 4
|
157
112
|
version: "0.4"
|
158
113
|
type: :development
|
159
114
|
version_requirements: *id009
|
@@ -165,10 +120,6 @@ dependencies:
|
|
165
120
|
requirements:
|
166
121
|
- - ~>
|
167
122
|
- !ruby/object:Gem::Version
|
168
|
-
hash: 3
|
169
|
-
segments:
|
170
|
-
- 1
|
171
|
-
- 6
|
172
123
|
version: "1.6"
|
173
124
|
type: :development
|
174
125
|
version_requirements: *id010
|
@@ -180,10 +131,6 @@ dependencies:
|
|
180
131
|
requirements:
|
181
132
|
- - ~>
|
182
133
|
- !ruby/object:Gem::Version
|
183
|
-
hash: 27
|
184
|
-
segments:
|
185
|
-
- 0
|
186
|
-
- 8
|
187
134
|
version: "0.8"
|
188
135
|
type: :development
|
189
136
|
version_requirements: *id011
|
@@ -204,26 +151,32 @@ files:
|
|
204
151
|
- .travis.yml
|
205
152
|
- Gemfile
|
206
153
|
- LICENSE.txt
|
207
|
-
- README.
|
154
|
+
- README.md
|
208
155
|
- Rakefile
|
209
156
|
- githu3.gemspec
|
157
|
+
- lib/faraday/response/raise_githu3_error.rb
|
210
158
|
- lib/githu3.rb
|
211
159
|
- lib/githu3/branch.rb
|
212
160
|
- lib/githu3/client.rb
|
213
161
|
- lib/githu3/comment.rb
|
162
|
+
- lib/githu3/error.rb
|
214
163
|
- lib/githu3/event.rb
|
215
164
|
- lib/githu3/issue.rb
|
216
165
|
- lib/githu3/key.rb
|
217
166
|
- lib/githu3/label.rb
|
218
167
|
- lib/githu3/milestone.rb
|
219
168
|
- lib/githu3/org.rb
|
169
|
+
- lib/githu3/relations.rb
|
220
170
|
- lib/githu3/repo.rb
|
221
171
|
- lib/githu3/resource.rb
|
172
|
+
- lib/githu3/resource_collection.rb
|
173
|
+
- lib/githu3/store.rb
|
222
174
|
- lib/githu3/tag.rb
|
223
175
|
- lib/githu3/team.rb
|
224
176
|
- lib/githu3/user.rb
|
225
177
|
- lib/githu3/version.rb
|
226
178
|
- spec/fixtures/all_repos.json
|
179
|
+
- spec/fixtures/error.json
|
227
180
|
- spec/fixtures/issues/comments.json
|
228
181
|
- spec/fixtures/issues/event.json
|
229
182
|
- spec/fixtures/issues/events.json
|
@@ -252,13 +205,16 @@ files:
|
|
252
205
|
- spec/fixtures/users/repos.json
|
253
206
|
- spec/fixtures/users/sbellity.json
|
254
207
|
- spec/githu3/client_spec.rb
|
208
|
+
- spec/githu3/error_spec.rb
|
255
209
|
- spec/githu3/issue_spec.rb
|
256
210
|
- spec/githu3/org_spec.rb
|
257
211
|
- spec/githu3/repo_spec.rb
|
212
|
+
- spec/githu3/resource_collection_spec.rb
|
258
213
|
- spec/githu3/team_spec.rb
|
259
214
|
- spec/githu3/user_spec.rb
|
260
215
|
- spec/githu3_spec.rb
|
261
216
|
- spec/helper.rb
|
217
|
+
has_rdoc: true
|
262
218
|
homepage: https://github.com/sbellity/githu3
|
263
219
|
licenses: []
|
264
220
|
|
@@ -272,30 +228,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
272
228
|
requirements:
|
273
229
|
- - ">="
|
274
230
|
- !ruby/object:Gem::Version
|
275
|
-
hash: 3
|
276
|
-
segments:
|
277
|
-
- 0
|
278
231
|
version: "0"
|
279
232
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
280
233
|
none: false
|
281
234
|
requirements:
|
282
235
|
- - ">="
|
283
236
|
- !ruby/object:Gem::Version
|
284
|
-
hash: 23
|
285
|
-
segments:
|
286
|
-
- 1
|
287
|
-
- 3
|
288
|
-
- 6
|
289
237
|
version: 1.3.6
|
290
238
|
requirements: []
|
291
239
|
|
292
240
|
rubyforge_project:
|
293
|
-
rubygems_version: 1.
|
241
|
+
rubygems_version: 1.6.2
|
294
242
|
signing_key:
|
295
243
|
specification_version: 3
|
296
244
|
summary: Ruby wrapper for the GitHub's v3' API
|
297
245
|
test_files:
|
298
246
|
- spec/fixtures/all_repos.json
|
247
|
+
- spec/fixtures/error.json
|
299
248
|
- spec/fixtures/issues/comments.json
|
300
249
|
- spec/fixtures/issues/event.json
|
301
250
|
- spec/fixtures/issues/events.json
|
@@ -324,11 +273,12 @@ test_files:
|
|
324
273
|
- spec/fixtures/users/repos.json
|
325
274
|
- spec/fixtures/users/sbellity.json
|
326
275
|
- spec/githu3/client_spec.rb
|
276
|
+
- spec/githu3/error_spec.rb
|
327
277
|
- spec/githu3/issue_spec.rb
|
328
278
|
- spec/githu3/org_spec.rb
|
329
279
|
- spec/githu3/repo_spec.rb
|
280
|
+
- spec/githu3/resource_collection_spec.rb
|
330
281
|
- spec/githu3/team_spec.rb
|
331
282
|
- spec/githu3/user_spec.rb
|
332
283
|
- spec/githu3_spec.rb
|
333
284
|
- spec/helper.rb
|
334
|
-
has_rdoc:
|