class PusherPlatform::Instance

Public Class Methods

new(options) click to toggle source
# File lib/pusher-platform/instance.rb, line 13
def initialize(options)
  raise PusherPlatform::Error.new("No instance locator provided") if options[:locator].nil?
  raise PusherPlatform::Error.new("No key provided") if options[:key].nil?
  raise PusherPlatform::Error.new("No service name provided") if options[:service_name].nil?
  raise PusherPlatform::Error.new("No service version provided") if options[:service_version].nil?
  if options[:sdk_info].nil? && options[:client].nil?
    raise PusherPlatform::Error.new("You must provide either an SDKInfo or BaseClient instance via sdk_info or client")
  end

  locator = options[:locator]
  @service_name = options[:service_name]
  @service_version = options[:service_version]

  key_parts = options[:key].match(/^([^:]+):(.+)$/)
  raise PusherPlatform::Error.new("Invalid key") if key_parts.nil?

  @key_id = key_parts[1]
  @key_secret = key_parts[2]

  split_locator = locator.split(':')

  @platform_version = split_locator[0]
  @cluster = split_locator[1]
  @instance_id = split_locator[2]

  @client = if options[:client]
    options[:client]
  else
    BaseClient.new(
      host: options[:host] || "#{@cluster}.#{HOST_BASE}",
      port: options[:port],
      instance_id: @instance_id,
      service_name: @service_name,
      service_version: @service_version,
      sdk_info: options[:sdk_info]
    )
  end

  @authenticator = Authenticator.new(@instance_id, @key_id, @key_secret)
end

Public Instance Methods

authenticate(auth_payload, options) click to toggle source
# File lib/pusher-platform/instance.rb, line 58
def authenticate(auth_payload, options)
  @authenticator.authenticate(auth_payload, options)
end
authenticate_with_refresh_token(auth_payload, options) click to toggle source
# File lib/pusher-platform/instance.rb, line 66
def authenticate_with_refresh_token(auth_payload, options)
  @authenticator.authenticate_with_refresh_token(auth_payload, options)
end
authenticate_with_refresh_token_and_request(auth_payload, options) click to toggle source
# File lib/pusher-platform/instance.rb, line 70
def authenticate_with_refresh_token_and_request(auth_payload, options)
  @authenticator.authenticate_with_refresh_token_and_request(auth_payload, options)
end
authenticate_with_request(request, options) click to toggle source
# File lib/pusher-platform/instance.rb, line 62
def authenticate_with_request(request, options)
  @authenticator.authenticate_with_request(request, options)
end
generate_access_token(options) click to toggle source
# File lib/pusher-platform/instance.rb, line 74
def generate_access_token(options)
  @authenticator.generate_access_token(options)
end
request(options) click to toggle source
# File lib/pusher-platform/instance.rb, line 54
def request(options)
  @client.request(options)
end