Skip to content

Commit

Permalink
Merge pull request #1335 from Shopify/add_current_methods
Browse files Browse the repository at this point in the history
Add `current` methods for shop and recurring application charges
  • Loading branch information
paulomarg authored Aug 20, 2024
2 parents c60a49b + acb314a commit c0e2439
Show file tree
Hide file tree
Showing 41 changed files with 589 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api
- [#1327](https://github.com/Shopify/shopify-api-ruby/pull/1327) Support `?debug=true` parameter in GraphQL client requests
- [#1308](https://github.com/Shopify/shopify-api-ruby/pull/1308) Support hash_with_indifferent_access when creating REST objects from Shopify responses. Closes #1296
- [#1332](https://github.com/Shopify/shopify-api-ruby/pull/1332) Fixed an issue where `Customer` REST API PUT requests didn't send all of the fields in the `email_marketing_consent` attribute
- [#1335](https://github.com/Shopify/shopify-api-ruby/pull/1335) Add back the `current` methods for `Shop` and `RecurringApplicationCharge` resources

## 14.4.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ def all(
T.cast(response, T::Array[RecurringApplicationCharge])
end

sig do
params(session: Auth::Session)
.returns(T.nilable(RecurringApplicationCharge))
end
def current(session: ShopifyAPI::Context.active_session)
charges = all(session: session)
charges.select { |charge| charge.status == "active" }.first
end

end

sig do
Expand Down
10 changes: 10 additions & 0 deletions lib/shopify_api/rest/resources/2022_04/shop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ def all(
T.cast(response, T::Array[Shop])
end

sig do
params(
fields: T.untyped,
session: Auth::Session,
).returns(T.nilable(Shop))
end
def current(fields: nil, session: ShopifyAPI::Context.active_session)
all(session: session, fields: fields).first
end

end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ def all(
T.cast(response, T::Array[RecurringApplicationCharge])
end

sig do
params(session: Auth::Session)
.returns(T.nilable(RecurringApplicationCharge))
end
def current(session: ShopifyAPI::Context.active_session)
charges = all(session: session)
charges.select { |charge| charge.status == "active" }.first
end

end

sig do
Expand Down
10 changes: 10 additions & 0 deletions lib/shopify_api/rest/resources/2022_07/shop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ def all(
T.cast(response, T::Array[Shop])
end

sig do
params(
fields: T.untyped,
session: Auth::Session,
).returns(T.nilable(Shop))
end
def current(fields: nil, session: ShopifyAPI::Context.active_session)
all(session: session, fields: fields).first
end

end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ def all(
T.cast(response, T::Array[RecurringApplicationCharge])
end

sig do
params(session: Auth::Session)
.returns(T.nilable(RecurringApplicationCharge))
end
def current(session: ShopifyAPI::Context.active_session)
charges = all(session: session)
charges.select { |charge| charge.status == "active" }.first
end

end

sig do
Expand Down
10 changes: 10 additions & 0 deletions lib/shopify_api/rest/resources/2022_10/shop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ def all(
T.cast(response, T::Array[Shop])
end

sig do
params(
fields: T.untyped,
session: Auth::Session,
).returns(T.nilable(Shop))
end
def current(fields: nil, session: ShopifyAPI::Context.active_session)
all(session: session, fields: fields).first
end

end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ def all(
T.cast(response, T::Array[RecurringApplicationCharge])
end

sig do
params(session: Auth::Session)
.returns(T.nilable(RecurringApplicationCharge))
end
def current(session: ShopifyAPI::Context.active_session)
charges = all(session: session)
charges.select { |charge| charge.status == "active" }.first
end

end

sig do
Expand Down
10 changes: 10 additions & 0 deletions lib/shopify_api/rest/resources/2023_01/shop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ def all(
T.cast(response, T::Array[Shop])
end

sig do
params(
fields: T.untyped,
session: Auth::Session,
).returns(T.nilable(Shop))
end
def current(fields: nil, session: ShopifyAPI::Context.active_session)
all(session: session, fields: fields).first
end

end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ def all(
T.cast(response, T::Array[RecurringApplicationCharge])
end

sig do
params(session: Auth::Session)
.returns(T.nilable(RecurringApplicationCharge))
end
def current(session: ShopifyAPI::Context.active_session)
charges = all(session: session)
charges.select { |charge| charge.status == "active" }.first
end

end

sig do
Expand Down
10 changes: 10 additions & 0 deletions lib/shopify_api/rest/resources/2023_04/shop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ def all(
T.cast(response, T::Array[Shop])
end

sig do
params(
fields: T.untyped,
session: Auth::Session,
).returns(T.nilable(Shop))
end
def current(fields: nil, session: ShopifyAPI::Context.active_session)
all(session: session, fields: fields).first
end

end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ def all(
T.cast(response, T::Array[RecurringApplicationCharge])
end

sig do
params(session: Auth::Session)
.returns(T.nilable(RecurringApplicationCharge))
end
def current(session: ShopifyAPI::Context.active_session)
charges = all(session: session)
charges.select { |charge| charge.status == "active" }.first
end

end

sig do
Expand Down
10 changes: 10 additions & 0 deletions lib/shopify_api/rest/resources/2023_07/shop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ def all(
T.cast(response, T::Array[Shop])
end

sig do
params(
fields: T.untyped,
session: Auth::Session,
).returns(T.nilable(Shop))
end
def current(fields: nil, session: ShopifyAPI::Context.active_session)
all(session: session, fields: fields).first
end

end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ def all(
T.cast(response, T::Array[RecurringApplicationCharge])
end

sig do
params(session: Auth::Session)
.returns(T.nilable(RecurringApplicationCharge))
end
def current(session: ShopifyAPI::Context.active_session)
charges = all(session: session)
charges.select { |charge| charge.status == "active" }.first
end

end

sig do
Expand Down
10 changes: 10 additions & 0 deletions lib/shopify_api/rest/resources/2023_10/shop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ def all(
T.cast(response, T::Array[Shop])
end

sig do
params(
fields: T.untyped,
session: Auth::Session,
).returns(T.nilable(Shop))
end
def current(fields: nil, session: ShopifyAPI::Context.active_session)
all(session: session, fields: fields).first
end

end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ def all(
T.cast(response, T::Array[RecurringApplicationCharge])
end

sig do
params(session: Auth::Session)
.returns(T.nilable(RecurringApplicationCharge))
end
def current(session: ShopifyAPI::Context.active_session)
charges = all(session: session)
charges.select { |charge| charge.status == "active" }.first
end

end

sig do
Expand Down
10 changes: 10 additions & 0 deletions lib/shopify_api/rest/resources/2024_01/shop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ def all(
T.cast(response, T::Array[Shop])
end

sig do
params(
fields: T.untyped,
session: Auth::Session,
).returns(T.nilable(Shop))
end
def current(fields: nil, session: ShopifyAPI::Context.active_session)
all(session: session, fields: fields).first
end

end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ def all(
T.cast(response, T::Array[RecurringApplicationCharge])
end

sig do
params(session: Auth::Session)
.returns(T.nilable(RecurringApplicationCharge))
end
def current(session: ShopifyAPI::Context.active_session)
charges = all(session: session)
charges.select { |charge| charge.status == "active" }.first
end

end

sig do
Expand Down
10 changes: 10 additions & 0 deletions lib/shopify_api/rest/resources/2024_04/shop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ def all(
T.cast(response, T::Array[Shop])
end

sig do
params(
fields: T.untyped,
session: Auth::Session,
).returns(T.nilable(Shop))
end
def current(fields: nil, session: ShopifyAPI::Context.active_session)
all(session: session, fields: fields).first
end

end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ def all(
T.cast(response, T::Array[RecurringApplicationCharge])
end

sig do
params(session: Auth::Session)
.returns(T.nilable(RecurringApplicationCharge))
end
def current(session: ShopifyAPI::Context.active_session)
charges = all(session: session)
charges.select { |charge| charge.status == "active" }.first
end
end

sig do
Expand Down
10 changes: 10 additions & 0 deletions lib/shopify_api/rest/resources/2024_07/shop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ def all(
T.cast(response, T::Array[Shop])
end

sig do
params(
fields: T.untyped,
session: Auth::Session,
).returns(T.nilable(Shop))
end
def current(fields: nil, session: ShopifyAPI::Context.active_session)
all(session: session, fields: fields).first
end

end

end
Expand Down
22 changes: 22 additions & 0 deletions test/rest/2022_04/recurring_application_charge_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,26 @@ def test_9()
end
end

sig do
void
end
def test_current()
stub_request(:get, "https://test-shop.myshopify.io/admin/api/2022-04/recurring_application_charges.json")
.with(
headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json"},
body: {}
)
.to_return(status: 200, body: JSON.generate({"recurring_application_charges" => [
{"id" => 455696195, "name" => "Super Mega Plan", "price" => "15.00", "billing_on" => "2022-04-02", "status" => "accepted", "created_at" => "2022-04-02T08:59:11-05:00", "updated_at" => "2022-04-02T09:03:16-05:00", "activated_on" => nil, "return_url" => "http://yourapp.example.org", "test" => nil, "cancelled_on" => nil, "trial_days" => 0, "trial_ends_on" => nil, "api_client_id" => 755357713, "decorated_return_url" => "http://yourapp.example.org?charge_id=455696195", "currency" => "USD"},
{"id" => 455696196, "name" => "Super Mega Plan", "price" => "15.00", "billing_on" => "2022-04-10", "status" => "active", "created_at" => "2022-04-10T08:59:11-05:00", "updated_at" => "2022-04-10T09:03:16-05:00", "activated_on" => nil, "return_url" => "http://yourapp.example.org", "test" => nil, "cancelled_on" => nil, "trial_days" => 0, "trial_ends_on" => nil, "api_client_id" => 755357714, "decorated_return_url" => "http://yourapp.example.org?charge_id=455696196", "currency" => "USD"},
]}), headers: {})

charge = ShopifyAPI::RecurringApplicationCharge.current

assert_requested(:get, "https://test-shop.myshopify.io/admin/api/2022-04/recurring_application_charges.json")

assert_equal(455696196, charge.id)
assert_equal("active", charge.status)
end

end
18 changes: 18 additions & 0 deletions test/rest/2022_04/shop_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,22 @@ def test_2()
end
end

sig do
void
end
def test_current
stub_request(:get, "https://test-shop.myshopify.io/admin/api/2022-04/shop.json")
.with(
headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json"},
body: {}
)
.to_return(status: 200, body: JSON.generate({"shop" => {"province" => "California", "country" => "US", "address1" => "1 Infinite Loop", "city" => "Cupertino", "address2" => "Suite 100"}}), headers: {})

shop = ShopifyAPI::Shop.current

assert_requested(:get, "https://test-shop.myshopify.io/admin/api/2022-04/shop.json")

assert_equal(shop.province, "California")
end

end
Loading

0 comments on commit c0e2439

Please sign in to comment.