Class: SelfSDK::App
- Inherits:
-
Object
- Object
- SelfSDK::App
- 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
-
#app_id ⇒ Types
readonly
the identifier of the current app.
-
#app_key ⇒ Types
readonly
the api key for the current app.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#messaging_client ⇒ Object
Returns the value of attribute messaging_client.
-
#started ⇒ Object
readonly
Returns the value of attribute started.
Instance Method Summary collapse
-
#authentication ⇒ Object
Provides access to SelfSDK::Services::Authentication service.
-
#chat ⇒ Object
Provides access to SelfSDK::Services::Chat service.
-
#close ⇒ Object
Closes the websocket connection.
-
#docs ⇒ Object
Provides access to SelfSDK::Services::Docs service.
-
#facts ⇒ Object
Provides access to SelfSDK::Services::Facts service.
-
#identity ⇒ Object
Provides access to SelfSDK::Services::Identity service.
-
#initialize(app_id, app_key, storage_key, storage_dir, opts = {}) ⇒ App
constructor
Initializes a SelfSDK App.
-
#messaging ⇒ Object
Provides access to SelfSDK::Services::Messaging service.
-
#start ⇒ Object
Starts the websockets connection and processes incoming messages in case the client is initialized with auto_start set to false.
-
#voice ⇒ Object
Provides access to SelfSDK::Services::Voice service.
Constructor Details
#initialize(app_id, app_key, storage_key, storage_dir, opts = {}) ⇒ App
Initializes a SelfSDK App
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# 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) @started = false unless messaging_url.nil? device_id = opts.fetch(:device_id, MessagingClient::DEFAULT_DEVICE) storage = opts.fetch(:storage, SelfSDK::Storage.new(@client.jwt.id, device_id, storage_dir, storage_key)) @messaging_client = MessagingClient.new(messaging_url, @client, storage_key, storage, 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_id ⇒ Types (readonly)
the identifier of the current app.
34 35 36 |
# File 'lib/selfsdk.rb', line 34 def app_id @app_id end |
#app_key ⇒ Types (readonly)
the api key for the current app.
34 35 36 |
# File 'lib/selfsdk.rb', line 34 def app_key @app_key end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
38 39 40 |
# File 'lib/selfsdk.rb', line 38 def client @client end |
#messaging_client ⇒ Object
Returns the value of attribute messaging_client.
39 40 41 |
# File 'lib/selfsdk.rb', line 39 def messaging_client @messaging_client end |
#started ⇒ Object (readonly)
Returns the value of attribute started.
38 39 40 |
# File 'lib/selfsdk.rb', line 38 def started @started end |
Instance Method Details
#authentication ⇒ Object
Provides access to SelfSDK::Services::Authentication service
93 94 95 |
# File 'lib/selfsdk.rb', line 93 def authentication @authentication ||= SelfSDK::Services::Authentication.new(requester) end |
#chat ⇒ Object
Provides access to SelfSDK::Services::Chat service
108 109 110 |
# File 'lib/selfsdk.rb', line 108 def chat @chat ||= SelfSDK::Services::Chat.new(messaging, identity) end |
#close ⇒ Object
Closes the websocket connection
131 132 133 |
# File 'lib/selfsdk.rb', line 131 def close @messaging_client.close end |
#docs ⇒ Object
Provides access to SelfSDK::Services::Docs service
118 119 120 |
# File 'lib/selfsdk.rb', line 118 def docs @docs ||= SelfSDK::Services::Docs.new(messaging, @client.self_url) end |
#facts ⇒ Object
Provides access to SelfSDK::Services::Facts service
88 89 90 |
# File 'lib/selfsdk.rb', line 88 def facts @facts ||= SelfSDK::Services::Facts.new(requester) end |
#identity ⇒ Object
Provides access to SelfSDK::Services::Identity service
98 99 100 |
# File 'lib/selfsdk.rb', line 98 def identity @identity ||= SelfSDK::Services::Identity.new(@client) end |
#messaging ⇒ Object
Provides access to SelfSDK::Services::Messaging service
103 104 105 |
# File 'lib/selfsdk.rb', line 103 def messaging @messaging ||= SelfSDK::Services::Messaging.new(@messaging_client) end |
#start ⇒ Object
Starts the websockets connection and processes incoming messages in case the client is initialized with auto_start set to false.
78 79 80 81 82 83 84 85 |
# File 'lib/selfsdk.rb', line 78 def start return self if @started @messaging_client.start @started = true self end |