shopifydev 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/shopifydev/faker.rb +18 -2
- data/lib/shopifydev/pry/commands.rb +11 -13
- data/lib/shopifydev/shopify_api/consume_api.rb +31 -0
- data/lib/shopifydev/version.rb +1 -1
- metadata +5 -4
data/lib/shopifydev/faker.rb
CHANGED
@@ -57,12 +57,19 @@ module Shopifydev
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def metafield_import_csv(resources, opts={})
|
60
|
-
opts[:import_type] ||= :
|
60
|
+
opts[:import_type] ||= :product_variant_multikey
|
61
61
|
opts[:num] ||= 1
|
62
62
|
opts[:namespace] ||= namespace
|
63
|
+
opts[:keys] ||= [key]
|
64
|
+
opts[:keys] = [opts[:keys]].flatten
|
65
|
+
|
66
|
+
resources = [resources].flatten
|
63
67
|
|
64
68
|
out = ""
|
65
69
|
|
70
|
+
while(opts[:keys].length < opts[:num]); opts[:keys] << key; end
|
71
|
+
puts "opts: #{opts.inspect}" if opts[:verbose]
|
72
|
+
|
66
73
|
case opts[:import_type]
|
67
74
|
when :owner_resource
|
68
75
|
when :product_handle
|
@@ -87,7 +94,16 @@ module Shopifydev
|
|
87
94
|
raise "don't know how to create import csv for #{opts[:type].to_s}"
|
88
95
|
end
|
89
96
|
|
90
|
-
|
97
|
+
if opts[:file]
|
98
|
+
opts[:file] << ".csv" unless opts[:file].include?('.csv')
|
99
|
+
File.open(opts[:file], 'w') { |file|
|
100
|
+
file.write(out)
|
101
|
+
}
|
102
|
+
puts "wrote #{out.lines.to_a.length - 1} records to #{opts[:file]}"
|
103
|
+
nil
|
104
|
+
else
|
105
|
+
out
|
106
|
+
end
|
91
107
|
end
|
92
108
|
end
|
93
109
|
end
|
@@ -380,19 +380,17 @@ shopifydev_command_set = Pry::CommandSet.new do
|
|
380
380
|
end
|
381
381
|
|
382
382
|
block_command "consume_api", "use up Shopify API calls until only [x] remain (default 0)" do |num|
|
383
|
-
|
384
|
-
num
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
h.run
|
395
|
-
end
|
383
|
+
require "shopifydev/shopify_api/consume_api"
|
384
|
+
report = Shopifydev::ShopifyAPI::ConsumeAPI.consume(num) do |report_line|
|
385
|
+
case report_line.first.first
|
386
|
+
when :info
|
387
|
+
puts Color.yellow{ report_line.first.last }
|
388
|
+
when :status
|
389
|
+
puts Color.blue{ report_line.first.last }
|
390
|
+
else
|
391
|
+
puts report_line.first.last
|
392
|
+
end
|
393
|
+
end
|
396
394
|
end
|
397
395
|
|
398
396
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Shopifydev
|
2
|
+
module ShopifyAPI
|
3
|
+
module ConsumeAPI
|
4
|
+
def self.consume(num=nil)
|
5
|
+
report = []
|
6
|
+
num ||= 1
|
7
|
+
num = num.to_i
|
8
|
+
report << {info: "consuming api calls until only #{num} are left..."}
|
9
|
+
yield report.last if block_given?
|
10
|
+
res = Shydra::Resources::Product.new.run
|
11
|
+
pids = res.data.map{|r| r['id']}
|
12
|
+
used, max = res.headers['HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT'].split('/').map(&:to_i)
|
13
|
+
report << {debug: "used: #{used.inspect} max: #{max.inspect}"}
|
14
|
+
yield report.last if block_given?
|
15
|
+
h = Shydra::Hydra.new(max_concurrency: 50)
|
16
|
+
to_consume = max - used - num - 2
|
17
|
+
report << {debug: "queueing to_consume: #{to_consume.inspect} requests"}
|
18
|
+
yield report.last if block_given?
|
19
|
+
if to_consume > 0
|
20
|
+
to_consume.times{ h.queue(Shydra::Resources::Product.new(id: pids.sample)) }
|
21
|
+
h.run
|
22
|
+
::ShopifyAPI::Shop.current
|
23
|
+
end
|
24
|
+
report << {status: "credit_left: #{::ShopifyAPI.credit_left}"}
|
25
|
+
yield report.last if block_given?
|
26
|
+
|
27
|
+
return report
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/shopifydev/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopifydev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -294,6 +294,7 @@ files:
|
|
294
294
|
- lib/shopifydev/railtie.rb
|
295
295
|
- lib/shopifydev/shop.rb
|
296
296
|
- lib/shopifydev/shopify_api/caches.rb
|
297
|
+
- lib/shopifydev/shopify_api/consume_api.rb
|
297
298
|
- lib/shopifydev/spec/helpers.rb
|
298
299
|
- lib/shopifydev/template.rb
|
299
300
|
- lib/shopifydev/version.rb
|
@@ -320,7 +321,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
320
321
|
version: '0'
|
321
322
|
segments:
|
322
323
|
- 0
|
323
|
-
hash:
|
324
|
+
hash: -3704745161446576111
|
324
325
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
325
326
|
none: false
|
326
327
|
requirements:
|
@@ -329,7 +330,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
329
330
|
version: '0'
|
330
331
|
segments:
|
331
332
|
- 0
|
332
|
-
hash:
|
333
|
+
hash: -3704745161446576111
|
333
334
|
requirements: []
|
334
335
|
rubyforge_project:
|
335
336
|
rubygems_version: 1.8.25
|