Prechádzať zdrojové kódy

Removing global limit from ShopifyAPI::Limits

Denis Odorcic 13 rokov pred
rodič
commit
f775747973
2 zmenil súbory, kde vykonal 7 pridanie a 16 odobranie
  1. 4 7
      lib/shopify_api/limits.rb
  2. 3 9
      test/limits_test.rb

+ 4 - 7
lib/shopify_api/limits.rb

@@ -9,7 +9,6 @@ module ShopifyAPI
       # Takes form num_requests_executed/max_requests
       # Eg: 101/3000
       CREDIT_LIMIT_HEADER_PARAM = {
-        :global => 'http_x_shopify_api_call_limit',
         :shop => 'http_x_shopify_shop_api_call_limit'
       }
 
@@ -18,9 +17,7 @@ module ShopifyAPI
       # @return {Integer}
       #
       def credit_left
-        shop = credit_limit(:shop) - credit_used(:shop)
-        global = credit_limit(:global) - credit_used(:global)      
-        shop < global ? shop : global
+        credit_limit(:shop) - credit_used(:shop)
       end
       alias_method :available_calls, :credit_left
       
@@ -35,8 +32,8 @@ module ShopifyAPI
       
       ##
       # How many total API calls can I make?
-      # NOTE: subtracting 1 from credit_limit because I think ShopifyAPI cuts off at 299/2999 or shop/global limits.
-      # @param {Symbol} scope [:shop|:global]
+      # NOTE: subtracting 1 from credit_limit because I think ShopifyAPI cuts off at 299 or shop limits.
+      # @param {Symbol} scope [:shop]
       # @return {Integer}
       #
       def credit_limit(scope=:shop)
@@ -47,7 +44,7 @@ module ShopifyAPI
 
       ##
       # How many API calls have I made?
-      # @param {Symbol} scope [:shop|:global]
+      # @param {Symbol} scope [:shop]
       # @return {Integer}
       #
       def credit_used(scope=:shop)

+ 3 - 9
test/limits_test.rb

@@ -4,20 +4,17 @@ require 'mocha'
 class LimitsTest < Test::Unit::TestCase
   def setup
     ShopifyAPI::Base.site = "test.myshopify.com"
-    @header_hash = {'http_x_shopify_api_call_limit' => '150/3000',
-                    'http_x_shopify_shop_api_call_limit' => '100/300'}
+    @header_hash = {'http_x_shopify_shop_api_call_limit' => '100/300'}
     ShopifyAPI::Base.connection.expects(:response).at_least(0).returns(@header_hash)
   end
   
   context "Limits" do
     should "fetch limit total" do
       assert_equal(299, ShopifyAPI.credit_limit(:shop))
-      assert_equal(2999, ShopifyAPI.credit_limit(:global))
     end
     
     should "fetch used calls" do
       assert_equal(100, ShopifyAPI.credit_used(:shop))
-      assert_equal(150, ShopifyAPI.credit_used(:global))
     end
     
     should "calculate remaining calls" do
@@ -26,12 +23,9 @@ class LimitsTest < Test::Unit::TestCase
     
     should "flag maxed out credits" do
       assert !ShopifyAPI.maxed?
-      @header_hash = {'http_x_shopify_api_call_limit' => '2999/3000',
-                      'http_x_shopify_shop_api_call_limit' => '299/300'}
+      @header_hash = {'http_x_shopify_shop_api_call_limit' => '299/300'}
       ShopifyAPI::Base.connection.expects(:response).at_least(1).returns(@header_hash)
       assert ShopifyAPI.maxed?
     end
   end
-  
-  
-end
+end