Sha256: bba840c6ea494c42e9fc5e433243784d1a8b94f1dcdff5c8c80cc4f35ac5e60e

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 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, last_name, email, 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

1 entries across 1 versions & 1 rubygems

Version Path
app_store_connect-0.3.2 lib/app_store_connect/client.rb