Last active
August 29, 2015 14:09
-
-
Save yock/479d656681b45000926d to your computer and use it in GitHub Desktop.
Thinking Outside the Block v2
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
require 'net/http' | |
response = Net::HTTP.start 'api.example.com', 80 { |http| | |
http.get '/endpoint' | |
} | |
response_base_class = response.class.name.split('::').last | |
begin | |
handler_class = Object.const_get("ApiResponse::#{response_base_class}") | |
handler_class.new(response).handle | |
rescue NameError => e | |
ApiResponse::DefaultHandler.new(response).handle | |
end | |
module ApiResponse | |
class DefaultHandler | |
# ... | |
end | |
class HTTPOK | |
# ... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment