Class: CubeSmart::Config

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

Overview

The core configuration.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



22
23
24
25
26
27
# File 'lib/cubesmart/config.rb', line 22

def initialize
  @accept_language = ENV.fetch('CUBESMART_ACCEPT_LANGUAGE', 'en-US,en;q=0.9')
  @user_agent = ENV.fetch('CUBESMART_USER_AGENT', "cubesmart.rb/#{VERSION}")
  @timeout = Integer(ENV.fetch('CUBESMART_TIMEOUT', 60))
  @proxy_url = ENV.fetch('CUBESMART_PROXY_URL', nil)
end

Instance Attribute Details

#accept_languageString

Returns:

  • (String)


8
9
10
# File 'lib/cubesmart/config.rb', line 8

def accept_language
  @accept_language
end

#proxy_urlString

Returns:

  • (String)


20
21
22
# File 'lib/cubesmart/config.rb', line 20

def proxy_url
  @proxy_url
end

#timeoutInteger

Returns:

  • (Integer)


16
17
18
# File 'lib/cubesmart/config.rb', line 16

def timeout
  @timeout
end

#user_agentString

Returns:

  • (String)


12
13
14
# File 'lib/cubesmart/config.rb', line 12

def user_agent
  @user_agent
end

Instance Method Details

#headersHash<String, String>

Returns e.g { ‘User-Agent’ => ‘cubesmart.rb/1.0.0’ }.

Returns:

  • (Hash<String, String>)

    e.g { ‘User-Agent’ => ‘cubesmart.rb/1.0.0’ }



45
46
47
48
49
50
# File 'lib/cubesmart/config.rb', line 45

def headers
  {
    'Accept-Language' => @accept_language,
    'User-Agent' => @user_agent
  }
end

#headers?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/cubesmart/config.rb', line 30

def headers?
  !@user_agent.nil?
end

#proxy?Boolean

Returns:

  • (Boolean)


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

def proxy?
  !@proxy_url.nil?
end

#timeout?Boolean

Returns:

  • (Boolean)


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

def timeout?
  !@timeout.zero?
end

#viaArray

Returns e.g. [‘proxy.example.com’, 8080, ‘user’, ‘pass’].

Returns:

  • (Array)

    e.g. [‘proxy.example.com’, 8080, ‘user’, ‘pass’]



53
54
55
56
# File 'lib/cubesmart/config.rb', line 53

def via
  proxy_uri = URI.parse(@proxy_url)
  [proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password]
end