Class: PusherPlatform::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/pusher-platform/instance.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Instance

Returns a new instance of Instance.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/pusher-platform/instance.rb', line 11

def initialize(options)
  raise "No instance locator provided" if options[:locator].nil?
  raise "No service name provided" if options[:service_name].nil?
  raise "No service version provided" if options[:service_version].nil?
  locator = options[:locator]
  @service_name = options[:service_name]
  @service_version = options[:service_version]

  key_parts = options[:key].match(/^([^:]+):(.+)$/)
  raise "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
    )
  end

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

Instance Method Details

#authenticate(request, options) ⇒ Object



55
56
57
# File 'lib/pusher-platform/instance.rb', line 55

def authenticate(request, options)
  @authenticator.authenticate(request, options)
end

#generate_access_token(options) ⇒ Object



59
60
61
# File 'lib/pusher-platform/instance.rb', line 59

def generate_access_token(options)
  @authenticator.generate_access_token(options)
end

#request(options) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/pusher-platform/instance.rb', line 46

def request(options)
  if options[:jwt].nil?
    options = options.merge(
      { jwt: @authenticator.generate_access_token({ su: true })[:token] }
    )
  end
  @client.request(options)
end