Skip to content

Instantly share code, notes, and snippets.

@monorkin
Created December 23, 2018 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monorkin/9bacab569b6fd893ef3b46740c79e76b to your computer and use it in GitHub Desktop.
Save monorkin/9bacab569b6fd893ef3b46740c79e76b to your computer and use it in GitHub Desktop.
# 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