How to grab shop methods

Shopify Partner
7 0 0

I've been playing around with the  Shopify API and have had some great success as im pretty new to RoR programming and using API's.

I have been trying to get information from the shop object but am not sure on what the correct method is to do this. For example i currently have @shop = ShopifyAPI::Shop and am stuck from here on

For getting product  information I can use find and parse in the params for the query I want to execute

I appreciate any help / pointer you can give

Nath

 

 

 

0 Likes
Shopify Partner
7 0 0

Sorry,

@shop = ShopifyAPI::Shop.current does the job

 

 

0 Likes
Shopify Staff
Shopify Staff
5704 0 281

Nath, I assume you used shopify_app to build you application?

It seems like you can access current_shop.shop from any view or controller within the Shopify app, and that gives you the 'shop' resource. It is the same as ShopifyAPI::Shop.current.

current_shop.shop is an Active Resource, and as such all these methods can be used on it: http://api.rubyonrails.org/classes/ActiveResource/Base.html

One of these methods is to_xml. So you can look at the XML response Shopify sent to your application:

<code><%=h current_shop.shop.to_xml %></code>

Of course, you can also look up the API documentation to see right away what kind of XML you should have received: http://api.shopify.com/shop.html

Looking at all this, you see that you can output the shop name like this, for example:

<p>Shop Name: <%= current_shop.shop.name %></p>

You can also get your resource as JSON to use in your JavaScript:

<script type="text/javascript" charset="utf-8">
//<![CDATA[
var shop = <%= current_shop.shop.to_json %>;
console.log(shop.name);
//]]>
</script>
Caroline from http://11heavens.com ∴ mllegeorgesand AT gmail DOT com
0 Likes
Shopify Partner
7 0 0

Thanks Caroline, Thats is really helpfull info.

0 Likes