Created
December 23, 2018 13:44
-
-
Save monorkin/9bacab569b6fd893ef3b46740c79e76b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Wrapper around a HTTP library | |
class ApiClient; ... end | |
# Knows how to decode JSON responses from the API | |
class JSONApiClient < ApiClient; ... end | |
# Knows how to decode XML responses from the API | |
class XMLApiClient < ApiClient; ... end | |
# Exposes an API's endpoints as methods on an object | |
class MyAppApiClient | |
attr_reader :json_client | |
attr_reader :xml_client | |
def initialize(api_token) | |
@json_client = JSONApiClient.new(api_token) | |
@xml_client = XMLApiClient.new(api_token) | |
end | |
def current_account | |
json_client.get('/api/current_account') | |
end | |
def balance | |
xml_client.get('/api/current_account/balance') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment