shopifydev 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -382,13 +382,13 @@ shopifydev_command_set = Pry::CommandSet.new do
382
382
  block_command "consume_api", "use up Shopify API calls until only [x] remain (default 0)" do |num|
383
383
  require "shopifydev/shopify_api/consume_api"
384
384
  report = Shopifydev::ShopifyAPI::ConsumeAPI.consume(num) do |report_line|
385
- case report_line.first.first
385
+ case report_line.level
386
386
  when :info
387
- puts Color.yellow{ report_line.first.last }
387
+ puts Color.yellow{ report_line.msg }
388
388
  when :status
389
- puts Color.blue{ report_line.first.last }
389
+ puts Color.blue{ report_line.msg}
390
390
  else
391
- puts report_line.first.last
391
+ puts report_line.msg
392
392
  end
393
393
  end
394
394
  end
@@ -1,27 +1,34 @@
1
1
  module Shopifydev
2
2
  module ShopifyAPI
3
3
  module ConsumeAPI
4
+ class Report
5
+ attr_accessor :level, :msg
6
+ def initialize(hash)
7
+ @level = hash.first.first
8
+ @msg = hash.first.last
9
+ end
10
+ end
4
11
  def self.consume(num=nil)
5
12
  report = []
6
13
  num ||= 1
7
14
  num = num.to_i
8
- report << {info: "consuming api calls until only #{num} are left..."}
15
+ report << Report.new(info: "consuming api calls until only #{num} are left...")
9
16
  yield report.last if block_given?
10
17
  res = Shydra::Resources::Product.new.run
11
18
  pids = res.data.map{|r| r['id']}
12
19
  used, max = res.headers['HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT'].split('/').map(&:to_i)
13
- report << {debug: "used: #{used.inspect} max: #{max.inspect}"}
20
+ report << Report.new(debug: "used: #{used.inspect} max: #{max.inspect}")
14
21
  yield report.last if block_given?
15
22
  h = Shydra::Hydra.new(max_concurrency: 50)
16
23
  to_consume = max - used - num - 2
17
- report << {debug: "queueing to_consume: #{to_consume.inspect} requests"}
24
+ report << Report.new(debug: "queueing to_consume: #{to_consume.inspect} requests")
18
25
  yield report.last if block_given?
19
26
  if to_consume > 0
20
27
  to_consume.times{ h.queue(Shydra::Resources::Product.new(id: pids.sample)) }
21
28
  h.run
22
29
  ::ShopifyAPI::Shop.current
23
30
  end
24
- report << {status: "credit_left: #{::ShopifyAPI.credit_left}"}
31
+ report << Report.new(status: "credit_left: #{::ShopifyAPI.credit_left}")
25
32
  yield report.last if block_given?
26
33
 
27
34
  return report
@@ -1,3 +1,3 @@
1
1
  module Shopifydev
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
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.12
4
+ version: 0.0.13
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-22 00:00:00.000000000 Z
12
+ date: 2013-07-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -321,7 +321,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
321
321
  version: '0'
322
322
  segments:
323
323
  - 0
324
- hash: -3704745161446576111
324
+ hash: -2770643691399012229
325
325
  required_rubygems_version: !ruby/object:Gem::Requirement
326
326
  none: false
327
327
  requirements:
@@ -330,7 +330,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
330
330
  version: '0'
331
331
  segments:
332
332
  - 0
333
- hash: -3704745161446576111
333
+ hash: -2770643691399012229
334
334
  requirements: []
335
335
  rubyforge_project:
336
336
  rubygems_version: 1.8.25