Class: Shopify

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

Overview

Class: Shopify Usage:

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

Defined Under Namespace

Classes: Article, CustomCollection, ShopifyModel

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.



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

def initialize(host, key=nil, secret=nil, token=nil)
  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



33
34
35
# File 'lib/shopify.rb', line 33

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

#authorize!(token) ⇒ Object



28
29
30
31
# File 'lib/shopify.rb', line 28

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

#needs_authorization?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/shopify.rb', line 24

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

#options(opts = {}) ⇒ Object



46
47
48
# File 'lib/shopify.rb', line 46

def options(opts={})
  {:base_uri => @base_uri, :basic_auth => @basic_auth, :format => @format}.merge(opts)
end