Module: KodiClient::Extensions::Chainable

Included in:
KodiClient, Client
Defined in:
lib/kodi_client/extensions/chainable.rb

Overview

Offers methods like connect, auth and tls to be chained together

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject

Returns the value of attribute client.



8
9
10
# File 'lib/kodi_client/extensions/chainable.rb', line 8

def client
  @client
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/kodi_client/extensions/chainable.rb', line 8

def options
  @options
end

Instance Method Details

#auth(username, password) ⇒ Client

sets username and password if required

Parameters:

  • username (String)

    the username

  • password (String)

    the password

Returns:

  • (Client)

    the existing, or if not existed, a new created client

Raises:

  • (ArgumentError)


26
27
28
29
30
# File 'lib/kodi_client/extensions/chainable.rb', line 26

def auth(username, password)
  raise ArgumentError, 'username or password can\'t be nil.' if username.nil? || password.nil?

  merge_options(->(options) { options.with_auth(username, password) })
end

#connect(ip, port) ⇒ Client

Creates a new Client instance and sets the given ip and port to connect to it

Parameters:

  • ip (String)

    the ip to use

  • port (Integer)

    the port to connect to

Returns:

  • (Client)

    the created client

Raises:

  • (ArgumentError)

    thrown if ip or port is nil



15
16
17
18
19
20
# File 'lib/kodi_client/extensions/chainable.rb', line 15

def connect(ip, port)
  raise ArgumentError, 'ip or port can\'t be nil.' if ip.nil? || port.nil?

  @client = KodiClient::Client.new
  merge_options(->(options) { options.with_connection(ip, port) })
end

#use_tls(enabled: true) ⇒ Client

enables/disables the use of TLS

Parameters:

  • enabled (Boolean) (defaults to: true)

    true to enable it, false to disable

Returns:

  • (Client)

    the existing, or if not existed, a new created client



35
36
37
# File 'lib/kodi_client/extensions/chainable.rb', line 35

def use_tls(enabled: true)
  merge_options(->(options) { options.with_tls(enabled) })
end