Method: SelfSDK::MessagingClient#initialize

Defined in:
lib/messaging.rb

#initialize(url, client, storage_key, storage_folder, options = {}) ⇒ MessagingClient

RestClient initializer

Parameters:

  • url (string)

    self-messaging url

  • opts (Hash)

    a customizable set of options

[View source]

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/messaging.rb', line 33

def initialize(url, client, storage_key, storage_folder, options = {})
  @mon = Monitor.new
  @url = url
  @messages = {}
  @acks = {}
  @type_observer = {}
  @uuid_observer = {}
  @jwt = client.jwt
  @client = client
  @ack_timeout = 60 # seconds
  @timeout = 120 # seconds
  @device_id = options.fetch(:device_id, DEFAULT_DEVICE)
  @auto_reconnect = options.fetch(:auto_reconnect, DEFAULT_AUTO_RECONNECT)
  @storage_dir = options.fetch(:storage_dir, DEFAULT_STORAGE_DIR)
  @offset_file = "#{@storage_dir}/#{@jwt.id}:#{@device_id}.offset"
  @offset = read_offset

  FileUtils.mkdir_p @storage_dir unless File.exist? @storage_dir
  unless options.include? :no_crypto
    @encryption_client = Crypto.new(@client, @device_id, storage_folder, storage_key)
  end

  if options.include? :ws
    @ws = options[:ws]
  else
    start
  end
end