From 026f830e1fe35c38f6a3f276dea5f3873b83a46f Mon Sep 17 00:00:00 2001 From: Grzegorz Jakubiak Date: Tue, 7 Feb 2023 13:22:48 +0100 Subject: [PATCH] Manage in app purchases (#131) * Add console script Co-authored-by: Tomislav Markanovic * List all price points for an app Co-authored-by: Tomislav Markanovic * Listing inAppPurchases and their details Co-authored-by: Tomislav Markanovic * Manage In-App Purchases Co-authored-by: Tomislav Markanovic * List In-App Purchase localizations Co-authored-by: Tomislav Markanovic --------- Co-authored-by: Tomislav Markanovic --- bin/console | 15 +++++ lib/app_store_connect.rb | 2 + .../requests/v2/in_app_purchase/create.rb | 26 +++++++++ .../requests/v2/in_app_purchase/update.rb | 25 +++++++++ lib/config/schema.json | 56 ++++++++++++++++++- spec/app_store_connect/client_spec.rb | 32 +++++++++++ spec/support/shared_examples/get_request.rb | 4 +- 7 files changed, 155 insertions(+), 5 deletions(-) create mode 100755 bin/console create mode 100644 lib/app_store_connect/requests/v2/in_app_purchase/create.rb create mode 100644 lib/app_store_connect/requests/v2/in_app_purchase/update.rb diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..9a4ed55 --- /dev/null +++ b/bin/console @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require 'bundler/setup' +require 'app_store_connect' + +# You can add fixtures and/or initialization code here to make experimenting +# with your gem easier. You can also use a different console, if you like. + +# (If you use this, don't forget to add pry to your Gemfile!) +# require "pry" +# Pry.start + +require 'irb' +IRB.start(__FILE__) diff --git a/lib/app_store_connect.rb b/lib/app_store_connect.rb index 65da5d2..d9e03df 100644 --- a/lib/app_store_connect.rb +++ b/lib/app_store_connect.rb @@ -19,6 +19,8 @@ require 'app_store_connect/bundle_id_create_request' require 'app_store_connect/certificate_create_request' require 'app_store_connect/device_create_request' +require 'app_store_connect/requests/v2/in_app_purchase/create' +require 'app_store_connect/requests/v2/in_app_purchase/update' require 'app_store_connect/profile_create_request' require 'app_store_connect/beta_build_localization_create_request' require 'app_store_connect/beta_build_localization_modify_request' diff --git a/lib/app_store_connect/requests/v2/in_app_purchase/create.rb b/lib/app_store_connect/requests/v2/in_app_purchase/create.rb new file mode 100644 index 0000000..ddf0d64 --- /dev/null +++ b/lib/app_store_connect/requests/v2/in_app_purchase/create.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'app_store_connect/create_request' + +module AppStoreConnect + module Requests + module V2 + module InAppPurchase + class Create < CreateRequest + data do + type 'inAppPurchases' + + attributes do + property :name, required: true + property :product_id, required: true + property :in_app_purchase_type, required: true + property :available_in_all_territories + property :family_sharable + property :review_note + end + end + end + end + end + end +end diff --git a/lib/app_store_connect/requests/v2/in_app_purchase/update.rb b/lib/app_store_connect/requests/v2/in_app_purchase/update.rb new file mode 100644 index 0000000..d86ec8d --- /dev/null +++ b/lib/app_store_connect/requests/v2/in_app_purchase/update.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'app_store_connect/create_request' + +module AppStoreConnect + module Requests + module V2 + module InAppPurchase + class Update < CreateRequest + data do + id + type 'inAppPurchases' + + attributes do + property :name + property :available_in_all_territories + property :family_sharable + property :review_note + end + end + end + end + end + end +end diff --git a/lib/config/schema.json b/lib/config/schema.json index e1249af..9ffc293 100644 --- a/lib/config/schema.json +++ b/lib/config/schema.json @@ -334,6 +334,48 @@ "url": "https://api.appstoreconnect.apple.com/v1/apps/{id}", "alias": "app" }, + { + "http_method": "get", + "url": "https://api.appstoreconnect.apple.com/v1/apps/{id}/pricePoints", + "alias": "app_price_points" + }, + { + "alias": "create_in_app_purchase", + "http_body_type": "Requests::V2::InAppPurchase::Create", + "http_method": "post", + "url": "https://api.appstoreconnect.apple.com/v2/inAppPurchases" + }, + { + "alias": "update_in_app_purchase", + "http_body_type": "Requests::V2::InAppPurchase::Update", + "http_method": "patch", + "url": "https://api.appstoreconnect.apple.com/v2/inAppPurchases/{id}" + }, + { + "alias": "delete_in_app_purchase", + "http_method": "delete", + "url": "https://api.appstoreconnect.apple.com/v2/inAppPurchases/{id}" + }, + { + "http_method": "get", + "url": "https://api.appstoreconnect.apple.com/v2/inAppPurchases/{id}", + "alias": "in_app_purchase" + }, + { + "http_method": "get", + "url": "https://api.appstoreconnect.apple.com/v1/apps/{id}/inAppPurchasesV2", + "alias": "app_in_app_purchases" + }, + { + "http_method": "get", + "url": "https://api.appstoreconnect.apple.com/v2/inAppPurchases/{id}/pricePoints", + "alias": "in_app_purchase_price_points" + }, + { + "http_method": "get", + "url": "https://api.appstoreconnect.apple.com/v2/inAppPurchases/{id}/inAppPurchaseLocalizations", + "alias": "in_app_purchase_localizations" + }, { "http_method": "get", "url": "https://api.appstoreconnect.apple.com/v1/apps/{id}/betaGroups", @@ -792,6 +834,13 @@ } ], "types": [ + { + "type": "BundleIdPlatform", + "values": [ + "IOS", + "MAC_OS" + ] + }, { "type": "CapabilityType", "values": [ @@ -833,10 +882,11 @@ ] }, { - "type": "BundleIdPlatform", + "type": "InAppPurchaseType", "values": [ - "IOS", - "MAC_OS" + "CONSUMABLE", + "NON_CONSUMABLE", + "NON_RENEWING_SUBSCRIPTION" ] }, { diff --git a/spec/app_store_connect/client_spec.rb b/spec/app_store_connect/client_spec.rb index e3cfeb4..65372d2 100644 --- a/spec/app_store_connect/client_spec.rb +++ b/spec/app_store_connect/client_spec.rb @@ -27,6 +27,38 @@ it_behaves_like :get_request, path: 'apps/1234' end + describe '#app_price_points' do + let(:id) { '1234' } + + before { subject.app_price_points(id: id) } + + it_behaves_like :get_request, path: 'apps/1234/pricePoints' + end + + describe '#in_app_purchase' do + let(:id) { '1234' } + + before { subject.in_app_purchase(id: id) } + + it_behaves_like :get_request, api_version: 'v2', path: 'inAppPurchases/1234' + end + + describe '#app_in_app_purchases' do + let(:id) { '1234' } + + before { subject.app_in_app_purchases(id: id) } + + it_behaves_like :get_request, path: 'apps/1234/inAppPurchasesV2' + end + + describe '#in_app_purchase_price_points' do + let(:id) { '1234' } + + before { subject.in_app_purchase_price_points(id: id) } + + it_behaves_like :get_request, api_version: 'v2', path: 'inAppPurchases/1234/pricePoints' + end + describe '#builds' do let(:id) { '1234' } diff --git a/spec/support/shared_examples/get_request.rb b/spec/support/shared_examples/get_request.rb index 7dfe839..dcf478e 100644 --- a/spec/support/shared_examples/get_request.rb +++ b/spec/support/shared_examples/get_request.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -RSpec.shared_examples :get_request do |path:, query_parameters: nil| +RSpec.shared_examples :get_request do |path:, api_version: 'v1', query_parameters: nil| it do - uri = "https://api.appstoreconnect.apple.com/v1/#{path}" + uri = "https://api.appstoreconnect.apple.com/#{api_version}/#{path}" uri += "?#{query_parameters.to_query}" if query_parameters