shopifydev 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,11 @@ require 'shopifydev/pry/commands'
2
2
  require 'shopifydev/pry/save_json'
3
3
  require 'shopifydev/shopify_api/caches'
4
4
 
5
- require 'term/ansicolor'
5
+ require 'term/ansicolor'
6
+
7
+ require 'shydra'
8
+ require 'shydra/hydra'
9
+
6
10
  class Color
7
11
  if Pry.config.color
8
12
  extend Term::ANSIColor
@@ -378,6 +378,22 @@ shopifydev_command_set = Pry::CommandSet.new do
378
378
  UnixTree.print_tree(path) # moved to module so can use in save_json & load_json
379
379
  end
380
380
 
381
+ block_command "consume_api", "use up Shopify API calls until only [x] remain (default 0)" do |num|
382
+
383
+ num ||= 1
384
+ num = num.to_i
385
+ puts Color.yellow{ "consuming api calls until only #{num} are left..."}
386
+ res = Shydra::Resources::Product.new.run
387
+ pids = res.data.map{|r| r['id']}
388
+ used, max = res.headers['HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT'].split('/').map(&:to_i)
389
+ h = Shydra::Hydra.new(max_concurrency: 50)
390
+ to_consume = max - used - num - 1
391
+ if to_consume > 0
392
+ to_consume.times{ h.queue(Shydra::Resources::Product.new(id: pids.sample)) }
393
+ h.run
394
+ end
395
+ end
396
+
381
397
  end
382
398
 
383
399
  Pry::Commands.import shopifydev_command_set
@@ -0,0 +1,12 @@
1
+ module Shopifydev
2
+ module Spec
3
+ module Helpers
4
+ OVER_LIMIT_ERROR_JSON = "{\"^o\":\"ActiveResource::ClientError\",\"^i\":1,\"response\":{\"^o\":\"Net::HTTPClientError\",\"^i\":2,\"http_version\":\"1.1\",\"code\":\"429\",\"message\":\"\",\"header\":{\"^i\":3,\"server\":[\"^i4\",\"nginx\"],\"date\":[\"^i5\",\"Tue, 09 Jul 2013 22:42:36 GMT\"],\"content-type\":[\"^i6\",\"application/json; charset=utf-8\"],\"transfer-encoding\":[\"^i7\",\"chunked\"],\"connection\":[\"^i8\",\"close\"],\"status\":[\"^i9\",\"429\"],\"x-shopid\":[\"^i10\",\"1768504\"],\"x-shopify-asset-version\":[\"^i11\",\"0d635931ada23a3f237940c18cd92a905f097ea1\"],\"retry-after\":[\"^i12\",\"300\"],\"x-request-id\":[\"^i13\",\"f362cbe90cb284e616a2eb65a1c490b9\"],\"x-ua-compatible\":[\"^i14\",\"IE=Edge,chrome=1\"],\"set-cookie\":[\"^i15\",\"_secure_session_id=b0deb3310f612c276cebe32a8a181d4b; path=/; secure; HttpOnly\"]},\"body\":\"{\\\"errors\\\":\\\"Exceeded 5 minutes call limit for api client. Contact support for higher limits.\\\"}\",\"read\":true,\"socket\":null,\"body_exist\":true},\"message\":null,\"~bt\":[\"^i16\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/activeresource-3.2.13/lib/active_resource/connection.rb:146:in `handle_response'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/shopify_api-3.0.3/lib/active_resource/connection_ext.rb:9:in `handle_response_with_response_capture'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/activeresource-3.2.13/lib/active_resource/connection.rb:115:in `request'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/shopify_api-3.0.3/lib/active_resource/connection_ext.rb:13:in `request_with_detailed_log_subscriber'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/activeresource-3.2.13/lib/active_resource/connection.rb:80:in `block in get'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/activeresource-3.2.13/lib/active_resource/connection.rb:218:in `with_auth'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/activeresource-3.2.13/lib/active_resource/connection.rb:80:in `get'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/activeresource-3.2.13/lib/active_resource/base.rb:901:in `find_every'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/activeresource-3.2.13/lib/active_resource/base.rb:814:in `find'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/activeresource-3.2.13/lib/active_resource/base.rb:826:in `first'\",\"(pry):15:in `__binding__'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:328:in `eval'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:328:in `evaluate_ruby'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:278:in `re'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:254:in `rep'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:234:in `block (3 levels) in repl'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:232:in `loop'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:232:in `block (2 levels) in repl'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:231:in `catch'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:231:in `block in repl'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:230:in `catch'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:230:in `repl'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/pry-0.9.12.2/lib/pry/pry_class.rb:170:in `start'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/pry-0.9.12.2/lib/pry/cli.rb:201:in `block in <top (required)>'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/pry-0.9.12.2/lib/pry/cli.rb:70:in `call'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/pry-0.9.12.2/lib/pry/cli.rb:70:in `block in parse_options'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/pry-0.9.12.2/lib/pry/cli.rb:70:in `each'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/pry-0.9.12.2/lib/pry/cli.rb:70:in `parse_options'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/gems/pry-0.9.12.2/bin/pry:16:in `<top (required)>'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/bin/pry:23:in `load'\",\"/Users/lasto/.rvm/gems/ruby-1.9.3-p429@global/bin/pry:23:in `<main>'\"]}"
5
+ class << self
6
+ def over_limit_error
7
+ Oj.load(OVER_LIMIT_ERROR_JSON)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Shopifydev
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
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.9
4
+ version: 0.0.10
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-03 00:00:00.000000000 Z
12
+ date: 2013-07-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -278,6 +278,7 @@ files:
278
278
  - lib/shopifydev/railtie.rb
279
279
  - lib/shopifydev/shop.rb
280
280
  - lib/shopifydev/shopify_api/caches.rb
281
+ - lib/shopifydev/spec/helpers.rb
281
282
  - lib/shopifydev/template.rb
282
283
  - lib/shopifydev/version.rb
283
284
  - shopifydev.gemspec
@@ -303,7 +304,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
303
304
  version: '0'
304
305
  segments:
305
306
  - 0
306
- hash: 3331124851762358064
307
+ hash: -600776122306853732
307
308
  required_rubygems_version: !ruby/object:Gem::Requirement
308
309
  none: false
309
310
  requirements:
@@ -312,7 +313,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
312
313
  version: '0'
313
314
  segments:
314
315
  - 0
315
- hash: 3331124851762358064
316
+ hash: -600776122306853732
316
317
  requirements: []
317
318
  rubyforge_project:
318
319
  rubygems_version: 1.8.25