Permalink
Browse files

Actually add user agent to connection

  • Loading branch information...
1 parent cf70f20 commit 40aea03fd3b835c1fa90bad96fd0051e07fd9d01 @pengwynn pengwynn committed Dec 3, 2012
Showing with 27 additions and 4 deletions.
  1. +6 −4 lib/octokit/connection.rb
  2. +21 −0 spec/octokit/client_spec.rb
View
@@ -8,11 +8,11 @@ module Connection
def connection(options={})
options = {
- :authenticate => true,
+ :authenticate => true,
:force_urlencoded => false,
- :raw => false,
- :ssl => { :verify => false },
- :url => Octokit.api_endpoint
+ :raw => false,
+ :ssl => { :verify => false },
+ :url => api_endpoint
}.merge(options)
if !proxy.nil?
@@ -43,6 +43,8 @@ def connection(options={})
connection.basic_auth authentication[:login], authentication[:password]
end
+ connection.headers[:user_agent] = user_agent
+
connection
end
end
@@ -1,6 +1,27 @@
require 'helper'
describe Octokit::Client do
+
+ it "sets a default user agent" do
+ stub_request(:get, "https://api.github.com/rate_limit").
+ with(:headers => {:user_agent => Octokit.user_agent }).
+ to_return(:status => 200, :body => '', :headers =>
+ { 'X-RateLimit-Limit' => 5000, 'X-RateLimit-Remaining' => 5000})
+
+ Octokit.rate_limit
+ end
+
+ it "allows a custom user agent" do
+ Octokit.user_agent = 'My mashup'
+
+ stub_request(:get, "https://api.github.com/rate_limit").
+ with(:headers => {:user_agent => 'My mashup' }).
+ to_return(:status => 200, :body => '', :headers =>
+ { 'X-RateLimit-Limit' => 5000, 'X-RateLimit-Remaining' => 5000})
+
+ Octokit.rate_limit
+ end
+
it "works with basic auth and password" do
stub_get("https://foo:bar@api.github.com/repos/baz/quux/commits?per_page=35&sha=master").
to_return(:status => 200, :body => '{"commits":[]}', :headers => {})

0 comments on commit 40aea03

Please sign in to comment.