Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to add or remove access for beta groups to a build #164

Merged
merged 5 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@ app_store_connect.create_in_app_purchase_price_schedule(
)
```

### Add or remove access for a Beta Group to a Build

```ruby
app_store_connect.add_build_beta_groups(
id: '<build-id>',
data: [{id: '<beta-group-id>'}]
)

app_store_connect.delete_build_beta_groups(
id: '<build-id>',
data: [{id: '<beta-group-id>'}]
)

```

## FAQ

### How to understand the `devices, sales_reports, create_bundle_id` keyword seen in the demo?
Expand Down
2 changes: 1 addition & 1 deletion lib/app_store_connect/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def build_request(web_service_endpoint, **kwargs)
headers: headers
}

options[:http_body] = http_body(web_service_endpoint, **kwargs) if %i[post patch].include?(web_service_endpoint.http_method)
options[:http_body] = http_body(web_service_endpoint, **kwargs) if web_service_endpoint.http_body_type.present?

Request.new(**options)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module AppStoreConnect
class BetaBuildLocalizationModifyRequest < Request::Body
data do
id
type 'betaBuildLocalizations'

attributes do
Expand Down
20 changes: 19 additions & 1 deletion lib/app_store_connect/object/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ module Data
attr_reader :data

klass = Class.new do |data|
include Object::DataType
include Object::Attributes
include Object::Type
include Object::Id

data.send(:define_method, :initialize) do |**kwargs|
instance_variable_set('@relationships', kwargs.delete(:relationships).to_h)
instance_variable_set('@data', Array(kwargs.delete(:data)))
instance_variable_set('@attributes', data::Attributes.new(**kwargs))
instance_variable_set('@id', kwargs[id_arg_name])
end
Expand All @@ -30,13 +32,29 @@ def to_h
props[:id] = @id if id?
props.reject { |_k, v| v.blank? }
end

def to_a
@data.each do |item|
item[:type] = type
end
@data
end

def to_data_type
if data_type == Array
to_a
else
to_h
end
end
end

const_set('Data', klass)
end

class_methods do
def data(&block)
def data(type = Hash, &block)
self::Data.data_type = type
self::Data.class_eval(&block)
end
end
Expand Down
23 changes: 23 additions & 0 deletions lib/app_store_connect/object/data_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require 'active_support/concern'

module AppStoreConnect
module Object
module DataType
extend ActiveSupport::Concern

class_methods do
def data_type=(type)
@data_type = type
end
end

included do
def data_type
self.class.instance_variable_get('@data_type')
end
end
end
end
end
4 changes: 2 additions & 2 deletions lib/app_store_connect/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def headers
def body
return if http_method == :get

@options.fetch(:http_body)
@options.fetch(:http_body, nil)
end

def url_parameter_names(web_service_endpoint)
Expand All @@ -77,7 +77,7 @@ def net_http_request_class
case http_method
when :get then Net::HTTP::Get
when :post then Net::HTTP::Post
when :delete then Net::HTTP::Delete
when :delete then Requests::DeleteWithBody
when :patch then Net::HTTP::Patch
else
raise UnsupportedHTTPMethod, http_method
Expand Down
2 changes: 1 addition & 1 deletion lib/app_store_connect/request/body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize(**kwargs)

def to_h
{
data: data.to_h,
data: data.to_data_type,
included: included.to_a
}
end
Expand Down
11 changes: 11 additions & 0 deletions lib/app_store_connect/requests/delete_with_body.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module AppStoreConnect
module Requests
class DeleteWithBody < Net::HTTPRequest
METHOD = 'DELETE'
REQUEST_HAS_BODY = true
RESPONSE_HAS_BODY = true
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module AppStoreConnect
module Requests
module V1
module BetaAppReviewSubmission
class Create < Request::Body
data do
type 'betaAppReviewSubmissions'
end
end
end
end
end
end
20 changes: 20 additions & 0 deletions lib/app_store_connect/requests/v1/build_beta_detail/update.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module AppStoreConnect
module Requests
module V1
module BuildBetaDetail
class Update < Request::Body
data do
id
type 'buildBetaDetails'

attributes do
property :auto_notify_enabled
end
end
end
end
end
end
end
16 changes: 16 additions & 0 deletions lib/app_store_connect/requests/v1/build_beta_groups/create.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module AppStoreConnect
module Requests
module V1
module BuildBetaGroups
class Create < Request::Body
data(Array) do
id
type 'betaGroups'
end
end
end
end
end
end
16 changes: 16 additions & 0 deletions lib/app_store_connect/requests/v1/build_beta_groups/delete.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module AppStoreConnect
module Requests
module V1
module BuildBetaGroups
class Delete < Request::Body
data(Array) do
id
type 'betaGroups'
end
end
end
end
end
end
27 changes: 26 additions & 1 deletion lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
{
"http_method": "delete",
"url": "https://api.appstoreconnect.apple.com/v1/builds/{id}/relationships/betaGroups",
"alias": "delete_build_beta_group"
"http_body_type": "Requests::V1::BuildBetaGroups::Delete",
"alias": "delete_build_beta_groups"
},
{
"http_method": "delete",
Expand Down Expand Up @@ -110,6 +111,18 @@
"http_body_type": "UserInvitationCreateRequest",
"http_method": "post"
},
{
"http_method": "post",
"url": "https://api.appstoreconnect.apple.com/v1/builds/{id}/relationships/betaGroups",
"http_body_type": "Requests::V1::BuildBetaGroups::Create",
"alias": "add_build_beta_groups"
},
{
"alias": "create_beta_build_localization",
"url": "https://api.appstoreconnect.apple.com/v1/betaBuildLocalizations",
"http_body_type": "BetaBuildLocalizationCreateRequest",
"http_method": "post"
},
{
"alias": "modify_beta_build_localization",
"url": "https://api.appstoreconnect.apple.com/v1/betaBuildLocalizations/{id}",
Expand Down Expand Up @@ -654,6 +667,12 @@
"url": "https://api.appstoreconnect.apple.com/v1/buildBetaDetails/{id}",
"alias": "build_beta_detail"
},
{
"http_method": "patch",
"url": "https://api.appstoreconnect.apple.com/v1/buildBetaDetails/{id}",
"http_body_type": "Requests::V1::BuildBetaDetail::Update",
"alias": "update_build_beta_detail"
},
{
"http_method": "get",
"url": "https://api.appstoreconnect.apple.com/v1/buildBetaDetails/{id}/build",
Expand Down Expand Up @@ -749,6 +768,12 @@
"url": "https://api.appstoreconnect.apple.com/v1/betaAppReviewSubmissions",
"alias": "beta_app_review_submissions"
},
{
"url": "https://api.appstoreconnect.apple.com/v1/betaAppReviewSubmissions",
"http_body_type": "Requests::V1::BetaAppReviewSubmission::Create",
"http_method": "post",
"alias": "create_beta_app_review_submission"
},
{
"http_method": "get",
"url": "https://api.appstoreconnect.apple.com/v1/betaAppReviewSubmissions/{id}",
Expand Down