Last active
November 23, 2017 02:37
-
-
Save SeanLF/b3ab048b8c22f6cef318 to your computer and use it in GitHub Desktop.
This code needs some loving - review the Ruby version and tell us what you would improve.
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 ShopifyAPIClient | |
attr_accessor :shop_id | |
def initialize | |
@params = Hash.new | |
@params[:basic_auth] = {username: ENV['SECRET_API_KEY'], password: ''} | |
@api_url = "https://www.shopify.this.is.a.sample.com/" | |
end | |
def orders | |
orders_json = some_http_library.get("#{@api_url + @shop_id}/orders", @params) | |
return JSON.parse(orders_json) | |
end | |
def products | |
products_json = some_http_library.get("#{@api_url + @shop_id}/products", @params) | |
return JSON.parse(products_json) | |
end | |
def product(id) | |
product_json = some_http_library.get("#{@api_url + @shop_id}/products/#{id}", @params) | |
return JSON.parse(product_json) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
shop_id
from an attribute reader to an attribute accessor. Remove the shop_id setter method (set_shop_id
).ENV["SECRET_API_KEY"]
)initialize
method.initialize
method, declare aparams
intance variable and set it toHash.new
. Set theparams[:basic_auth]
with the username and password. Declare anapi_url
instance variable and set it to"https://www.shopify.this.is.a.sample.com/"
.return
keyword can be omitted.@
to theparams
,api_url
andshop_id
variables when they are used outside of theinitialize
method.