-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #307 from armilam/switch-to-faraday
Allow use of either rest-client or faraday
- Loading branch information
Showing
17 changed files
with
282 additions
and
53 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module Trello | ||
module TFaraday | ||
class TInternet | ||
class << self | ||
begin | ||
require 'faraday' | ||
rescue LoadError | ||
end | ||
|
||
def execute(request) | ||
try_execute request | ||
end | ||
|
||
private | ||
|
||
def try_execute(request) | ||
begin | ||
if request | ||
result = execute_core request | ||
Response.new(200, {}, result.body) | ||
end | ||
rescue Faraday::Error => e | ||
raise if !e.respond_to?(:response) || e.response.nil? || e.response[:status].nil? | ||
Response.new(e.response[:status], {}, e.response[:body]) | ||
end | ||
end | ||
|
||
def execute_core(request) | ||
conn = Faraday.new( | ||
request.uri.to_s, | ||
headers: request.headers, | ||
proxy: ENV['HTTP_PROXY'], | ||
request: { timeout: 10 } | ||
) do |faraday| | ||
faraday.response :raise_error | ||
faraday.request :json | ||
end | ||
|
||
conn.send(request.verb) do |req| | ||
req.body = request.body | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module Trello | ||
module TRestClient | ||
class TInternet | ||
class << self | ||
begin | ||
require 'rest-client' | ||
rescue LoadError | ||
end | ||
|
||
def execute(request) | ||
try_execute request | ||
end | ||
|
||
private | ||
|
||
def try_execute(request) | ||
begin | ||
if request | ||
result = execute_core request | ||
Response.new(200, {}, result.body) | ||
end | ||
rescue RestClient::Exception => e | ||
raise if !e.respond_to?(:http_code) || e.http_code.nil? | ||
Response.new(e.http_code, {}, e.http_body) | ||
end | ||
end | ||
|
||
def execute_core(request) | ||
RestClient.proxy = ENV['HTTP_PROXY'] if ENV['HTTP_PROXY'] | ||
RestClient::Request.execute( | ||
method: request.verb, | ||
url: request.uri.to_s, | ||
headers: request.headers, | ||
payload: request.body, | ||
timeout: 10 | ||
) | ||
end | ||
end | ||
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
Oops, something went wrong.