Class: SelfSDK::App

Inherits:
Object
  • Object
show all
Defined in:
lib/selfsdk.rb

Overview

Abstract base class for CLI utilities. Provides some helper methods for the option parser

Constant Summary collapse

BASE_URL =
"https://api.joinself.com".freeze
MESSAGING_URL =
"wss://messaging.joinself.com/v2/messaging".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_id, app_key, storage_key, storage_dir, opts = {}) ⇒ App

Initializes a SelfSDK App

Parameters:

  • app_id (string)

    the app id.

  • app_key (string)

    the app api key provided by developer portal.

  • storage_key (string)

    the key to be used to encrypt persisted data.

  • storage_dir (String)

    The folder where encryption sessions and settings will be stored

  • opts (Hash) (defaults to: {})

    the options to authenticate.

Options Hash (opts):

  • :base_url (String)

    The self provider url.

  • :messaging_url (String)

    The messaging self provider url.

  • :auto_reconnect (Bool)

    Automatically reconnects to websocket if connection is lost (defaults to true).

  • :env (Symbol)

    The environment to be used, defaults to “:production”.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/selfsdk.rb', line 53

def initialize(app_id, app_key, storage_key, storage_dir, opts = {})
  app_key = cleanup_key(app_key)

  SelfSDK.logger.debug "syncing ntp times #{SelfSDK::Time.now}"
  env = opts.fetch(:env, "")
  env = "" if env == "production"

  @client = RestClient.new(base_url(opts), app_id, app_key, env)
  messaging_url = messaging_url(opts)
  unless messaging_url.nil?
    @messaging_client = MessagingClient.new(messaging_url,
                                            @client,
                                            storage_key,
                                            storage_dir: storage_dir,
                                            auto_reconnect: opts.fetch(:auto_reconnect, MessagingClient::DEFAULT_AUTO_RECONNECT),
                                            device_id: opts.fetch(:device_id, MessagingClient::DEFAULT_DEVICE))
  end
end

Instance Attribute Details

#app_idTypes (readonly)

the identifier of the current app.

Returns:

  • (Types)

    the current value of app_id



35
36
37
# File 'lib/selfsdk.rb', line 35

def app_id
  @app_id
end

#app_keyTypes (readonly)

the api key for the current app.

Returns:

  • (Types)

    the current value of app_key



35
36
37
# File 'lib/selfsdk.rb', line 35

def app_key
  @app_key
end

#clientObject (readonly)

Returns the value of attribute client.



39
40
41
# File 'lib/selfsdk.rb', line 39

def client
  @client
end

#messaging_clientObject

Returns the value of attribute messaging_client.



40
41
42
# File 'lib/selfsdk.rb', line 40

def messaging_client
  @messaging_client
end

Instance Method Details

#authenticationObject

Provides access to SelfSDK::Services::Authentication service



78
79
80
# File 'lib/selfsdk.rb', line 78

def authentication
  @authentication ||= SelfSDK::Services::Authentication.new(requester)
end

#chatObject

Provides access to SelfSDK::Services::Chat service



93
94
95
# File 'lib/selfsdk.rb', line 93

def chat
  @chat ||= SelfSDK::Services::Chat.new(messaging, identity)
end

#closeObject

Closes the websocket connection



116
117
118
# File 'lib/selfsdk.rb', line 116

def close
  @messaging_client.close
end

#docsObject

Provides access to SelfSDK::Services::Docs service



103
104
105
# File 'lib/selfsdk.rb', line 103

def docs
  @docs ||= SelfSDK::Services::Docs.new(messaging, @client.self_url)
end

#factsObject

Provides access to SelfSDK::Services::Facts service



73
74
75
# File 'lib/selfsdk.rb', line 73

def facts
  @facts ||= SelfSDK::Services::Facts.new(requester)
end

#identityObject

Provides access to SelfSDK::Services::Identity service



83
84
85
# File 'lib/selfsdk.rb', line 83

def identity
  @identity ||= SelfSDK::Services::Identity.new(@client)
end

#messagingObject

Provides access to SelfSDK::Services::Messaging service



88
89
90
# File 'lib/selfsdk.rb', line 88

def messaging
  @messaging ||= SelfSDK::Services::Messaging.new(@messaging_client)
end

#voiceObject

Provides access to SelfSDK::Services::Voice service



98
99
100
# File 'lib/selfsdk.rb', line 98

def voice
  @voice ||= SelfSDK::Services::Voice.new(messaging)
end