Class: Iterable::Config

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

Overview

Config provides a class to configre the API calls when interacting with REST endpoints

Examples:

Creating a config object

Iterable::Config.new token: 'secret-token'

Constant Summary collapse

DEFAULT_VERSION =
'1.8'.freeze
DEFAULT_HOST =
'https://api.iterable.com'.freeze
DEFAULT_URI =
"#{DEFAULT_HOST}/api".freeze
DEFAULT_PORT =
443

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token: nil) ⇒ Iterable::Config

initialize a new [Iterable::Config] object for requests

Parameters:

  • token (String) (defaults to: nil)

    Iterable API token



23
24
25
26
27
28
# File 'lib/iterable/config.rb', line 23

def initialize(token: nil)
  @host = DEFAULT_HOST
  @port = DEFAULT_PORT
  @version = DEFAULT_VERSION
  @token = token
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



15
16
17
# File 'lib/iterable/config.rb', line 15

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



15
16
17
# File 'lib/iterable/config.rb', line 15

def port
  @port
end

#tokenObject

Returns the value of attribute token.



14
15
16
# File 'lib/iterable/config.rb', line 14

def token
  @token
end

#versionObject (readonly)

Returns the value of attribute version.



15
16
17
# File 'lib/iterable/config.rb', line 15

def version
  @version
end

Instance Method Details

#uriURI

Creates a [URI] for the API host

Returns:

  • (URI)

    API URI object



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

def uri
  URI.parse("#{@host || DEFAULT_HOST}:#{@port || DEFAULT_PORT}/api")
end