Class: CubeSmart::Config
- Inherits:
-
Object
- Object
- CubeSmart::Config
- Defined in:
- lib/cubesmart/config.rb
Overview
The core configuration.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#headers ⇒ Hash<String, String>
E.g { ‘User-Agent’ => ‘cubesmart.rb/1.0.0’ }.
- #headers? ⇒ Boolean
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #proxy? ⇒ Boolean
- #timeout? ⇒ Boolean
-
#via ⇒ Array
E.g.
Constructor Details
#initialize ⇒ Config
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_language ⇒ String
8 9 10 |
# File 'lib/cubesmart/config.rb', line 8 def accept_language @accept_language end |
#proxy_url ⇒ String
20 21 22 |
# File 'lib/cubesmart/config.rb', line 20 def proxy_url @proxy_url end |
#timeout ⇒ Integer
16 17 18 |
# File 'lib/cubesmart/config.rb', line 16 def timeout @timeout end |
#user_agent ⇒ String
12 13 14 |
# File 'lib/cubesmart/config.rb', line 12 def user_agent @user_agent end |
Instance Method Details
#headers ⇒ Hash<String, String>
Returns 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
30 31 32 |
# File 'lib/cubesmart/config.rb', line 30 def headers? !@user_agent.nil? end |
#proxy? ⇒ Boolean
40 41 42 |
# File 'lib/cubesmart/config.rb', line 40 def proxy? !@proxy_url.nil? end |
#timeout? ⇒ Boolean
35 36 37 |
# File 'lib/cubesmart/config.rb', line 35 def timeout? !@timeout.zero? end |
#via ⇒ Array
Returns 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 |