github_api 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -301,6 +301,24 @@ res.next_page
301
301
  res.last_page
302
302
  ```
303
303
 
304
+ ## Error Handling
305
+
306
+ The generic error class `Github::Error::GithubError` will handle both the client(`Github::Error::ClientError`) and service(`Github::Error::ServiceError`) side errors. For instance in your code you can catch erros like
307
+
308
+ ```ruby
309
+ begin
310
+ # Do something with github_api gem
311
+ rescue Github::Error::GithubError => e
312
+ puts e.message
313
+
314
+ if e.is_a? Github::Error::ServiceError
315
+ # handle GitHub service errors such as 404
316
+ elsif e.is_a? Github::Error::ClientError
317
+ # handle client errors e.i. missing required parameter in request
318
+ end
319
+ end
320
+ ```
321
+
304
322
  ## Response Message
305
323
 
306
324
  Each response comes packaged with methods allowing for inspection of HTTP start line and headers. For example to check for rate limits and status code issue
@@ -5,6 +5,7 @@ require 'github_api/connection'
5
5
  require 'github_api/validations'
6
6
  require 'github_api/request'
7
7
  require 'github_api/mime_type'
8
+ require 'github_api/rate_limit'
8
9
  require 'github_api/core_ext/hash'
9
10
  require 'github_api/core_ext/array'
10
11
  require 'github_api/compatibility'
@@ -13,10 +14,12 @@ require 'github_api/api_factory'
13
14
 
14
15
  module Github
15
16
  class API
17
+ include Constants
16
18
  include Authorization
17
19
  include MimeType
18
20
  include Connection
19
21
  include Request
22
+ include RateLimit
20
23
 
21
24
  # TODO consider these optional in a stack
22
25
  include Validations
@@ -83,19 +86,17 @@ module Github
83
86
  end
84
87
  end
85
88
 
89
+ def update_settings(options={})
90
+ options.each do |key, val|
91
+ self.instance_variable_set(:"@#{key}", val)
92
+ end
93
+ end
94
+
86
95
  def _update_user_repo_params(user_name, repo_name=nil) # :nodoc:
87
96
  self.user = user_name || self.user
88
97
  self.repo = repo_name || self.repo
89
98
  end
90
99
 
91
- def _merge_user_into_params!(params) # :nodoc:
92
- params.merge!({ 'user' => self.user }) if user?
93
- end
94
-
95
- def _merge_user_repo_into_params!(params) # :nodoc:
96
- { 'user' => self.user, 'repo' => self.repo }.merge!(params)
97
- end
98
-
99
100
  # TODO: See whether still needed, consider adding to core_exts
100
101
  def _hash_traverse(hash, &block)
101
102
  hash.each do |key, val|
@@ -6,11 +6,13 @@ module Github
6
6
  attr_accessor :scopes
7
7
 
8
8
  # Setup OAuth2 instance
9
- def client
9
+ def client(options={})
10
10
  @client ||= ::OAuth2::Client.new(client_id, client_secret,
11
- :site => 'https://github.com',
12
- :authorize_url => 'login/oauth/authorize',
13
- :token_url => 'login/oauth/access_token'
11
+ {
12
+ :site => options.fetch(:site) { Github.site },
13
+ :authorize_url => 'login/oauth/authorize',
14
+ :token_url => 'login/oauth/access_token'
15
+ }
14
16
  )
15
17
  end
16
18
 
@@ -9,6 +9,7 @@ module Github
9
9
  :client_secret,
10
10
  :oauth_token,
11
11
  :endpoint,
12
+ :site,
12
13
  :mime_type,
13
14
  :user_agent,
14
15
  :connection_options,
@@ -40,9 +41,12 @@ module Github
40
41
  # By default, don't set a user basic authentication
41
42
  DEFAULT_BASIC_AUTH = nil
42
43
 
43
- # The endpoint used to connect to GitHub if none is set
44
+ # The api endpoint used to connect to GitHub if none is set
44
45
  DEFAULT_ENDPOINT = 'https://api.github.com'.freeze
45
46
 
47
+ # The web endpoint used to connect to GitHub if none is set
48
+ DEFAULT_SITE = 'https://github.com'.freeze
49
+
46
50
  # The value sent in the http header for 'User-Agent' if none is set
47
51
  DEFAULT_USER_AGENT = "Github Ruby Gem #{Github::VERSION::STRING}".freeze
48
52
 
@@ -81,6 +85,7 @@ module Github
81
85
  self.client_secret = DEFAULT_CLIENT_SECRET
82
86
  self.oauth_token = DEFAULT_OAUTH_TOKEN
83
87
  self.endpoint = DEFAULT_ENDPOINT
88
+ self.site = DEFAULT_SITE
84
89
  self.user_agent = DEFAULT_USER_AGENT
85
90
  self.connection_options = DEFAULT_CONNECTION_OPTIONS
86
91
  self.mime_type = DEFAULT_MIME_TYPE
@@ -26,9 +26,10 @@ module Github
26
26
  def default_options(options={})
27
27
  {
28
28
  :headers => {
29
- ACCEPT => "application/vnd.github.v3.raw+json," \
30
- "application/vnd.github.beta.raw+json;q=0.5," \
31
- "application/json;q=0.1",
29
+ ACCEPT => "application/json" \
30
+ "application/vnd.github+json;q=0.7" \
31
+ "application/vnd.github.v3.raw+json;q=0.5" \
32
+ "application/vnd.github.beta.raw+json;q=0.1",
32
33
  ACCEPT_CHARSET => "utf-8",
33
34
  USER_AGENT => user_agent,
34
35
  CONTENT_TYPE => 'application/json'
@@ -5,31 +5,40 @@ module Github
5
5
  class GithubError < StandardError
6
6
  attr_reader :response_message, :response_headers
7
7
 
8
- def initialize(message)
9
- super message
10
- @response_message = message
8
+ # Initialize a new Github error object.
9
+ #
10
+ def initialize(message=$!)
11
+ if message.respond_to?(:backtrace)
12
+ super(message.message)
13
+ @response_message = message
14
+ else
15
+ super(message.to_s)
16
+ end
11
17
  end
12
18
 
13
- # def inspect
14
- # %(#<#{self.class}>)
15
- # end
16
- end
19
+ def backtrace
20
+ @response_message ? @response_message.backtrace : super
21
+ end
22
+
23
+ end # GithubError
17
24
  end # Error
18
25
  end # Github
19
26
 
20
27
  %w[
21
28
  service_error
22
- not_found
23
- forbidden
24
29
  bad_request
25
30
  unauthorized
26
- service_unavailable
27
- internal_server_error
31
+ forbidden
32
+ not_found
33
+ not_acceptable
28
34
  unprocessable_entity
35
+ internal_server_error
36
+ service_unavailable
29
37
  client_error
30
38
  invalid_options
31
39
  required_params
32
40
  unknown_value
41
+ validations
33
42
  ].each do |error|
34
43
  require "github_api/error/#{error}"
35
44
  end
@@ -4,8 +4,10 @@ module Github
4
4
  module Error
5
5
  # Raised when Github returns the HTTP status code 400
6
6
  class BadRequest < ServiceError
7
- def initialize(env)
8
- super(env)
7
+ http_status_code 400
8
+
9
+ def initialize(response)
10
+ super(response)
9
11
  end
10
12
  end
11
13
  end
@@ -3,9 +3,11 @@
3
3
  module Github #:nodoc
4
4
  # Raised when Github returns the HTTP status code 403
5
5
  module Error
6
- class Forbidden < GithubError
7
- def initialize(env)
8
- super(env)
6
+ class Forbidden < ServiceError
7
+ http_status_code 403
8
+
9
+ def initialize(response)
10
+ super(response)
9
11
  end
10
12
  end
11
13
  end # Error
@@ -3,10 +3,13 @@
3
3
  module Github #:nodoc
4
4
  # Raised when Github returns the HTTP status code 500
5
5
  module Error
6
- class InternalServerError < GithubError
7
- def initialize(env)
8
- super(env)
6
+ class InternalServerError < ServiceError
7
+ http_status_code 500
8
+
9
+ def initialize(response)
10
+ super(response)
9
11
  end
10
- end
12
+
13
+ end # InternalServerError
11
14
  end # Error
12
15
  end # Github
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ module Github #:nodoc
4
+ # Raised when GitHub returns the HTTP status code 406
5
+ module Error
6
+ class NotAcceptable < ServiceError
7
+ http_status_code 406
8
+
9
+ def initialize(response)
10
+ super(response)
11
+ end
12
+
13
+ end # NotAcceptable
14
+ end # Error
15
+ end # Github
@@ -4,6 +4,8 @@ module Github #:nodoc
4
4
  # Raised when Github returns the HTTP status code 404
5
5
  module Error
6
6
  class NotFound < ServiceError
7
+ http_status_code 404
8
+
7
9
  def initialize(env)
8
10
  super(env)
9
11
  end
@@ -1,19 +1,56 @@
1
1
  # encoding: utf-8
2
+ require 'multi_json'
2
3
 
3
- module Github #:nodoc
4
- # Raised when Github returns any of the HTTP status codes
4
+ module Github
5
+ # Raised when GitHub returns any of the HTTP status codes
5
6
  module Error
6
7
  class ServiceError < GithubError
7
- attr_accessor :http_headers
8
+ attr_reader :http_headers
8
9
 
9
- def initialize(env)
10
- super(generate_message(env))
11
- @http_headers = env[:response_headers]
10
+ def initialize(response)
11
+ @http_headers = response[:response_headers]
12
+ message = parse_response(response)
13
+ super(message)
12
14
  end
13
15
 
14
- def generate_message(env)
15
- "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]} #{env[:body]}"
16
+ def parse_response(response)
17
+ body = parse_body(response[:body])
18
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]} #{body}"
16
19
  end
20
+
21
+ def decode_body(body)
22
+ if body.respond_to?(:to_str) && body.length >= 2
23
+ MultiJson.load(body, :symbolize_keys => true)
24
+ else
25
+ body
26
+ end
27
+ end
28
+
29
+ def parse_body(body)
30
+ body = decode_body(body)
31
+
32
+ return '' if body.nil? || body.empty?
33
+
34
+ if body[:error]
35
+ body[:error]
36
+ elsif body[:errors]
37
+ error = Array(body[:errors]).first
38
+ if error.kind_of?(Hash)
39
+ error[:message]
40
+ else
41
+ error
42
+ end
43
+ elsif body[:message]
44
+ body[:message]
45
+ else
46
+ ''
47
+ end
48
+ end
49
+
50
+ def self.http_status_code(code)
51
+ define_method(:http_status_code) { code }
52
+ end
53
+
17
54
  end
18
55
  end # Error
19
56
  end # Github
@@ -1,12 +1,15 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github #:nodoc
4
- # Raised when Github returns the HTTP status code 404
4
+ # Raised when Github returns the HTTP status code 503
5
5
  module Error
6
- class ServiceUnavailable < GithubError
7
- def initialize(env)
8
- super(env)
6
+ class ServiceUnavailable < ServiceError
7
+ http_status_code 503
8
+
9
+ def initialize(response)
10
+ super(response)
9
11
  end
10
- end
12
+
13
+ end # ServiceUnavailable
11
14
  end # Error
12
15
  end # Github
@@ -3,10 +3,13 @@
3
3
  module Github #:nodoc
4
4
  # Raised when Github returns the HTTP status code 401
5
5
  module Error
6
- class Unauthorized < GithubError
7
- def initialize(env)
8
- super(env)
6
+ class Unauthorized < ServiceError
7
+ http_status_code 401
8
+
9
+ def initialize(response)
10
+ super(response)
9
11
  end
10
- end
12
+
13
+ end # Unauthorized
11
14
  end # Error
12
15
  end # Github
@@ -3,9 +3,11 @@
3
3
  module Github #:nodoc
4
4
  # Raised when Github returns the HTTP status code 422
5
5
  module Error
6
- class UnprocessableEntity < GithubError
7
- def initialize(env)
8
- super(env)
6
+ class UnprocessableEntity < ServiceError
7
+ http_status_code 422
8
+
9
+ def initialize(response)
10
+ super(response)
9
11
  end
10
12
  end
11
13
  end # Error
@@ -7,9 +7,9 @@ module Github #:nodoc
7
7
  def initialize(errors)
8
8
  super(
9
9
  generate_message(
10
- :problem => '',
11
- :summary => '',
12
- :resolution => ''
10
+ :problem => "Attempted to send request with nil arguments for #{errors.keys.join(', ')}.",
11
+ :summary => 'Each request expects certain number of arguments.',
12
+ :resolution => 'Double check that the provided arguments are set to some value.'
13
13
  )
14
14
  )
15
15
  end
@@ -0,0 +1,13 @@
1
+ module Github
2
+ module RateLimit
3
+
4
+ def ratelimit
5
+ get_request("/rate_limit").rate.limit
6
+ end
7
+
8
+ def ratelimit_remaining
9
+ get_request("/rate_limit").rate.remaining
10
+ end
11
+
12
+ end # RateLimit
13
+ end # Github
@@ -54,7 +54,7 @@ module Github
54
54
 
55
55
  # Access to Repos::Contents API
56
56
  def contents
57
- @commits ||= ApiFactory.new 'Repos::Contents'
57
+ @contents ||= ApiFactory.new 'Repos::Contents'
58
58
  end
59
59
 
60
60
  # Access to Repos::Downloads API
@@ -277,7 +277,6 @@ module Github
277
277
  def list(*args)
278
278
  params = args.extract_options!
279
279
  normalize! params
280
- _merge_user_into_params!(params) unless params.has_key?('user')
281
280
  filter! %w[ org user type ], params
282
281
 
283
282
  response = if (user_name = params.delete("user"))
@@ -35,7 +35,6 @@ module Github
35
35
  def watched(*args)
36
36
  params = args.extract_options!
37
37
  normalize! params
38
- _merge_user_into_params!(params) unless params.has_key?('user')
39
38
 
40
39
  response = if (user_name = params.delete('user'))
41
40
  get_request("/users/#{user_name}/watched", params)
@@ -16,6 +16,8 @@ module Github
16
16
  raise Github::Error::Forbidden.new(env)
17
17
  when 404
18
18
  raise Github::Error::NotFound.new(env)
19
+ when 406
20
+ raise Github::Error::NotAcceptable.new(env)
19
21
  when 422
20
22
  raise Github::Error::UnprocessableEntity.new(env)
21
23
  when 500
@@ -8,8 +8,13 @@ module Github
8
8
  # Ensures that esential arguments are present before request is made
9
9
  #
10
10
  def _validate_presence_of(*params)
11
- params.each do |param|
12
- raise ArgumentError, "parameter cannot be nil" if param.nil?
11
+ case params
12
+ when Hash
13
+ raise Github::Error::Validations.new(params)
14
+ when Array
15
+ params.each do |param|
16
+ raise ArgumentError, "parameter cannot be nil" if param.nil?
17
+ end
13
18
  end
14
19
  end
15
20
 
@@ -4,7 +4,7 @@ module Github
4
4
  module VERSION
5
5
  MAJOR = 0
6
6
  MINOR = 6
7
- PATCH = 3
7
+ PATCH = 4
8
8
  BUILD = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.');
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Error::ServiceError do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+
9
+ def test_request(body='')
10
+ stub_get("/repos/#{user}/#{repo}/branches").
11
+ to_return(:body => body, :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
12
+ end
13
+
14
+ it "handles empty message" do
15
+ test_request
16
+ expect {
17
+ Github.repos.branches user, repo
18
+ }.to raise_error(Github::Error::NotFound)
19
+ end
20
+
21
+ it "handles error message" do
22
+ test_request :error => 'not found'
23
+ expect {
24
+ Github.repos.branches user, repo
25
+ }.to raise_error(Github::Error::NotFound, /not found/)
26
+ end
27
+
28
+ it "handles nested errors" do
29
+ test_request :errors => { :message => 'key is already in use' }
30
+ expect {
31
+ Github.repos.branches user, repo
32
+ }.to raise_error(Github::Error::NotFound, /key is already in use/)
33
+ end
34
+
35
+ it 'decodes message' do
36
+ test_request MultiJson.dump(:errors => { :message => 'key is already in use' })
37
+ expect {
38
+ Github.repos.branches user, repo
39
+ }.to raise_error(Github::Error::NotFound, /key is already in use/)
40
+ end
41
+
42
+
43
+ end # Github::Error::ServiceError
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Error::Validations do
6
+ describe '#message' do
7
+ let(:error) { described_class.new(:username => nil) }
8
+
9
+ it 'contains the problem in the message' do
10
+ error.message.should include "Attempted to send request with nil arguments"
11
+ end
12
+
13
+ it 'contains the summary in the message' do
14
+ error.message.should include "Each request expects certain number of arguments."
15
+ end
16
+
17
+ it 'contains the resolution in the message' do
18
+ error.message.should include "Double check that the provided arguments are set to some value."
19
+ end
20
+ end
21
+ end # Github::Error::Validations
@@ -131,7 +131,7 @@ describe Github::GitData::References do
131
131
  context "resource not found" do
132
132
  before do
133
133
  stub_get("/repos/#{user}/#{repo}/git/refs/#{ref}").
134
- to_return(:body => fixture('git_data/reference.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
134
+ to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
135
135
  end
136
136
 
137
137
  it "should fail to retrive resource" do
@@ -196,8 +196,8 @@ describe Github::GitData::References do
196
196
  context "failed to create resource" do
197
197
  before do
198
198
  stub_post("/repos/#{user}/#{repo}/git/refs").with(inputs).
199
- to_return(:body => fixture('git_data/reference.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
200
-
199
+ to_return(:body => '', :status => 404,
200
+ :headers => {:content_type => "application/json; charset=utf-8"})
201
201
  end
202
202
 
203
203
  it "should faile to retrieve resource" do
@@ -256,8 +256,8 @@ describe Github::GitData::References do
256
256
  context "failed to update resource" do
257
257
  before do
258
258
  stub_patch("/repos/#{user}/#{repo}/git/refs/#{ref}").with(inputs).
259
- to_return(:body => fixture('git_data/reference.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
260
-
259
+ to_return(:body => '', :status => 404,
260
+ :headers => {:content_type => "application/json; charset=utf-8"})
261
261
  end
262
262
 
263
263
  it "should faile to retrieve resource" do
@@ -51,7 +51,7 @@ describe Github::Orgs::Members do
51
51
  context "resource not found" do
52
52
  before do
53
53
  stub_get("/orgs/#{org}/members").
54
- to_return(:body => fixture('orgs/members.json'), :status => 404,
54
+ to_return(:body => '', :status => 404,
55
55
  :headers => {:content_type => "application/json; charset=utf-8"})
56
56
  end
57
57
 
@@ -136,7 +136,8 @@ describe Github::Orgs::Members do
136
136
  context "resource not found" do
137
137
  before do
138
138
  stub_get("/orgs/#{org}/public_members").
139
- to_return(:body => fixture('orgs/members.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
139
+ to_return(:body => '', :status => 404,
140
+ :headers => {:content_type => "application/json; charset=utf-8"})
140
141
  end
141
142
 
142
143
  it "should return 404 with a message 'Not Found'" do
@@ -197,7 +198,7 @@ describe Github::Orgs::Members do
197
198
  context "resource not found" do
198
199
  before do
199
200
  stub_put("/orgs/#{org}/public_members/#{member}").
200
- to_return(:body => fixture('orgs/members.json'), :status => 404,
201
+ to_return(:body => '', :status => 404,
201
202
  :headers => {:content_type => "application/json; charset=utf-8"})
202
203
  end
203
204
 
@@ -232,7 +233,7 @@ describe Github::Orgs::Members do
232
233
  context "resource not found" do
233
234
  before do
234
235
  stub_delete("/orgs/#{org}/public_members/#{member}").
235
- to_return(:body => fixture('orgs/members.json'), :status => 404,
236
+ to_return(:body => '', :status => 404,
236
237
  :headers => {:content_type => "application/json; charset=utf-8"})
237
238
  end
238
239
 
@@ -52,7 +52,7 @@ describe Github::Orgs::Teams do
52
52
  context "resource not found" do
53
53
  before do
54
54
  stub_get("/orgs/#{org}/teams").
55
- to_return(:body => fixture('orgs/teams.json'), :status => 404,
55
+ to_return(:body => '', :status => 404,
56
56
  :headers => {:content_type => "application/json; charset=utf-8"})
57
57
  end
58
58
 
@@ -146,7 +146,7 @@ describe Github::Orgs::Teams do
146
146
  context "failed to create resource" do
147
147
  before do
148
148
  stub_post("/orgs/#{org}/teams").with(inputs).
149
- to_return(:body => fixture('orgs/team.json'), :status => 404,
149
+ to_return(:body => '', :status => 404,
150
150
  :headers => {:content_type => "application/json; charset=utf-8"})
151
151
  end
152
152
 
@@ -285,7 +285,8 @@ describe Github::Orgs::Teams do
285
285
  context "resource not found" do
286
286
  before do
287
287
  stub_get("/teams/#{team}/members").
288
- to_return(:body => fixture('orgs/teams.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
288
+ to_return(:body => '', :status => 404,
289
+ :headers => {:content_type => "application/json; charset=utf-8"})
289
290
  end
290
291
 
291
292
  it "should return 404 with a message 'Not Found'" do
@@ -43,7 +43,7 @@ describe Github::Repos::Keys do
43
43
  context "resource not found" do
44
44
  before do
45
45
  stub_get("/repos/#{user}/#{repo}/keys").
46
- to_return(:body => fixture("repos/keys.json"), :status => 404)
46
+ to_return(:body => '', :status => 404)
47
47
  end
48
48
 
49
49
  it "should fail to retrieve resource" do
@@ -85,7 +85,7 @@ describe Github::Repos::Keys do
85
85
  context "resource not found" do
86
86
  before do
87
87
  stub_get("/repos/#{user}/#{repo}/keys/#{key_id}").
88
- to_return(:body => fixture("repos/keys.json"), :status => 404)
88
+ to_return(:body => '', :status => 404)
89
89
  end
90
90
 
91
91
  it "should fail to retrieve resource" do
@@ -67,7 +67,7 @@ describe Github::Repos::Watching do
67
67
  context "if user unauthenticated" do
68
68
  it "should fail to get resource without username " do
69
69
  stub_get("/user/watched").
70
- to_return(:body => fixture("repos/watched.json"), :status => 401, :headers => {})
70
+ to_return(:body => '', :status => 401, :headers => {})
71
71
  expect {
72
72
  github.repos.watching.watched
73
73
  }.to raise_error(Github::Error::Unauthorized)
@@ -67,7 +67,7 @@ describe Github::Repos do
67
67
  context "resource not found" do
68
68
  before do
69
69
  stub_get("/repos/#{user}/#{repo}/branches").
70
- to_return(:body => fixture('repos/branches.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
70
+ to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
71
71
 
72
72
  end
73
73
 
@@ -163,8 +163,8 @@ describe Github::Repos do
163
163
  context "resource not found" do
164
164
  before do
165
165
  stub_get("/repos/#{user}/#{repo}/contributors").
166
- to_return(:body => fixture('repos/contributors.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
167
-
166
+ to_return(:body => '', :status => 404,
167
+ :headers => {:content_type => "application/json; charset=utf-8"})
168
168
  end
169
169
 
170
170
  it "should fail to get resource" do
@@ -525,7 +525,8 @@ describe Github::Repos do
525
525
  context "resource not found" do
526
526
  before do
527
527
  stub_get("/repos/#{user}/#{repo}/tags").
528
- to_return(:body => fixture('repos/branches.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
528
+ to_return(:body => '', :status => 404,
529
+ :headers => {:content_type => "application/json; charset=utf-8"})
529
530
  end
530
531
 
531
532
  it "should fail to get resource" do
@@ -580,7 +581,8 @@ describe Github::Repos do
580
581
  context "resource not found" do
581
582
  before do
582
583
  stub_get("/repos/#{user}/#{repo}/teams").
583
- to_return(:body => fixture('repos/teams.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
584
+ to_return(:body => '', :status => 404,
585
+ :headers => {:content_type => "application/json; charset=utf-8"})
584
586
  end
585
587
 
586
588
  it "should fail to get resource" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-17 00:00:00.000000000Z
12
+ date: 2012-07-28 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashie
16
- requirement: &2153056440 !ruby/object:Gem::Requirement
16
+ requirement: &2153193940 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153056440
24
+ version_requirements: *2153193940
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: faraday
27
- requirement: &2153055720 !ruby/object:Gem::Requirement
27
+ requirement: &2153193440 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.8.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2153055720
35
+ version_requirements: *2153193440
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: multi_json
38
- requirement: &2153055000 !ruby/object:Gem::Requirement
38
+ requirement: &2153192940 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '1.3'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2153055000
46
+ version_requirements: *2153192940
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: oauth2
49
- requirement: &2153054440 !ruby/object:Gem::Requirement
49
+ requirement: &2153192560 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2153054440
57
+ version_requirements: *2153192560
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: nokogiri
60
- requirement: &2153053580 !ruby/object:Gem::Requirement
60
+ requirement: &2153192000 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.5.2
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *2153053580
68
+ version_requirements: *2153192000
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &2153053000 !ruby/object:Gem::Requirement
71
+ requirement: &2153191480 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2153053000
79
+ version_requirements: *2153191480
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: cucumber
82
- requirement: &2153052540 !ruby/object:Gem::Requirement
82
+ requirement: &2153190980 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2153052540
90
+ version_requirements: *2153190980
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: webmock
93
- requirement: &2153052080 !ruby/object:Gem::Requirement
93
+ requirement: &2153190380 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 1.8.0
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2153052080
101
+ version_requirements: *2153190380
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: vcr
104
- requirement: &2153051600 !ruby/object:Gem::Requirement
104
+ requirement: &2153189800 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 2.2.0
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *2153051600
112
+ version_requirements: *2153189800
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: simplecov
115
- requirement: &2153051140 !ruby/object:Gem::Requirement
115
+ requirement: &2153189220 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 0.6.1
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *2153051140
123
+ version_requirements: *2153189220
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: guard
126
- requirement: &2153050760 !ruby/object:Gem::Requirement
126
+ requirement: &2153188820 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *2153050760
134
+ version_requirements: *2153188820
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: guard-rspec
137
- requirement: &2153050300 !ruby/object:Gem::Requirement
137
+ requirement: &2153188240 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *2153050300
145
+ version_requirements: *2153188240
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: guard-cucumber
148
- requirement: &2153049880 !ruby/object:Gem::Requirement
148
+ requirement: &2153187680 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,10 +153,10 @@ dependencies:
153
153
  version: '0'
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *2153049880
156
+ version_requirements: *2153187680
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: rake
159
- requirement: &2153049460 !ruby/object:Gem::Requirement
159
+ requirement: &2153187220 !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
162
162
  - - ! '>='
@@ -164,10 +164,10 @@ dependencies:
164
164
  version: '0'
165
165
  type: :development
166
166
  prerelease: false
167
- version_requirements: *2153049460
167
+ version_requirements: *2153187220
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: bundler
170
- requirement: &2153049040 !ruby/object:Gem::Requirement
170
+ requirement: &2153186740 !ruby/object:Gem::Requirement
171
171
  none: false
172
172
  requirements:
173
173
  - - ! '>='
@@ -175,7 +175,7 @@ dependencies:
175
175
  version: '0'
176
176
  type: :development
177
177
  prerelease: false
178
- version_requirements: *2153049040
178
+ version_requirements: *2153186740
179
179
  description: ! ' Ruby wrapper that supports all of the GitHub API v3 methods(nearly
180
180
  200). It''s build in a modular way, that is, you can either instantiate the whole
181
181
  api wrapper Github.new or use parts of it e.i. Github::Repos.new if working solely
@@ -301,6 +301,7 @@ files:
301
301
  - lib/github_api/error/forbidden.rb
302
302
  - lib/github_api/error/internal_server_error.rb
303
303
  - lib/github_api/error/invalid_options.rb
304
+ - lib/github_api/error/not_acceptable.rb
304
305
  - lib/github_api/error/not_found.rb
305
306
  - lib/github_api/error/required_params.rb
306
307
  - lib/github_api/error/service_error.rb
@@ -338,7 +339,7 @@ files:
338
339
  - lib/github_api/params_hash.rb
339
340
  - lib/github_api/pull_requests/comments.rb
340
341
  - lib/github_api/pull_requests.rb
341
- - lib/github_api/ratelimit_status.rb
342
+ - lib/github_api/rate_limit.rb
342
343
  - lib/github_api/repos/collaborators.rb
343
344
  - lib/github_api/repos/commits.rb
344
345
  - lib/github_api/repos/contents.rb
@@ -461,7 +462,9 @@ files:
461
462
  - spec/github/error/client_error_spec.rb
462
463
  - spec/github/error/invalid_options_spec.rb
463
464
  - spec/github/error/required_params_spec.rb
465
+ - spec/github/error/service_error_spec.rb
464
466
  - spec/github/error/unknown_value_spec.rb
467
+ - spec/github/error/validations_spec.rb
465
468
  - spec/github/events_spec.rb
466
469
  - spec/github/gists/comments_spec.rb
467
470
  - spec/github/gists_spec.rb
@@ -525,7 +528,7 @@ files:
525
528
  homepage: https://github.com/peter-murach/github
526
529
  licenses: []
527
530
  post_install_message: ! "\n--------------------------------------------------------------------------------\nThank
528
- you for installing github_api-0.6.3.\n\n*NOTE*: Version 0.5.0 introduces breaking
531
+ you for installing github_api-0.6.4.\n\n*NOTE*: Version 0.5.0 introduces breaking
529
532
  changes to the way github api is queried.\nThe interface has been rewritten to be
530
533
  more consistent with REST verbs that\ninteract with GitHub hypermedia resources.
531
534
  Thus, to list resources 'list' or 'all'\nverbs are used, to retrieve individual
@@ -1,17 +0,0 @@
1
- module Github
2
- class RatelimitStatus
3
- include Github::Constants
4
-
5
- attr_reader :ratelimit_limit, :ratelimit_remaining
6
-
7
- def initialize(env)
8
- @env = env
9
- @ratelimit_limit = env[:response_headers][RATELIMIT_LIMIT]
10
- @ratelimit_remaining = env[:response_headers][RATELIMIT_REMAINING]
11
- end
12
-
13
- def ratelimit_reset_time
14
- @ratelimit_reset_time ||= Time.parse(@env[:reponse_headers]['date'])
15
- end
16
- end
17
- end