weixin_39596720 2020-11-20 21:30
浏览 0

Add ApiVersion coercion_modes and fetch_known_versions from Shopify

This PR allows us to dynamically define api_versions based on the response from https://app.shopify.com/services/apis.json

This removes the need to manually updated the gem every time a new version is released or set to end of life.

When the gem is required, we define a set of known versions from the unauthenticated services/apis.json endpoint and everything behaves more or less like it did before. If an unknown version is attempted to be set (ie as of today, 2020-04 or taco-42) an UnknownVersion error is raised with all known versions as message.

If for some reason the known_version_set cannot be initialized at start, then we default to assuming the version is valid, and rely on the server to handle the request and return an error if necessary. Developers can retry defining the version set by calling ShopifyAPI::ApiVersion.define_known_versions at anytime. Any version that was fetched from the server will have persisted? return true, and any on the fly version instances would return false.

ApiVersion attributes were solidified internally at shopify I think after version support was added to the gem, so I also deprecated and aliased methods like #name and #stable? to #handle and #supported?

该提问来源于开源项目:Shopify/shopify_api

  • 写回答

6条回答 默认 最新

  • weixin_39596720 2020-11-20 21:30
    关注

    updated per 's comments on slack. ApiVersion now supports two coercion modes. The default will just accept whatever handle you give it and leave it to the server to deal with any invalid versions, probably what you would want in production since you should have everything tested already.

    The second stricter mode will not allow you to set any version that is not pre-defined. Setting ApiVersion.coercion_mode = :predefined_only will require you to fetch the known versions from Shopify with ApiVersion.define_known_versions. Theres no more remote request when requiring the gem and any developers who want to pre-define versions on boot can do so in an initializer.

    Little more flexibility for different developers for different environments.

    Readme still needs to be updated and this needs a rebase

    评论

报告相同问题?