Class: ActiveFulfillment::ShopifyAPIService

Inherits:
Service
  • Object
show all
Defined in:
lib/active_fulfillment/services/shopify_api.rb

Constant Summary collapse

OrderIdCutoffDate =
Date.iso8601('2015-03-01').freeze
MAX_LOGGED_RESPONSE_LENGTH =
70
RESCUABLE_CONNECTION_ERRORS =
[
  Net::ReadTimeout,
  Net::OpenTimeout,
  Errno::ETIMEDOUT,
  Timeout::Error,
  IOError,
  EOFError,
  SocketError,
  Errno::ECONNRESET,
  Errno::ECONNABORTED,
  Errno::EPIPE,
  Errno::ECONNREFUSED,
  Errno::EAGAIN,
  Errno::EHOSTUNREACH,
  Errno::ENETUNREACH,
  Resolv::ResolvError,
  Net::HTTPBadResponse,
  Net::HTTPHeaderSyntaxError,
  Net::ProtocolError,
  ActiveUtils::ConnectionError,
  ActiveUtils::ResponseError,
  ActiveUtils::InvalidResponseError
].freeze

Instance Method Summary collapse

Methods inherited from Service

#fetch_tracking_numbers, #test?, #test_mode?, #valid_credentials?

Constructor Details

#initialize(options = {}) ⇒ ShopifyAPIService

Returns a new instance of ShopifyAPIService.



35
36
37
38
39
# File 'lib/active_fulfillment/services/shopify_api.rb', line 35

def initialize(options = {})
  @name = options[:name]
  @callback_url = options[:callback_url]
  @format = options[:format]
end

Instance Method Details

#fetch_stock_levels(options = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/active_fulfillment/services/shopify_api.rb', line 45

def fetch_stock_levels(options = {})
  response = send_app_request('fetch_stock'.freeze, options.delete(:headers), options)
  if response
    stock_levels = parse_response(response, 'StockLevels'.freeze, 'Product'.freeze, 'Sku'.freeze, 'Quantity'.freeze) { |p| p.to_i }
    Response.new(true, 'API stock levels'.freeze, {:stock_levels => stock_levels})
  else
    Response.new(false, 'Unable to fetch remote stock levels'.freeze)
  end
end

#fetch_tracking_data(order_numbers, options = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/active_fulfillment/services/shopify_api.rb', line 55

def fetch_tracking_data(order_numbers, options = {})
  options.merge!({:order_names => order_numbers})
  response = send_app_request('fetch_tracking_numbers'.freeze, options.delete(:headers), options)
  if response
    tracking_numbers = parse_response(response, 'TrackingNumbers'.freeze, 'Order'.freeze, 'ID'.freeze, 'Tracking'.freeze) { |o| o }
    Response.new(true, 'API tracking_numbers'.freeze, {:tracking_numbers => tracking_numbers,
                                                       :tracking_companies => {},
                                                       :tracking_urls => {}})
  else
    Response.new(false, "Unable to fetch remote tracking numbers #{order_numbers.inspect}")
  end
end

#fulfill(order_id, shipping_address, line_items, options = {}) ⇒ Object

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/active_fulfillment/services/shopify_api.rb', line 41

def fulfill(order_id, shipping_address, line_items, options = {})
  raise NotImplementedError.new('Shopify API Service must listen to fulfillment/create Webhooks'.freeze)
end