Skip to content

Commit

Permalink
Merge pull request #42 from kyledecot/kd-dynamic
Browse files Browse the repository at this point in the history
Dynamic Client
  • Loading branch information
Kyle Decot authored Aug 8, 2019
2 parents 5f1a823 + a410c0b commit 4002f71
Showing 1 changed file with 48 additions and 25 deletions.
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

0 comments on commit 4002f71

Please sign in to comment.