From 92a4a05852639e130d4cd6ed9c9b60e176b7fdeb Mon Sep 17 00:00:00 2001 From: = Date: Wed, 15 Feb 2023 19:54:05 +0800 Subject: [PATCH 1/7] Create Included Concern --- lib/app_store_connect.rb | 2 ++ .../bundle_id_update_request.rb | 17 ++++++++++++ lib/app_store_connect/create_request.rb | 10 +++++++ lib/app_store_connect/modify_request.rb | 12 ++++++++- lib/app_store_connect/object/data.rb | 6 ----- lib/app_store_connect/object/included.rb | 27 +++++++++++++++++++ lib/config/schema.json | 7 ++++- 7 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 lib/app_store_connect/bundle_id_update_request.rb create mode 100644 lib/app_store_connect/object/included.rb diff --git a/lib/app_store_connect.rb b/lib/app_store_connect.rb index d36110d..6c93a3d 100644 --- a/lib/app_store_connect.rb +++ b/lib/app_store_connect.rb @@ -5,6 +5,7 @@ require 'app_store_connect/object/id' require 'app_store_connect/object/attributes' require 'app_store_connect/object/properties' +require 'app_store_connect/object/included' require 'app_store_connect/object/data' require 'app_store_connect/version' @@ -14,6 +15,7 @@ require 'app_store_connect/app_store_version_phased_release_update_request' require 'app_store_connect/app_store_version_release_request_create_request' require 'app_store_connect/app_store_version_update_request' +require 'app_store_connect/bundle_id_update_request' require 'app_store_connect/build_update_request' require 'app_store_connect/bundle_id_capability_create_request' require 'app_store_connect/bundle_id_create_request' diff --git a/lib/app_store_connect/bundle_id_update_request.rb b/lib/app_store_connect/bundle_id_update_request.rb new file mode 100644 index 0000000..11b75a1 --- /dev/null +++ b/lib/app_store_connect/bundle_id_update_request.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'app_store_connect/modify_request' + +module AppStoreConnect + class BundleIdUpdateRequest < ModifyRequest + data do + id + + type 'bundleIds' + + attributes do + property :name + end + end + end +end diff --git a/lib/app_store_connect/create_request.rb b/lib/app_store_connect/create_request.rb index 058ae0c..2441844 100644 --- a/lib/app_store_connect/create_request.rb +++ b/lib/app_store_connect/create_request.rb @@ -4,11 +4,21 @@ module AppStoreConnect class CreateRequest def self.inherited(klass) super + + klass.include(Object::Included) klass.include(Object::Data) end def initialize(**kwargs) + @included = self.class::Included.new([*kwargs.delete(:included)]) @data = self.class::Data.new(**kwargs) end + + def to_h + { + data: data.to_h, + included: included.to_a.join(',') + } + end end end diff --git a/lib/app_store_connect/modify_request.rb b/lib/app_store_connect/modify_request.rb index 2c55726..6411421 100644 --- a/lib/app_store_connect/modify_request.rb +++ b/lib/app_store_connect/modify_request.rb @@ -4,11 +4,21 @@ module AppStoreConnect class ModifyRequest def self.inherited(klass) super + + klass.include(Object::Included) klass.include(Object::Data) end def initialize(**kwargs) - @data = self.class::Data.new(kwargs) + @included = self.class::Included.new([*kwargs.delete(:included)]) + @data = self.class::Data.new(**kwargs) + end + + def to_h + { + data: data.to_h, + included: included.to_a.join(',') + } end end end diff --git a/lib/app_store_connect/object/data.rb b/lib/app_store_connect/object/data.rb index fefc5dc..6530c16 100644 --- a/lib/app_store_connect/object/data.rb +++ b/lib/app_store_connect/object/data.rb @@ -33,12 +33,6 @@ def to_h end const_set('Data', klass) - - def to_h - { - data: data.to_h - } - end end class_methods do diff --git a/lib/app_store_connect/object/included.rb b/lib/app_store_connect/object/included.rb new file mode 100644 index 0000000..658b0d3 --- /dev/null +++ b/lib/app_store_connect/object/included.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'active_support/concern' + +module AppStoreConnect + module Object + module Included + extend ActiveSupport::Concern + + included do + attr_reader :included + + klass = Class.new do |i| + i.send(:define_method, :initialize) do |values| + instance_variable_set('@values', [*values]) + end + + def to_a + @values + end + end + + const_set('Included', klass) + end + end + end +end diff --git a/lib/config/schema.json b/lib/config/schema.json index 927045f..14cb811 100644 --- a/lib/config/schema.json +++ b/lib/config/schema.json @@ -793,7 +793,12 @@ "http_body_type": "BuildUpdateRequest", "alias": "update_build" }, - + { + "http_method": "patch", + "url": "https://api.appstoreconnect.apple.com/v1/bundleIds/{id}", + "http_body_type": "BundleIdUpdateRequest", + "alias": "update_bundle_id" + }, { "url": "https://api.appstoreconnect.apple.com/v1/appStoreVersions", "http_body_type": "AppStoreVersionCreateRequest", From 627f210a5d8e829aa6fd9e55338c5fa993a5ea35 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 15 Feb 2023 22:05:07 +0800 Subject: [PATCH 2/7] Update specs --- lib/app_store_connect/create_request.rb | 2 +- lib/app_store_connect/modify_request.rb | 2 +- lib/app_store_connect/object/included.rb | 6 +++--- spec/bundle_id_create_request_spec.rb | 6 ++++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/app_store_connect/create_request.rb b/lib/app_store_connect/create_request.rb index 2441844..705ba39 100644 --- a/lib/app_store_connect/create_request.rb +++ b/lib/app_store_connect/create_request.rb @@ -17,7 +17,7 @@ def initialize(**kwargs) def to_h { data: data.to_h, - included: included.to_a.join(',') + included: included.to_a } end end diff --git a/lib/app_store_connect/modify_request.rb b/lib/app_store_connect/modify_request.rb index 6411421..769be6b 100644 --- a/lib/app_store_connect/modify_request.rb +++ b/lib/app_store_connect/modify_request.rb @@ -17,7 +17,7 @@ def initialize(**kwargs) def to_h { data: data.to_h, - included: included.to_a.join(',') + included: included.to_a } end end diff --git a/lib/app_store_connect/object/included.rb b/lib/app_store_connect/object/included.rb index 658b0d3..1bc0720 100644 --- a/lib/app_store_connect/object/included.rb +++ b/lib/app_store_connect/object/included.rb @@ -11,12 +11,12 @@ module Included attr_reader :included klass = Class.new do |i| - i.send(:define_method, :initialize) do |values| - instance_variable_set('@values', [*values]) + i.send(:define_method, :initialize) do |objects| + instance_variable_set('@objects', [*objects]) end def to_a - @values + @objects end end diff --git a/spec/bundle_id_create_request_spec.rb b/spec/bundle_id_create_request_spec.rb index d09802f..837ccce 100644 --- a/spec/bundle_id_create_request_spec.rb +++ b/spec/bundle_id_create_request_spec.rb @@ -17,7 +17,8 @@ name: attributes.name, platform: attributes.platform } - } + }, + included: [], ) end end @@ -36,7 +37,8 @@ seed_id: attributes.seed_id, platform: attributes.platform } - } + }, + included: [], ) end end From 012e7c2821690bce01d1c3baef800cbadf8887f3 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 15 Feb 2023 22:07:16 +0800 Subject: [PATCH 3/7] Fix Linting --- spec/bundle_id_create_request_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/bundle_id_create_request_spec.rb b/spec/bundle_id_create_request_spec.rb index 837ccce..7ab58a7 100644 --- a/spec/bundle_id_create_request_spec.rb +++ b/spec/bundle_id_create_request_spec.rb @@ -18,7 +18,7 @@ platform: attributes.platform } }, - included: [], + included: [] ) end end @@ -38,7 +38,7 @@ platform: attributes.platform } }, - included: [], + included: [] ) end end From b311f7385990f493947dfe0dfd8168d543b4582f Mon Sep 17 00:00:00 2001 From: = Date: Wed, 15 Feb 2023 22:10:22 +0800 Subject: [PATCH 4/7] Remove debug endpoint --- lib/app_store_connect.rb | 1 - .../bundle_id_update_request.rb | 17 ----------------- lib/config/schema.json | 7 +------ 3 files changed, 1 insertion(+), 24 deletions(-) delete mode 100644 lib/app_store_connect/bundle_id_update_request.rb diff --git a/lib/app_store_connect.rb b/lib/app_store_connect.rb index 6c93a3d..1d2b89e 100644 --- a/lib/app_store_connect.rb +++ b/lib/app_store_connect.rb @@ -15,7 +15,6 @@ require 'app_store_connect/app_store_version_phased_release_update_request' require 'app_store_connect/app_store_version_release_request_create_request' require 'app_store_connect/app_store_version_update_request' -require 'app_store_connect/bundle_id_update_request' require 'app_store_connect/build_update_request' require 'app_store_connect/bundle_id_capability_create_request' require 'app_store_connect/bundle_id_create_request' diff --git a/lib/app_store_connect/bundle_id_update_request.rb b/lib/app_store_connect/bundle_id_update_request.rb deleted file mode 100644 index 11b75a1..0000000 --- a/lib/app_store_connect/bundle_id_update_request.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -require 'app_store_connect/modify_request' - -module AppStoreConnect - class BundleIdUpdateRequest < ModifyRequest - data do - id - - type 'bundleIds' - - attributes do - property :name - end - end - end -end diff --git a/lib/config/schema.json b/lib/config/schema.json index 14cb811..927045f 100644 --- a/lib/config/schema.json +++ b/lib/config/schema.json @@ -793,12 +793,7 @@ "http_body_type": "BuildUpdateRequest", "alias": "update_build" }, - { - "http_method": "patch", - "url": "https://api.appstoreconnect.apple.com/v1/bundleIds/{id}", - "http_body_type": "BundleIdUpdateRequest", - "alias": "update_bundle_id" - }, + { "url": "https://api.appstoreconnect.apple.com/v1/appStoreVersions", "http_body_type": "AppStoreVersionCreateRequest", From df864776665fd639ced09db1bbb4d6f41fe0f647 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 15 Feb 2023 23:11:56 +0800 Subject: [PATCH 5/7] Revert "Remove debug endpoint" This reverts commit b311f7385990f493947dfe0dfd8168d543b4582f. --- lib/app_store_connect.rb | 1 + .../bundle_id_update_request.rb | 17 +++++++++++++++++ lib/config/schema.json | 7 ++++++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 lib/app_store_connect/bundle_id_update_request.rb diff --git a/lib/app_store_connect.rb b/lib/app_store_connect.rb index 1d2b89e..6c93a3d 100644 --- a/lib/app_store_connect.rb +++ b/lib/app_store_connect.rb @@ -15,6 +15,7 @@ require 'app_store_connect/app_store_version_phased_release_update_request' require 'app_store_connect/app_store_version_release_request_create_request' require 'app_store_connect/app_store_version_update_request' +require 'app_store_connect/bundle_id_update_request' require 'app_store_connect/build_update_request' require 'app_store_connect/bundle_id_capability_create_request' require 'app_store_connect/bundle_id_create_request' diff --git a/lib/app_store_connect/bundle_id_update_request.rb b/lib/app_store_connect/bundle_id_update_request.rb new file mode 100644 index 0000000..11b75a1 --- /dev/null +++ b/lib/app_store_connect/bundle_id_update_request.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'app_store_connect/modify_request' + +module AppStoreConnect + class BundleIdUpdateRequest < ModifyRequest + data do + id + + type 'bundleIds' + + attributes do + property :name + end + end + end +end diff --git a/lib/config/schema.json b/lib/config/schema.json index 927045f..14cb811 100644 --- a/lib/config/schema.json +++ b/lib/config/schema.json @@ -793,7 +793,12 @@ "http_body_type": "BuildUpdateRequest", "alias": "update_build" }, - + { + "http_method": "patch", + "url": "https://api.appstoreconnect.apple.com/v1/bundleIds/{id}", + "http_body_type": "BundleIdUpdateRequest", + "alias": "update_bundle_id" + }, { "url": "https://api.appstoreconnect.apple.com/v1/appStoreVersions", "http_body_type": "AppStoreVersionCreateRequest", From 36700bf57c3c7c354962fa2f3fe2c3e5ca5d9827 Mon Sep 17 00:00:00 2001 From: = Date: Sun, 26 Feb 2023 16:20:55 +0800 Subject: [PATCH 6/7] Fix Merge --- .../bundle_id_update_request.rb | 17 ------------- lib/app_store_connect/create_request.rb | 24 ------------------- lib/app_store_connect/modify_request.rb | 24 ------------------- lib/app_store_connect/request/body.rb | 10 ++++++++ lib/config/schema.json | 7 +----- 5 files changed, 11 insertions(+), 71 deletions(-) delete mode 100644 lib/app_store_connect/bundle_id_update_request.rb delete mode 100644 lib/app_store_connect/create_request.rb delete mode 100644 lib/app_store_connect/modify_request.rb diff --git a/lib/app_store_connect/bundle_id_update_request.rb b/lib/app_store_connect/bundle_id_update_request.rb deleted file mode 100644 index 11b75a1..0000000 --- a/lib/app_store_connect/bundle_id_update_request.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -require 'app_store_connect/modify_request' - -module AppStoreConnect - class BundleIdUpdateRequest < ModifyRequest - data do - id - - type 'bundleIds' - - attributes do - property :name - end - end - end -end diff --git a/lib/app_store_connect/create_request.rb b/lib/app_store_connect/create_request.rb deleted file mode 100644 index 705ba39..0000000 --- a/lib/app_store_connect/create_request.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -module AppStoreConnect - class CreateRequest - def self.inherited(klass) - super - - klass.include(Object::Included) - klass.include(Object::Data) - end - - def initialize(**kwargs) - @included = self.class::Included.new([*kwargs.delete(:included)]) - @data = self.class::Data.new(**kwargs) - end - - def to_h - { - data: data.to_h, - included: included.to_a - } - end - end -end diff --git a/lib/app_store_connect/modify_request.rb b/lib/app_store_connect/modify_request.rb deleted file mode 100644 index 769be6b..0000000 --- a/lib/app_store_connect/modify_request.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -module AppStoreConnect - class ModifyRequest - def self.inherited(klass) - super - - klass.include(Object::Included) - klass.include(Object::Data) - end - - def initialize(**kwargs) - @included = self.class::Included.new([*kwargs.delete(:included)]) - @data = self.class::Data.new(**kwargs) - end - - def to_h - { - data: data.to_h, - included: included.to_a - } - end - end -end diff --git a/lib/app_store_connect/request/body.rb b/lib/app_store_connect/request/body.rb index b014ee5..7832abc 100644 --- a/lib/app_store_connect/request/body.rb +++ b/lib/app_store_connect/request/body.rb @@ -5,12 +5,22 @@ class Request class Body def self.inherited(klass) super + + klass.include(Object::Included) klass.include(Object::Data) end def initialize(**kwargs) + @included = self.class::Included.new([*kwargs.delete(:included)]) @data = self.class::Data.new(**kwargs) end + + def to_h + { + data: data.to_h, + included: included.to_a + } + end end end end diff --git a/lib/config/schema.json b/lib/config/schema.json index e31a2ea..be82234 100644 --- a/lib/config/schema.json +++ b/lib/config/schema.json @@ -765,12 +765,7 @@ "http_body_type": "BuildUpdateRequest", "alias": "update_build" }, - { - "http_method": "patch", - "url": "https://api.appstoreconnect.apple.com/v1/bundleIds/{id}", - "http_body_type": "BundleIdUpdateRequest", - "alias": "update_bundle_id" - }, + { "url": "https://api.appstoreconnect.apple.com/v1/appStoreVersions", "http_body_type": "AppStoreVersionCreateRequest", From 17b1a48a396614002fc001da42ddae291e44a038 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 27 Feb 2023 00:35:26 +0800 Subject: [PATCH 7/7] Update spec for request body --- spec/app_store_connect/request/body_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/app_store_connect/request/body_spec.rb b/spec/app_store_connect/request/body_spec.rb index 1659c90..b2dc22e 100644 --- a/spec/app_store_connect/request/body_spec.rb +++ b/spec/app_store_connect/request/body_spec.rb @@ -4,6 +4,7 @@ let(:klass) do Class.new(described_class) do include AppStoreConnect::Object::Data + include AppStoreConnect::Object::Included data do attributes do @@ -18,6 +19,6 @@ subject { instance.to_h } describe '#to_h' do - it { is_expected.to eq({ data: { attributes: { bar: :baz } } }) } + it { is_expected.to eq({ included: [{ type: :foo }], data: { attributes: { bar: :baz } } }) } end end