forked from facebookarchive/instagram-ruby-gem
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated faraday version and fixed related issues
- Loading branch information
Peter Bakkum
committed
Feb 9, 2012
1 parent
c24c963
commit b84aee3
Showing
9 changed files
with
61 additions
and
79 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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'faraday' | ||
|
||
# @private | ||
module FaradayMiddleware | ||
# @private | ||
class RaiseHttpException < Faraday::Middleware | ||
def call(env) | ||
@app.call(env).on_complete do |response| | ||
case response[:status].to_i | ||
when 400 | ||
raise Instagram::BadRequest, error_message_400(response) | ||
when 404 | ||
raise Instagram::NotFound, error_message_400(response) | ||
when 500 | ||
raise Instagram::InternalServerError, error_message_500(response, "Something is technically wrong.") | ||
when 503 | ||
raise Instagram::ServiceUnavailable, error_message_500(response, "Instagram is rate limiting your requests.") | ||
end | ||
end | ||
end | ||
|
||
def initialize(app) | ||
super app | ||
@parser = nil | ||
end | ||
|
||
private | ||
|
||
def error_message_400(response) | ||
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{error_body(response[:body])}" | ||
end | ||
|
||
def error_body(body) | ||
if body.nil? | ||
nil | ||
elsif body['meta'] and body['meta']['error_message'] and not body['meta']['error_message'].empty? | ||
": #{body['meta']['error_message']}" | ||
end | ||
end | ||
|
||
def error_message_500(response, body=nil) | ||
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{[response[:status].to_s + ':', body].compact.join(' ')}" | ||
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'openssl' | ||
require 'multi_json' | ||
|
||
module Instagram | ||
class Client | ||
|
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