Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.project
tmp
nbproject/
.env
5 changes: 5 additions & 0 deletions .sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SHOPIFY_APIKEY=
SHOPIFY_PASSWORD=
SHOPIFY_HOST=
SHOPIFY_WAIT='0.5'
CREATE_SHIPMENTS='1'
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ gem 'capistrano'
gem 'rest-client'
gem 'require_all'

group :development do
group :development, :test do
gem 'shotgun'
gem 'pry'
gem 'pry-byebug'
gem 'awesome_print'
gem 'dotenv'
end

group :test do
Expand All @@ -30,4 +32,4 @@ group :production do
gem 'unicorn'
end

gem 'endpoint_base', github: 'spree/endpoint_base'
gem 'endpoint_base', github: 'spree/endpoint_base'
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ GEM
tzinfo (~> 1.1)
addressable (2.3.6)
awesome_print (1.2.0)
byebug (9.0.5)
capistrano (3.2.1)
i18n
rake (>= 10.0.0)
Expand Down Expand Up @@ -67,6 +68,9 @@ GEM
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-byebug (3.4.0)
byebug (~> 9.0)
pry (~> 0.10)
rack (1.5.2)
rack-protection (1.5.3)
rack
Expand Down Expand Up @@ -130,11 +134,13 @@ PLATFORMS
DEPENDENCIES
awesome_print
capistrano
dotenv
endpoint_base!
foreman (= 0.66.0)
guard-rspec
jbuilder (= 2.0.7)
pry
pry-byebug
rack-test
rb-fsevent (~> 0.9.1)
require_all
Expand All @@ -148,3 +154,6 @@ DEPENDENCIES
unicorn
vcr
webmock

BUNDLED WITH
1.11.2
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The following parameters must be setup within [Wombat](http://wombat.co):
| shopify_apikey | Shopify account API key (required) |
| shopify_password | Shopify account password (required) |
| shopify_host | Shopify account host, no 'http://' (required) |
| shopify_wait | Shopify API wait between calls, `0.5` for 0.5 second |

## Webhooks

Expand Down
2 changes: 1 addition & 1 deletion config/unicorn.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
worker_processes ENV.fetch('WORKER_PROCESSES', 3).to_i
worker_processes ENV.fetch('WORKER_PROCESSES', 1).to_i
timeout 180

preload_app true
Expand Down
12 changes: 12 additions & 0 deletions lib/shopify/api_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@ def api_get resource, data = {}
end
end

throttle_api_calls

response = RestClient.get shopify_url + (final_resource resource) + params
JSON.parse response.force_encoding("utf-8")
end

def api_post resource, data
throttle_api_calls

response = RestClient.post shopify_url + resource, data.to_json,
:content_type => :json, :accept => :json
JSON.parse response.force_encoding("utf-8")
end

def api_put resource, data
throttle_api_calls

response = RestClient.put shopify_url + resource, data.to_json,
:content_type => :json, :accept => :json
JSON.parse response.force_encoding("utf-8")
Expand All @@ -41,6 +47,12 @@ def final_resource resource
end
resource
end

private

def throttle_api_calls
sleep Util.shopify_wait @config if Util.shopify_wait(@config).present?
end
end
end

4 changes: 2 additions & 2 deletions lib/shopify_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def set_inventory
end

def add_metafield obj_name, shopify_id, wombat_id
api_obj_name = (obj_name == "inventory" ? "product" : obj_name)
api_obj_name = (obj_name == "inventory" ? "variant" : obj_name)

api_post "#{api_obj_name}s/#{shopify_id}/metafields.json",
Metafield.new(@payload[obj_name]['id']).shopify_obj
Expand All @@ -199,7 +199,7 @@ def add_metafield obj_name, shopify_id, wombat_id
def wombat_id_metafield obj_name, shopify_id
wombat_id = nil

api_obj_name = (obj_name == "inventory" ? "product" : obj_name)
api_obj_name = (obj_name == "inventory" ? "variant" : obj_name)

metafields_array = api_get "#{api_obj_name}s/#{shopify_id}/metafields"
unless metafields_array.nil? || metafields_array['metafields'].nil?
Expand Down
4 changes: 4 additions & 0 deletions lib/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@ def self.shopify_host wombat_config
wombat_config['shopify_host']
end

def self.shopify_wait wombat_config
wombat_config['shopify_wait'].to_f
end

end
2 changes: 1 addition & 1 deletion shopify_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def shopify_action action, obj_name
response['objects'].each do |obj|
## Check if object has a metafield with a Wombat ID in it,
## if so change object ID to that prior to adding to Wombat
wombat_id = shopify.wombat_id_metafield obj_name, obj['shopify_id']
wombat_id = shopify.wombat_id_metafield obj_name, obj['shopify_id'] if obj_name != "shipment"
unless wombat_id.nil?
obj['id'] = wombat_id
end
Expand Down
Loading