-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to HTTP to raise connection errors with specific error cl…
…ass.
- Loading branch information
1 parent
b1648d2
commit 29cacf7
Showing
17 changed files
with
83 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
# https://developer.dailymotion.com/api | ||
|
||
class DailymotionError < HTTPError; end | ||
|
||
class Dailymotion < HTTP | ||
BASE_URL = "https://api.dailymotion.com" | ||
ERROR_CLASS = DailymotionError | ||
end | ||
|
||
class DailymotionError < HTTPError; end | ||
|
||
error DailymotionError do |e| | ||
status 503 | ||
"There was a problem talking to Dailymotion." | ||
"There was a problem talking to Dailymotion. Please try again in a moment." | ||
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,13 +1,14 @@ | ||
# https://developers.facebook.com/docs/graph-api/reference/ | ||
|
||
class FacebookError < HTTPError; end | ||
|
||
class Facebook < HTTP | ||
BASE_URL = "https://graph.facebook.com/v2.8" | ||
PARAMS = "access_token=#{ENV["FACEBOOK_APP_ID"]}|#{ENV["FACEBOOK_APP_SECRET"]}" | ||
ERROR_CLASS = FacebookError | ||
end | ||
|
||
class FacebookError < HTTPError; end | ||
|
||
error FacebookError do |e| | ||
status 503 | ||
"There was a problem talking to Facebook." | ||
"There was a problem talking to Facebook. Please try again in a moment." | ||
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,18 +1,19 @@ | ||
# https://developers.google.com/youtube/v3/docs/ | ||
# https://developers.google.com/+/web/api/rest/ | ||
|
||
class GoogleError < HTTPError; end | ||
|
||
class Google < HTTP | ||
BASE_URL = "https://www.googleapis.com" | ||
PARAMS = "key=#{ENV["GOOGLE_API_KEY"]}" | ||
ERROR_CLASS = GoogleError | ||
end | ||
|
||
class GoogleError < HTTPError; end | ||
|
||
error GoogleError do |e| | ||
status 503 | ||
if (e.data["error"]["errors"][0]["reason"] == "accessNotConfigured" rescue false) | ||
"Please enable the appropriate API for this project in the Google Developer Console." | ||
else | ||
"There was a problem talking to Google." | ||
"There was a problem talking to Google. Please try again in a moment." | ||
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,15 +1,16 @@ | ||
# https://api.imgur.com/endpoints | ||
|
||
class ImgurError < HTTPError; end | ||
|
||
class Imgur < HTTP | ||
BASE_URL = "https://api.imgur.com/3" | ||
HEADERS = { | ||
"Authorization": "Client-ID #{ENV["IMGUR_CLIENT_ID"]}", | ||
} | ||
ERROR_CLASS = ImgurError | ||
end | ||
|
||
class ImgurError < HTTPError; end | ||
|
||
error ImgurError do |e| | ||
status 503 | ||
"There was a problem talking to Imgur." | ||
"There was a problem talking to Imgur. Please try again in a moment." | ||
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,13 +1,14 @@ | ||
# https://www.instagram.com/developer/endpoints/ | ||
|
||
class InstagramError < HTTPError; end | ||
|
||
class Instagram < HTTP | ||
BASE_URL = "https://www.instagram.com" | ||
PARAMS = "__a=1" | ||
ERROR_CLASS = InstagramError | ||
end | ||
|
||
class InstagramError < HTTPError; end | ||
|
||
error InstagramError do |e| | ||
status 503 | ||
"There was a problem talking to Instagram." | ||
"There was a problem talking to Instagram. Please try again in a moment." | ||
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,12 +1,13 @@ | ||
# https://www.mixcloud.com/developers/ | ||
|
||
class MixcloudError < HTTPError; end | ||
|
||
class Mixcloud < HTTP | ||
BASE_URL = "https://api.mixcloud.com" | ||
ERROR_CLASS = MixcloudError | ||
end | ||
|
||
class MixcloudError < HTTPError; end | ||
|
||
error MixcloudError do |e| | ||
status 503 | ||
"There was a problem talking to Mixcloud." | ||
"There was a problem talking to Mixcloud. Please try again in a moment." | ||
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 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,13 +1,14 @@ | ||
# https://developers.soundcloud.com/docs/api/reference | ||
|
||
class SoundcloudError < HTTPError; end | ||
|
||
class Soundcloud < HTTP | ||
BASE_URL = "https://api.soundcloud.com" | ||
PARAMS = "client_id=#{ENV["SOUNDCLOUD_CLIENT_ID"]}" | ||
ERROR_CLASS = SoundcloudError | ||
end | ||
|
||
class SoundcloudError < HTTPError; end | ||
|
||
error SoundcloudError do |e| | ||
status 503 | ||
"There was a problem talking to Soundcloud." | ||
"There was a problem talking to SoundCloud. Please try again in a moment." | ||
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 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,16 +1,17 @@ | ||
# https://github.com/justintv/Twitch-API/ | ||
|
||
class TwitchError < HTTPError; end | ||
|
||
class Twitch < HTTP | ||
BASE_URL = "https://api.twitch.tv" | ||
HEADERS = { | ||
"Accept": "application/vnd.twitchtv.v3+json", | ||
"Client-ID": ENV["TWITCH_CLIENT_ID"], | ||
} | ||
ERROR_CLASS = TwitchError | ||
end | ||
|
||
class TwitchError < HTTPError; end | ||
|
||
error TwitchError do |e| | ||
status 503 | ||
"There was a problem talking to Twitch." | ||
"There was a problem talking to Twitch. Please try again in a moment." | ||
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,15 +1,16 @@ | ||
# https://dev.twitter.com/rest/reference/get/statuses/user_timeline | ||
|
||
class TwitterError < HTTPError; end | ||
|
||
class Twitter < HTTP | ||
BASE_URL = "https://api.twitter.com/1.1" | ||
HEADERS = { | ||
"Authorization": "Bearer #{ENV["TWITTER_ACCESS_TOKEN"]}", | ||
} | ||
ERROR_CLASS = TwitterError | ||
end | ||
|
||
class TwitterError < HTTPError; end | ||
|
||
error TwitterError do |e| | ||
status 503 | ||
"There was a problem talking to Twitter." | ||
"There was a problem talking to Twitter. Please try again in a moment." | ||
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,12 +1,13 @@ | ||
# http://ustream.github.io/api-docs/broadcasting-api/channel.html | ||
|
||
class UstreamError < HTTPError; end | ||
|
||
class Ustream < HTTP | ||
BASE_URL = "https://api.ustream.tv" | ||
ERROR_CLASS = UstreamError | ||
end | ||
|
||
class UstreamError < HTTPError; end | ||
|
||
error UstreamError do |e| | ||
status 503 | ||
"There was a problem talking to Ustream." | ||
"There was a problem talking to Ustream. Please try again in a moment." | ||
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,12 +1,13 @@ | ||
# https://docs.vid.me/ | ||
|
||
class VidmeError < HTTPError; end | ||
|
||
class Vidme < HTTP | ||
BASE_URL = "https://api.vid.me" | ||
ERROR_CLASS = VidmeError | ||
end | ||
|
||
class VidmeError < HTTPError; end | ||
|
||
error VidmeError do |e| | ||
status 503 | ||
"There was a problem talking to Vidme." | ||
"There was a problem talking to Vidme. Please try again in a moment." | ||
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,15 +1,16 @@ | ||
# https://developer.vimeo.com/api/start | ||
|
||
class VimeoError < HTTPError; end | ||
|
||
class Vimeo < HTTP | ||
BASE_URL = "https://api.vimeo.com" | ||
HEADERS = { | ||
"Authorization": "bearer #{ENV["VIMEO_ACCESS_TOKEN"]}", | ||
} | ||
ERROR_CLASS = VimeoError | ||
end | ||
|
||
class VimeoError < HTTPError; end | ||
|
||
error VimeoError do |e| | ||
status 503 | ||
"There was a problem talking to Vimeo." | ||
"There was a problem talking to Vimeo. Please try again in a moment." | ||
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,3 @@ | ||
require "addressable/uri" | ||
require "net/http" | ||
require "resolv-replace.rb" | ||
|
||
|
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