Class: ShopifyAPI::Clients::Graphql::Storefront
- Defined in:
- lib/shopify_api/clients/graphql/storefront.rb
Instance Method Summary collapse
-
#initialize(shop, private_token: nil, public_token: nil, api_version: nil) ⇒ Storefront
constructor
A new instance of Storefront.
- #query(query:, variables: nil, headers: {}, tries: 1, response_as_struct: Context.response_as_struct, debug: false) ⇒ Object
Constructor Details
#initialize(shop, private_token: nil, public_token: nil, api_version: nil) ⇒ Storefront
Returns a new instance of Storefront.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/shopify_api/clients/graphql/storefront.rb', line 16 def initialize(shop, private_token: nil, public_token: nil, api_version: nil) token = private_token || public_token if token.nil? raise ArgumentError, "Storefront client requires either private_token or public_token to be provided" end session = Auth::Session.new( id: shop, shop: shop, access_token: "", is_online: false, ) super(session: session, base_path: "/api", api_version: api_version) @storefront_access_token = T.let(token, String) @storefront_auth_header = T.let( private_token.nil? ? "X-Shopify-Storefront-Access-Token" : "Shopify-Storefront-Private-Token", String, ) end |
Instance Method Details
#query(query:, variables: nil, headers: {}, tries: 1, response_as_struct: Context.response_as_struct, debug: false) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/shopify_api/clients/graphql/storefront.rb', line 46 def query( query:, variables: nil, headers: {}, tries: 1, response_as_struct: Context.response_as_struct, debug: false ) T.must(headers).merge!({ @storefront_auth_header => @storefront_access_token }) super(query: query, variables: variables, headers: headers, tries: tries, response_as_struct: response_as_struct, debug: debug) end |