-
-
Save craigjbass/5f90eef7b2b17431fb12fb381298d04b to your computer and use it in GitHub Desktop.
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
class HTTPProductGateway | |
def find_by(id:) | |
@id = id | |
product_for(decode(fetch_product_from_api)) | |
end | |
private | |
def product_for(product_payload) | |
Product.new(name: product_payload[:name], description: product_payload[:description]) | |
end | |
def fetch_product_from_api | |
HTTP.get(uri).response.body | |
end | |
def decode(api_product) | |
JSON.decode(api_product) | |
end | |
def uri | |
"https://example.com/api/products/#{@id}" | |
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
class HTTPProductGateway | |
def find_by(id:) | |
product_for(decode(fetch_product_from_api(id))) | |
end | |
private | |
def product_for(product_payload) | |
Domain::Product.new(name: product_payload[:name], description: product_payload[:description]) | |
end | |
def fetch_product_from_api(id) | |
HTTP.get(uri(id)).response.body | |
end | |
def decode(api_product) | |
JSON.decode(api_product) | |
end | |
def uri(id) | |
"https://example.com/api/products/#{id}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment