Forráskód Böngészése

Merge pull request #559 from Shopify/override-access-scopes-url

Override versioned prefix for access scopes.
Alex Aitken 6 éve
szülő
commit
b684210db6

+ 4 - 3
README.md

@@ -86,9 +86,10 @@ end
 
 ### URLs that have not changed
 
-- OAuth URLs for `authorize`, getting the `access_token` from a code, and using a `refresh_token` have _not_ changed.
-  - get: `/admin/oauth/authorize`
-  - post: `/admin/oauth/access_token`
+- OAuth URLs for `authorize`, getting the `access_token` from a code, `access_scopes`, and using a `refresh_token` have _not_ changed.
+  - get: `/admin/oauth/authorize.json`
+  - post: `/admin/oauth/access_token.json`
+  - get: `/admin/oauth/access_scopes.json`
 - URLs for the merchant’s web admin have _not_ changed. For example: to send the merchant to the product page the url is still `/admin/product/<id>`
 
 ## Usage

+ 6 - 1
lib/shopify_api/resources/access_scope.rb

@@ -1,5 +1,10 @@
+# frozen_string_literal: true
 module ShopifyAPI
   class AccessScope < Base
-    self.resource_prefix = "oauth/"
+    class << self
+      def prefix(_options={})
+        '/admin/oauth/'
+      end
+    end
   end
 end

+ 23 - 0
test/access_scope_test.rb

@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+require 'test_helper'
+
+class AccessScopeTest < Test::Unit::TestCase
+  test 'access scope does not use the versioned resource urls' do
+    fake(
+      'access_scopes',
+      url: 'https://shop2.myshopify.com/admin/oauth/access_scopes.json',
+      method: :get,
+      status: 201,
+      body: load_fixture('access_scopes'),
+      extension: false
+    )
+
+    unstable_version = ShopifyAPI::Session.new(domain: 'shop2.myshopify.com', token: 'token2', api_version: :unstable)
+
+    ShopifyAPI::Base.activate_session(unstable_version)
+
+    scope_handles = ShopifyAPI::AccessScope.find(:all).map(&:handle)
+
+    assert_equal(['write_product_listings', 'read_shipping'], scope_handles)
+  end
+end

+ 10 - 0
test/fixtures/access_scopes.json

@@ -0,0 +1,10 @@
+{
+  "access_scopes": [
+    {
+      "handle": "write_product_listings"
+    },
+    {
+      "handle": "read_shipping"
+    }
+  ]
+}