Class: Pubnub::PAM

Inherits:
SingleEvent show all
Defined in:
lib/pubnub/pam.rb

Overview

PAM module holds shared functionality for all PAM requests

Direct Known Subclasses

Audit, Grant, Revoke

Instance Attribute Summary

Attributes inherited from Event

#callback, #channel, #channel_group, #fresh_clone, #given_options, #group, #idle_timeout, #open_timeout, #origin, #presence_callback, #read_timeout, #ssl, #state, #wildcard_channel, #with_presence

Instance Method Summary collapse

Methods inherited from Event

#finalized?, #fire, #send_request, #sync?, #uri

Methods included from Event::EFormatter

#format_channels, #format_envelopes, #format_group

Constructor Details

#initialize(options, app) ⇒ PAM

Returns a new instance of PAM.



5
6
7
8
9
10
11
12
13
14
# File 'lib/pubnub/pam.rb', line 5

def initialize(options, app)
  super

  @auth_key = options[:auth_key]
  @telemetry_name = :l_pam

  # @channel += format_channels(options[:presence]).map do |c|
  #   c + '-pnpres'
  # end if options[:presence].present?
end

Instance Method Details

#current_operationObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/pubnub/pam.rb', line 30

def current_operation
  case @event
  when :audit
    Pubnub::Constants::OPERATION_AUDIT
  when :grant
    Pubnub::Constants::OPERATION_GRANT
  when :revoke
    Pubnub::Constants::OPERATION_REVOKE
  end
end

#error_envelope(parsed_response, error, req_res_objects) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/pubnub/pam.rb', line 75

def error_envelope(parsed_response, error, req_res_objects)
  case error
  when JSON::ParserError
    error_category = Pubnub::Constants::STATUS_NON_JSON_RESPONSE
    code = req_res_objects[:response].code
  when HTTPClient::TimeoutError
    error_category = Pubnub::Constants::STATUS_TIMEOUT
    code = 408
  else
    error_category = Pubnub::Constants::STATUS_ERROR
    code = req_res_objects[:response].code
  end

  ErrorEnvelope.new(
    event: @event,
    event_options: @given_options,
    timetoken: nil,
    status: {
      code: code,
      client_request: req_res_objects[:request],
      server_response: req_res_objects[:response],
      category: error_category,
      error: true,
      auto_retried: false,

      current_timetoken: nil,
      last_timetoken: nil,
      subscribed_channels: nil,
      subscribed_channel_groups: nil,

      data: nil,

      config: get_config
    },
    result: {
      code: code,
      operation: current_operation,
      client_request: req_res_objects[:request],
      server_response: req_res_objects[:response],

      data: {
        message: error_message(parsed_response)
      }
    }
  )
end

#parameters(set_signature = false) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/pubnub/pam.rb', line 20

def parameters(set_signature = false)
  params = super()
  params['channel-group'] = @group.join(',') unless @group.blank?
  params[:timestamp] = @timestamp
  params[:channel] = @channel.join(',') unless @channel.first.blank?
  params['target-uuid'] = @uuids.join(',') if !@uuids.nil? && !@uuids.first.blank?
  params[:signature] = signature unless set_signature
  params
end

#signatureObject



16
17
18
# File 'lib/pubnub/pam.rb', line 16

def signature
  super_admin_signature("GET", nil)
end

#valid_envelope(parsed_response, req_res_objects) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/pubnub/pam.rb', line 41

def valid_envelope(parsed_response, req_res_objects)
  Pubnub::Envelope.new(
    event: @event,
    event_options: @given_options,
    timetoken: nil,
    status: {
      code: req_res_objects[:response].code,
      client_request: req_res_objects[:request],
      server_response: req_res_objects[:response],
      category: Pubnub::Constants::STATUS_ACK,
      error: false,
      auto_retried: false,

      current_timetoken: nil,
      last_timetoken: nil,
      subscribed_channels: nil,
      subscribed_channel_groups: nil,

      data: nil,

      config: get_config

    },
    result: {
      code: req_res_objects[:response].code,
      operation: current_operation,
      client_request: req_res_objects[:request],
      server_response: req_res_objects[:response],

      data: parsed_response['payload']
    }
  )
end