Sha256: 37f616ea6a4ba3de643e0203a4f24e83fa18df392cc2679c0a051a411f79eb36

Contents?: true

Size: 1.65 KB

Versions: 2

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

require 'active_support/all'

module AppStoreConnect
  class Client
    ENDPOINT = 'https://api.appstoreconnect.apple.com/v1'

    def initialize(key_id:, issuer_id:, private_key:)
      @authorization = Authorization.new(
        private_key: private_key,
        key_id: key_id,
        issuer_id: issuer_id
      )
    end

    def apps
      get('apps')
    end

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

    def builds(app_id)
      get("apps/#{app_id}/builds")
    end

    def build(app_id, build_id)
      get("apps/#{app_id}/builds/#{build_id}")
    end

    def invite_user(first_name:, last_name:, email:, roles:)
      invitation = UserInvitationCreateRequest.new(
        first_name: first_name,
        last_name: last_name,
        email: email,
        roles: roles
      )

      post('userInvitations', invitation.body.to_json)
    end

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

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

    def users
      get('users')
    end

    def user_invitations
      get('userInvitations')
    end

    private

    def body(request)
      request
        .to_hash
        .deep_transform_keys { |k| k.to_s.camelize(:lower) }
        .to_json
    end

    def get(path)
      response = HTTParty.get("#{ENDPOINT}/#{path}", headers: headers)

      response['data']
    end

    def post(path, body)
      response = HTTParty.post("#{ENDPOINT}/#{path}", headers: headers, body: body)

      response
    end

    def headers
      {
        'Authorization' => "Bearer #{@authorization.token}",
        'Content-Type' => 'application/json'
      }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
app_store_connect-0.3.1 lib/app_store_connect/client.rb
app_store_connect-0.3.0 lib/app_store_connect/client.rb