class AppStoreConnect::Client

Public Class Methods

new(**kwargs) click to toggle source
# File lib/app_store_connect/client.rb, line 15
def initialize(**kwargs)
  @options = Options.new(kwargs)
  @usage = Usage.new(@options.slice(*Usage::OPTIONS))
  @authorization = Authorization.new(@options.slice(*Authorization::OPTIONS))
  @registry = Registry.new(@options.slice(*Registry::OPTIONS))
end

Public Instance Methods

inspect() click to toggle source

:nocov:

# File lib/app_store_connect/client.rb, line 35
def inspect
  "#<#{self.class.name}:#{object_id}>"
end
method_missing(method_name, *kwargs) click to toggle source
Calls superclass method
# File lib/app_store_connect/client.rb, line 26
def method_missing(method_name, *kwargs)
  super unless web_service_endpoint_aliases.include?(method_name)

  web_service_endpoint = web_service_endpoint_by(method_name)

  call(web_service_endpoint, *kwargs)
end
respond_to_missing?(method_name, include_private = false) click to toggle source
Calls superclass method
# File lib/app_store_connect/client.rb, line 22
def respond_to_missing?(method_name, include_private = false)
  web_service_endpoint_aliases.include?(method_name) || super
end
web_service_endpoint_aliases() click to toggle source

:nocov:

# File lib/app_store_connect/client.rb, line 40
def web_service_endpoint_aliases
  @registry.keys
end

Private Instance Methods

build_request(web_service_endpoint, **kwargs) click to toggle source
# File lib/app_store_connect/client.rb, line 74
def build_request(web_service_endpoint, **kwargs)
  options = {
    kwargs: kwargs,
    web_service_endpoint: web_service_endpoint,
    http_method: web_service_endpoint.http_method,
    uri: build_uri(web_service_endpoint, **kwargs),
    headers: headers
  }

  options[:http_body] = http_body(web_service_endpoint, **kwargs) if web_service_endpoint.http_method == :post

  Request.new(options)
end
build_uri(web_service_endpoint, **kwargs) click to toggle source
# File lib/app_store_connect/client.rb, line 57
def build_uri(web_service_endpoint, **kwargs)
  URI(web_service_endpoint
    .url
    .gsub(/(\{(\w+)\})/) { kwargs.fetch(Regexp.last_match(2).to_sym) })
end
call(web_service_endpoint, **kwargs) click to toggle source
# File lib/app_store_connect/client.rb, line 46
def call(web_service_endpoint, **kwargs)
  raise "invalid http method: #{web_service_endpoint.http_method}" unless %i[get delete post].include?(web_service_endpoint.http_method)

  request = build_request(web_service_endpoint, **kwargs)

  @usage.track
  response = request.execute

  Utils.decode(response.body, response.content_type) if response.body
end
headers() click to toggle source
# File lib/app_store_connect/client.rb, line 88
def headers
  {
    'Authorization' => "Bearer #{@authorization.token}",
    'Content-Type' => 'application/json'
  }
end
http_body(web_service_endpoint, **kwargs) click to toggle source
# File lib/app_store_connect/client.rb, line 67
def http_body(web_service_endpoint, **kwargs)
  Utils.encode("AppStoreConnect::#{web_service_endpoint.http_body_type}"
    .constantize
    .new(**kwargs)
    .to_h)
end
web_service_endpoint_by(alias_sym) click to toggle source
# File lib/app_store_connect/client.rb, line 63
def web_service_endpoint_by(alias_sym)
  @registry[alias_sym]
end