Class: Purest::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/purest/configuration.rb

Overview

Methods for configuring Purest

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil, api_version = nil, url = nil, username = nil, password = nil, options = {}) ⇒ Configuration

Override defaults for configuration

Parameters:

  • api_version (String) (defaults to: nil)

    the API version to interact with

  • url (String) (defaults to: nil)

    pure’s connection URL

  • username (String) (defaults to: nil)

    username to authenticate with

  • password (String) (defaults to: nil)

    password to authenticate with

  • options (Hash) (defaults to: {})

    extra options to configure Faraday::Connection



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/purest/configuration.rb', line 14

def initialize(api_key = nil, api_version = nil, url = nil, username = nil, password = nil, options = {})
  load_yaml
  if load_yaml
    @api_key     = load_yaml['api_key']
    @api_version = load_yaml['api_version']
    @options     = load_yaml['options']
    @password    = load_yaml['password']
    @url         = load_yaml['url']
    @username    = load_yaml['username']
  else
    @api_key     = api_key
    @api_version = api_version
    @options     = options
    @password    = password
    @url         = url
    @username    = username
  end
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



6
7
8
# File 'lib/purest/configuration.rb', line 6

def api_key
  @api_key
end

#api_versionObject

Returns the value of attribute api_version.



6
7
8
# File 'lib/purest/configuration.rb', line 6

def api_version
  @api_version
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/purest/configuration.rb', line 6

def options
  @options
end

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'lib/purest/configuration.rb', line 6

def password
  @password
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/purest/configuration.rb', line 6

def url
  @url
end

#usernameObject

Returns the value of attribute username.



6
7
8
# File 'lib/purest/configuration.rb', line 6

def username
  @username
end

Instance Method Details

#load_yamlObject



33
34
35
36
37
38
39
# File 'lib/purest/configuration.rb', line 33

def load_yaml
  begin
    Psych.load_file(ENV['HOME'] + '/.purest.yaml')
  rescue Errno::ENOENT
    false
  end
end