Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 3 commits
  • 11 files changed
  • 0 commit comments
  • 1 contributor
Commits on Aug 31, 2012
@pengwynn pengwynn Support unauthed rate limited requests
Refs #128. Now you can set Octokit.client_id and
Octokit.client_secret to make unauthenticated while using
higher rate limits for your OAuth app if available.
68f288d
@pengwynn pengwynn Implements Status API 37e0d84
Commits on Sep 04, 2012
@pengwynn pengwynn Version bump bc76423
View
1 CHANGELOG.md
@@ -1,5 +1,6 @@
# CHANGELOG
+* [1.12.0 - September 4,2012](https://github.com/pengwynn/octokit/compare/v1.11.0...v1.12.0)
* [1.11.0 - August 29, 2012](https://github.com/pengwynn/octokit/compare/v1.10.0...v1.11.0)
* [1.10.0 - August 8, 2012](https://github.com/pengwynn/octokit/compare/v1.9.4...v1.10.0)
* [1.9.4 - August 6, 2012](https://github.com/pengwynn/octokit/compare/v1.9.3...v1.9.4)
View
11 lib/octokit/authentication.rb
@@ -15,5 +15,16 @@ def authenticated?
def oauthed?
!oauth_token.nil?
end
+
+ def unauthed_rate_limited?
+ client_id && client_secret
+ end
+
+ def unauthed_rate_limit_params
+ {
+ :client_id => client_id,
+ :client_secret => client_secret
+ }
+ end
end
end
View
2 lib/octokit/client.rb
@@ -23,6 +23,7 @@
require 'octokit/client/contents'
require 'octokit/client/markdown'
require 'octokit/client/emojis'
+require 'octokit/client/statuses'
module Octokit
class Client
@@ -58,5 +59,6 @@ def initialize(options={})
include Octokit::Client::Contents
include Octokit::Client::Markdown
include Octokit::Client::Emojis
+ include Octokit::Client::Statuses
end
end
View
29 lib/octokit/client/statuses.rb
@@ -0,0 +1,29 @@
+module Octokit
+ class Client
+ module Statuses
+
+ # List all statuses for a given commit
+ #
+ # @param repo [String, Repository, Hash] A GitHub repository
+ # @param sha [String] The SHA1 for the commit
+ # @return [Array] A list of statuses
+ # @see http://developer.github.com/v3/repos/status
+ def statuses(repo, sha, options={})
+ get("repos/#{Repository.new(repo)}/statuses/#{sha}", options, 3)
+ end
+ alias :list_statuses :statuses
+
+ # Create status for a commit
+ #
+ # @param repo [String, Repository, Hash] A GitHub repository
+ # @param sha [String] The SHA1 for the commit
+ # @param state [String] The state: pending, success, failure, error
+ # @return [Hash] A status
+ # @see http://developer.github.com/v3/repos/status
+ def create_status(repo, sha, state, options={})
+ options.merge!(:state => state)
+ post("repos/#{Repository.new(repo)}/statuses/#{sha}", options, 3)
+ end
+ end
+ end
+end
View
4 lib/octokit/configuration.rb
@@ -12,6 +12,8 @@ module Configuration
:password,
:proxy,
:oauth_token,
+ :client_id,
+ :client_secret,
:user_agent,
:auto_traversal,
:per_page].freeze
@@ -54,6 +56,8 @@ def reset
self.password = nil
self.proxy = nil
self.oauth_token = nil
+ self.client_id = nil
+ self.client_secret = nil
self.user_agent = DEFAULT_USER_AGENT
self.auto_traversal = DEFAULT_AUTO_TRAVERSAL
end
View
1 lib/octokit/connection.rb
@@ -19,6 +19,7 @@ def connection(authenticate=true, raw=false, version=3, force_urlencoded=false)
}
options.merge!(:params => {:access_token => oauth_token}) if oauthed? && !authenticated?
+ options.merge!(:params => unauthed_rate_limit_params) if !oauthed? && !authenticated? && unauthed_rate_limited?
# TODO: Don't build on every request
connection = Faraday.new(options) do |builder|
View
2 lib/octokit/version.rb
@@ -1,3 +1,3 @@
module Octokit
- VERSION = "1.11.0" unless defined?(Octokit::VERSION)
+ VERSION = "1.12.0" unless defined?(Octokit::VERSION)
end
View
16 spec/fixtures/v3/status.json
@@ -0,0 +1,16 @@
+{
+ "target_url": "http://wynnnetherland.com",
+ "created_at": "2012-08-31T19:43:44Z",
+ "creator": {
+ "avatar_url": "https://secure.gravatar.com/avatar/7e19cd5486b5d6dc1ef90e671ba52ae0?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
+ "gravatar_id": "7e19cd5486b5d6dc1ef90e671ba52ae0",
+ "login": "pengwynn",
+ "url": "https://api.github.com/users/pengwynn",
+ "id": 865
+ },
+ "description": null,
+ "updated_at": "2012-08-31T19:43:44Z",
+ "url": "https://api.github.com/repos/pengwynn/api-sandbox/statuses/195422",
+ "id": 195422,
+ "state": "success"
+}
View
34 spec/fixtures/v3/statuses.json
@@ -0,0 +1,34 @@
+[
+ {
+ "target_url": "http://travis-ci.org/pengwynn/octokit/builds/2092930",
+ "created_at": "2012-08-11T06:49:10Z",
+ "creator": {
+ "avatar_url": "https://secure.gravatar.com/avatar/7e19cd5486b5d6dc1ef90e671ba52ae0?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
+ "gravatar_id": "7e19cd5486b5d6dc1ef90e671ba52ae0",
+ "login": "pengwynn",
+ "url": "https://api.github.com/users/pengwynn",
+ "id": 865
+ },
+ "description": "The Travis build failed",
+ "updated_at": "2012-08-11T06:49:10Z",
+ "url": "https://api.github.com/repos/pengwynn/octokit/statuses/64171",
+ "id": 64171,
+ "state": "failure"
+ },
+ {
+ "target_url": "http://travis-ci.org/pengwynn/octokit/builds/2092930",
+ "created_at": "2012-08-11T06:48:35Z",
+ "creator": {
+ "avatar_url": "https://secure.gravatar.com/avatar/7e19cd5486b5d6dc1ef90e671ba52ae0?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
+ "gravatar_id": "7e19cd5486b5d6dc1ef90e671ba52ae0",
+ "login": "pengwynn",
+ "url": "https://api.github.com/users/pengwynn",
+ "id": 865
+ },
+ "description": "The Travis build is in progress",
+ "updated_at": "2012-08-11T06:48:35Z",
+ "url": "https://api.github.com/repos/pengwynn/octokit/statuses/64167",
+ "id": 64167,
+ "state": "pending"
+ }
+]
View
35 spec/octokit/client/statuses_spec.rb
@@ -0,0 +1,35 @@
+# -*- encoding: utf-8 -*-
+require 'helper'
+
+describe Octokit::Client::Statuses do
+
+ before do
+ @client = Octokit::Client.new(:login => 'sferik')
+ end
+
+ describe '.statuses' do
+
+ it 'should list commit statuses' do
+ stub_get('https://api.github.com/repos/pengwynn/octokit/statuses/7d069dedd4cb56bf57760688657abd0e6b5a28b8').
+ to_return(:body => fixture('v3/statuses.json'))
+ statuses = @client.statuses('pengwynn/octokit', '7d069dedd4cb56bf57760688657abd0e6b5a28b8')
+ statuses.first.target_url.should == 'http://travis-ci.org/pengwynn/octokit/builds/2092930'
+ end
+
+ end
+
+ describe '.create_status' do
+
+ it 'should create status' do
+ stub_post('https://api.github.com/repos/pengwynn/octokit/statuses/7d069dedd4cb56bf57760688657abd0e6b5a28b8').
+ to_return(:body => fixture('v3/status.json'))
+ info = {
+ :target_url => 'http://wynnnetherland.com'
+ }
+ status = @client.create_status('pengwynn/octokit', '7d069dedd4cb56bf57760688657abd0e6b5a28b8', 'success', info)
+ status.target_url.should == 'http://wynnnetherland.com'
+ end
+
+ end
+
+end
View
26 spec/octokit/client_spec.rb
@@ -62,6 +62,32 @@
end
+ describe "unauthed rate limit" do
+
+ before(:each) do
+ Octokit.client_id = "OU812"
+ Octokit.client_secret = "P4N4MA"
+
+ stub_request(:get, "https://api.github.com/rate_limit?client_id=OU812&client_secret=P4N4MA").
+ to_return(:status => 200, :body => '', :headers =>
+ { 'X-RateLimit-Limit' => 62500, 'X-RateLimit-Remaining' => 62500})
+ @client = Octokit::Client.new()
+ end
+
+ after(:each) do
+ Octokit.reset
+ end
+
+ it "should get the ratelimit-limit from the header" do
+ @client.ratelimit.should == 62500
+ end
+
+ it "should get the ratelimit-remaining using header" do
+ @client.ratelimit_remaining.should == 62500
+ end
+
+ end
+
describe "api_endpoint" do
after(:each) do

No commit comments for this range

Something went wrong with that request. Please try again.