Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
79 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Octokit | ||
module Authentication | ||
def authentication | ||
if login && token | ||
{:login => "#{login}/token", :password => token} | ||
elsif login && password | ||
{:login => login, :password => password} | ||
else | ||
{} | ||
end | ||
end | ||
|
||
def authenticated? | ||
!authentication.empty? | ||
end | ||
|
||
def oauthed? | ||
!oauth_token.nil? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,40 @@ | ||
require 'multi_json' | ||
|
||
module Octokit | ||
class Client | ||
module Request | ||
def get(path, options={}, version=api_version, authenticate=true, raw=false, force_urlencoded=false) | ||
request(:get, path, options, version, authenticate, raw, force_urlencoded) | ||
end | ||
module Request | ||
def get(path, options={}, version=api_version, authenticate=true, raw=false, force_urlencoded=false) | ||
request(:get, path, options, version, authenticate, raw, force_urlencoded) | ||
end | ||
|
||
def post(path, options={}, version=api_version, authenticate=true, raw=false, force_urlencoded=false) | ||
request(:post, path, options, version, authenticate, raw, force_urlencoded) | ||
end | ||
def post(path, options={}, version=api_version, authenticate=true, raw=false, force_urlencoded=false) | ||
request(:post, path, options, version, authenticate, raw, force_urlencoded) | ||
end | ||
|
||
def put(path, options={}, version=api_version, authenticate=true, raw=false, force_urlencoded=false) | ||
request(:put, path, options, version, authenticate, raw, force_urlencoded) | ||
end | ||
def put(path, options={}, version=api_version, authenticate=true, raw=false, force_urlencoded=false) | ||
request(:put, path, options, version, authenticate, raw, force_urlencoded) | ||
end | ||
|
||
def delete(path, options={}, version=api_version, authenticate=true, raw=false, force_urlencoded=false) | ||
request(:delete, path, options, version, authenticate, raw, force_urlencoded) | ||
end | ||
def delete(path, options={}, version=api_version, authenticate=true, raw=false, force_urlencoded=false) | ||
request(:delete, path, options, version, authenticate, raw, force_urlencoded) | ||
end | ||
|
||
private | ||
private | ||
|
||
def request(method, path, options, version, authenticate, raw, force_urlencoded) | ||
response = connection(authenticate, raw, version, force_urlencoded).send(method) do |request| | ||
case method | ||
when :get, :delete | ||
request.url(path, options) | ||
when :post, :put | ||
request.path = path | ||
if version >= 3 && !force_urlencoded | ||
request.body = MultiJson.encode(options) unless options.empty? | ||
else | ||
request.body = options unless options.empty? | ||
end | ||
def request(method, path, options, version, authenticate, raw, force_urlencoded) | ||
response = connection(authenticate, raw, version, force_urlencoded).send(method) do |request| | ||
case method | ||
when :get, :delete | ||
request.url(path, options) | ||
when :post, :put | ||
request.path = path | ||
if version >= 3 && !force_urlencoded | ||
request.body = MultiJson.encode(options) unless options.empty? | ||
else | ||
request.body = options unless options.empty? | ||
end | ||
end | ||
raw ? response : response.body | ||
end | ||
|
||
raw ? response : response.body | ||
end | ||
end | ||
end |