|
| 1 | +# Adding a New API Version to Shopify API Ruby |
| 2 | + |
| 3 | +## Overview |
| 4 | +This guide provides step-by-step instructions for adding a new API version to the Shopify API Ruby library. This example uses the addition of the 2025-07 API version as a reference, but the process applies to any new API version. |
| 5 | + |
| 6 | +## Prerequisites |
| 7 | +- Understanding of any breaking changes or removed resources in the new API version |
| 8 | + |
| 9 | +## Step 1: Update API Version Constants |
| 10 | + |
| 11 | +### Update admin_versions.rb |
| 12 | +Edit `lib/shopify_api/admin_versions.rb` to add your new version: |
| 13 | + |
| 14 | +```ruby |
| 15 | +module ShopifyAPI |
| 16 | + module AdminVersions |
| 17 | + SUPPORTED_ADMIN_VERSIONS = T.let([ |
| 18 | + "unstable", |
| 19 | + "2025-10", # Add new version here |
| 20 | + "2025-07", |
| 21 | + "2025-04", |
| 22 | + # ... other versions |
| 23 | + ], T::Array[String]) |
| 24 | + |
| 25 | + LATEST_SUPPORTED_ADMIN_VERSION = T.let("2025-07", String) # Update if this is the latest stable |
| 26 | + RELEASE_CANDIDATE_ADMIN_VERSION = T.let("2025-10", String) # Update if this is RC |
| 27 | + end |
| 28 | +end |
| 29 | +``` |
| 30 | + |
| 31 | +**Version Management:** |
| 32 | +- Add new versions to the top of `SUPPORTED_ADMIN_VERSIONS` |
| 33 | +- Update `LATEST_SUPPORTED_ADMIN_VERSION` when the version is stable |
| 34 | +- Update `RELEASE_CANDIDATE_ADMIN_VERSION` for release candidates |
| 35 | + |
| 36 | +## Step 2: Create Directory Structure |
| 37 | + |
| 38 | +### Create Resource Directory |
| 39 | +```bash |
| 40 | +mkdir lib/shopify_api/rest/resources/{YYYY_MM}/ |
| 41 | +``` |
| 42 | +Example: `lib/shopify_api/rest/resources/2025_07/` |
| 43 | + |
| 44 | +### Create Test Directory |
| 45 | +```bash |
| 46 | +mkdir test/rest/{YYYY_MM}/ |
| 47 | +``` |
| 48 | +Example: `test/rest/2025_07/` |
| 49 | + |
| 50 | +**Directory Naming Convention:** |
| 51 | +- Format: `YYYY_MM` (e.g., `2025_04`, `2025_07`, `2025_10`) |
| 52 | +- Use underscore between year and month |
| 53 | + |
| 54 | +## Step 3: Copy Resource Files from Previous Version |
| 55 | + |
| 56 | +### Copy All Resource Files |
| 57 | +```bash |
| 58 | +# Copy resource files |
| 59 | +cp -r lib/shopify_api/rest/resources/{PREVIOUS_VERSION}/* lib/shopify_api/rest/resources/{NEW_VERSION}/ |
| 60 | + |
| 61 | +# Copy test files |
| 62 | +cp -r test/rest/{PREVIOUS_VERSION}/* test/rest/{NEW_VERSION}/ |
| 63 | +``` |
| 64 | + |
| 65 | +Example: |
| 66 | +```bash |
| 67 | +cp -r lib/shopify_api/rest/resources/2025_04/* lib/shopify_api/rest/resources/2025_07/ |
| 68 | +cp -r test/rest/2025_04/* test/rest/2025_07/ |
| 69 | +``` |
| 70 | + |
| 71 | +## Step 4: Update Test Files |
| 72 | + |
| 73 | +After copying test files, you must update version-specific information in each test file. |
| 74 | + |
| 75 | +### Update Test Class Names |
| 76 | +Change the class name to include the new version: |
| 77 | + |
| 78 | +```ruby |
| 79 | +# From |
| 80 | +class AbandonedCheckout202504Test < Test::Unit::TestCase |
| 81 | + |
| 82 | +# To |
| 83 | +class AbandonedCheckout202507Test < Test::Unit::TestCase |
| 84 | +``` |
| 85 | + |
| 86 | +**Naming Pattern:** `{ResourceName}{YYYYMM}Test` |
| 87 | +- Remove underscores from the version (e.g., `202507` not `2025_07`) |
| 88 | + |
| 89 | +### Update Context API Version |
| 90 | +In the `setup` method, update the API version: |
| 91 | + |
| 92 | +```ruby |
| 93 | +def setup |
| 94 | + super |
| 95 | + test_session = ShopifyAPI::Auth::Session.new(id: "id", shop: "test-shop.myshopify.io", access_token: "this_is_a_test_token") |
| 96 | + ShopifyAPI::Context.activate_session(test_session) |
| 97 | + |
| 98 | + # Update this line: |
| 99 | + modify_context(api_version: "2025-07") # Was "2025-04" |
| 100 | +end |
| 101 | +``` |
| 102 | + |
| 103 | +### Update URLs in Stub Requests |
| 104 | +Update all API URLs in the test methods: |
| 105 | + |
| 106 | +```ruby |
| 107 | +# From |
| 108 | +stub_request(:get, "https://test-shop.myshopify.io/admin/api/2025-04/checkouts.json") |
| 109 | + |
| 110 | +# To |
| 111 | +stub_request(:get, "https://test-shop.myshopify.io/admin/api/2025-07/checkouts.json") |
| 112 | +``` |
| 113 | + |
| 114 | +## Step 5: Handle Breaking Changes |
| 115 | + |
| 116 | +### Identify Removed Resources |
| 117 | +In this example, `CustomerAddress` was removed in 2025-07. |
| 118 | + |
| 119 | +### Remove Deprecated Resources |
| 120 | +If a resource is removed: |
| 121 | +```bash |
| 122 | +# Remove resource file |
| 123 | +rm lib/shopify_api/rest/resources/{NEW_VERSION}/{resource_name}.rb |
| 124 | + |
| 125 | +# Remove test file |
| 126 | +rm test/rest/{NEW_VERSION}/{resource_name}_test.rb |
| 127 | +``` |
| 128 | + |
| 129 | +### Update Modified Resources |
| 130 | +If a resource has structural changes: |
| 131 | +1. Update the resource class attributes |
| 132 | +2. Modify the `@paths` array if endpoints changed |
| 133 | +3. Update method signatures if parameters changed |
| 134 | +4. Adjust test cases accordingly |
| 135 | + |
| 136 | +## Step 7: Run Tests |
| 137 | + |
| 138 | +### Execute Test Suite |
| 139 | +```bash |
| 140 | +# Run all tests |
| 141 | +bundle exec rake test |
| 142 | + |
| 143 | +# Run specific version tests |
| 144 | +bundle exec rake test TEST=test/rest/{NEW_VERSION}/* |
| 145 | +``` |
| 146 | + |
| 147 | +## Checklist |
| 148 | + |
| 149 | +- [ ] Added new version to `SUPPORTED_ADMIN_VERSIONS` in `admin_versions.rb` |
| 150 | +- [ ] Updated `LATEST_SUPPORTED_ADMIN_VERSION` if applicable |
| 151 | +- [ ] Updated `RELEASE_CANDIDATE_ADMIN_VERSION` if applicable |
| 152 | +- [ ] Created `lib/shopify_api/rest/resources/{NEW_VERSION}/` directory |
| 153 | +- [ ] Created `test/rest/{NEW_VERSION}/` directory |
| 154 | +- [ ] Copied all resource files from previous version |
| 155 | +- [ ] Copied all test files from previous version |
| 156 | +- [ ] Updated test class names (e.g., `Article202507Test`) |
| 157 | +- [ ] Updated API version in test contexts (`modify_context(api_version: "2025-07")`) |
| 158 | +- [ ] Updated all API URLs in test stub requests |
| 159 | +- [ ] Removed deprecated resources and their tests |
| 160 | +- [ ] Updated any modified resources |
| 161 | +- [ ] Run test suite successfully |
0 commit comments