kyledecot / app_store_connect

A Ruby interface to the App Store Connect API
https://rubygems.org/gems/app_store_connect
MIT License
54 stars 28 forks source link

How do I set GET query parameters? #90

Closed abgier-blitzm closed 5 years ago

abgier-blitzm commented 5 years ago

https://developer.apple.com/documentation/appstoreconnectapi/list_and_download_profiles#query-parameters

Lets say I want to call GET https://api.appstoreconnect.apple.com/v1/profiles and filter by bundleIds.

How would I do this? Is it still done from app_store_connect.profiles?

kyledecot commented 5 years ago

Both URL and query parameters are passed as the first argument. For example:

app_store_connect.profiles(
  limit: 1,
  filter: { 
    name: 'Kyle Decot\'s Development Profile', 
    profile_type: 'IOS_APP_DEVELOPMENT' 
  }
)

If you want to filter by Bundle ID (com.kyledecot.Example) I think you'd need to do something like:

require 'app_store_connect'

app_store_connect = AppStoreConnect::Client.new
bundle_id_identifier = 'com.kyledecot.Example'

response = app_store_connect.profiles(
  include: 'bundleId',
  fields: {
    profiles: 'bundleId',
    bundle_ids: 'identifier'
  }
)

bundle_id = response['included']
  .select { |i| i['type'] == 'bundleIds' }
  .detect({}) { |i| i.dig('attributes', 'identifier') == bundle_id_identifier }

profiles = response['data']
  .select { |d| bundle_id['id'] == d.dig('relationships', 'bundleId', 'data', 'id') }