Class: Shopify

Inherits:
Object show all
Defined in:
lib/shopify.rb,
lib/shopify/support.rb

Overview

Class: Shopify Usage:

shop = Shopify.new(host, [key, [secret, [token]]])
shop.orders

TODO: Make the object remember the results of queries such as shop.orders when called without parameters,

and reload only when you call shop.orders(true)

Defined Under Namespace

Classes: Article, Blog, Collect, Comment, Country, CustomCollection, Fulfillment, Image, LineItem, Order, Page, Product, Province, Redirect, Shop, ShopifyModel, Transaction, Variant

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, key = nil, secret = nil, token = nil) ⇒ Shopify

Returns a new instance of Shopify.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/shopify.rb', line 14

def initialize(host, key=nil, secret=nil, token=nil)
  @default_options = {}
  extend HTTParty::ClassMethods

  host.gsub!(/https?:\/\//, '') # remove http(s)://
  @host = host.include?('.') ? host : "#{host}.myshopify.com" # extend url to myshopify.com if no host is given
  @key    = key
  @secret = secret
  @token  = token
  setup
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



12
13
14
# File 'lib/shopify.rb', line 12

def host
  @host
end

Instance Method Details

#authorization_url(mode = 'w') ⇒ Object



35
36
37
# File 'lib/shopify.rb', line 35

def authorization_url(mode='w')
  "http://#{@host}/admin/api/auth?api_key=#{@key}&mode=#{mode}"
end

#authorize!(token) ⇒ Object



30
31
32
33
# File 'lib/shopify.rb', line 30

def authorize!(token)
  @token = token
  setup
end

#needs_authorization?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/shopify.rb', line 26

def needs_authorization?
  ![@host, @key, @secret, @token].all?
end