Module: Episodic::Platform::Connection::Management::ClassMethods

Defined in:
lib/episodic/platform/connection.rb

Overview

Manage the creation and destruction of connections for Episodic::Platform::Base and its subclasses. Connections are created with establish_connection!.

Instance Method Summary collapse

Instance Method Details

#connected?Boolean

Returns true if a connection has been made yet.

Returns

Boolean

true if there is at least one connection

Returns:

  • (Boolean)


250
251
252
# File 'lib/episodic/platform/connection.rb', line 250

def connected?
  !connections.empty?
end

#connectionObject

Returns the connection for the current class, or Base’s default connection if the current class does not have its own connection.

If not connection has been established yet, NoConnectionEstablished will be raised.

Returns

Episodic::Platform::Connection

The connection for the current class or the default connection



235
236
237
238
239
240
241
# File 'lib/episodic/platform/connection.rb', line 235

def connection
  if connected?
    connections[connection_name] || default_connection
  else
    raise NoConnectionEstablished
  end
end

#disconnect(name = connection_name) ⇒ Object

Removes the connection for the current class. If there is no connection for the current class, the default connection will be removed.

Parameters

name<String>

The name of the connection. This defaults to the default connection name.



262
263
264
265
# File 'lib/episodic/platform/connection.rb', line 262

def disconnect(name = connection_name)
  name       = default_connection unless connections.has_key?(name)
  connections.delete(name)
end

#disconnect!Object

Removes all connections



270
271
272
# File 'lib/episodic/platform/connection.rb', line 270

def disconnect!
  connections.each_key {|connection| disconnect(connection)}
end

#establish_connection!(episodic_api_key, episodic_secret_key, options = {}) ⇒ Object

Creates a new connection with which to make requests to the Episodic Platform for the calling class.

Episodic::Platform::Base.establish_connection!(episodic_api_key, episodic_secret_key)

You can set connections for every subclass of Episodic::Platform::Base. Once the initial connection is made on Base, all subsequent connections will inherit whatever values you don’t specify explictly.

Parameters

episodic_api_key<String>

This is your Episodic API Key

episodic_secret_key<String>

This is your Episodic Secret Key



221
222
223
# File 'lib/episodic/platform/connection.rb', line 221

def establish_connection!(episodic_api_key, episodic_secret_key, options = {})
  connections[connection_name] = Connection.new(episodic_api_key, episodic_secret_key, options)
end