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

Dynamic Client #42

Merged
merged 1 commit into from
Aug 8, 2019
Merged
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
73 changes: 48 additions & 25 deletions lib/app_store_connect/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,69 @@ def initialize(**kwargs)
key_id: @options[:key_id],
issuer_id: @options[:issuer_id]
)
end

def apps
get('apps')
end

def app(id)
get("apps/#{id}")
@web_service_endpoints_by_name = web_service_endpoints_by_name
end

def builds(app_id)
get("apps/#{app_id}/builds")
def web_service_endpoint_names
@web_service_endpoints_by_name.keys
end

def build(app_id, build_id)
get("apps/#{app_id}/builds/#{build_id}")
def respond_to_missing?(method_name, include_private = false)
web_service_endpoint_names.include?(method_name) || super
end

def invite_user(first_name:, last_name:, email:, roles:)
invitation = UserInvitationCreateRequest.new(first_name, last_name, email, roles)
def method_missing(method_name, *args, &block)
super unless web_service_endpoint_names.include?(method_name)

post('userInvitations', invitation.body.to_json)
web_service_endpoint_by(name: method_name)[:executor].call(*args, &block)
end

def create_bundle_id(*args)
request = BundleIdCreateRequest.new(*args)

post('bundleIds', body(request))
end
private

def users(limit: 200)
get('users', query_params: { 'limit' => limit })
def web_service_endpoint_by(name:)
@web_service_endpoints_by_name[name]
end

def user_invitations
get('userInvitations')
def web_service_endpoints_by_name # rubocop:disable Metrics/AbcSize
{
apps: {
executor: -> { get('apps') }
},
app: {
executor: ->(id) { get("apps/#{id}") }
},
builds: {
executor: ->(app_id) { get("apps/#{app_id}/builds") }
},
build: {
executor: ->(app_id, build_id) { get("apps/#{app_id}/builds/#{build_id}") }
},
invite_user: {
executor: lambda do |first_name:, last_name:, email:, roles:|
invitation = UserInvitationCreateRequest.new(first_name, last_name, email, roles)

post('userInvitations', invitation.body.to_json)
end
},
create_bundle_id: {
executor: lambda do |*args|
request = BundleIdCreateRequest.new(*args)

post('bundleIds', body(request))
end
},
users: {
executor: lambda do |limit: 200|
get('users', query_params: { 'limit' => limit })
end
},
user_invitations: {
executor: -> { get('userInvitations') }
}
}
end

private

def options(**kwargs)
AppStoreConnect.config.merge(kwargs).tap do |options|
%i[key_id issuer_id private_key].each do |key|
Expand Down