class ShopifyClient::Client

Public Class Methods

new(url, token, options = {}) click to toggle source
# File lib/shopify_client/client.rb, line 34
def initialize(url, token, options = {})
  @token = token
  @url = self.class.normalize_url url
end
normalize_url(url) click to toggle source
# File lib/shopify_client/client.rb, line 26
def self.normalize_url(url)
   myshopify_domain = url.match(/(https?:\/\/)?(.+\.myshopify\.com)/)
   if myshopify_domain
     myshopify_domain = myshopify_domain[2]
     "https://#{myshopify_domain}/admin"
   end
end

Public Instance Methods

delete(path, params={}) click to toggle source

Perform an HTTP DELETE request

# File lib/shopify_client/client.rb, line 55
def delete(path, params={})
  request(:delete, path, params)
end
get(path, params={}) click to toggle source

Perform an HTTP GET request

# File lib/shopify_client/client.rb, line 40
def get(path, params={})
  request(:get, path, params)
end
post(path, params={}) click to toggle source

Perform an HTTP POST request

# File lib/shopify_client/client.rb, line 45
def post(path, params={})
  request(:post, path, params)
end
put(path, params={}) click to toggle source

Perform an HTTP PUT request

# File lib/shopify_client/client.rb, line 50
def put(path, params={})
  request(:put, path, params)
end

Private Instance Methods

connection() click to toggle source
# File lib/shopify_client/client.rb, line 65
def connection
  @connection ||= Faraday.new(@url, connection_options)
end
connection_middleware() click to toggle source
# File lib/shopify_client/client.rb, line 80
def connection_middleware
  @builder ||= Faraday::Builder.new do |builder|
    builder.use ShopifyClient::Request::ContentType
    builder.use ShopifyClient::Response::RaiseError
    builder.use ShopifyClient::Response::ParseJson
    builder.adapter Faraday.default_adapter
  end
end
connection_options() click to toggle source
# File lib/shopify_client/client.rb, line 69
def connection_options
  {
    :headers => {
      :accept => 'application/json',
      :user_agent => "ShopifyClient Ruby Gem #{ShopifyClient::VERSION}",
      'X-Shopify-Access-Token' => @token
    },
    :builder => connection_middleware
  }
end
request(method, path, params) click to toggle source
# File lib/shopify_client/client.rb, line 61
def request(method, path, params)
  connection.send(method.to_sym, path, params).env
end