Class: Valuefirst::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Config

Returns a new instance of Config.



5
6
7
8
9
10
11
# File 'lib/valuefirst/config.rb', line 5

def initialize(opts = {})
  @username = opts[:username]
  @password = opts[:password]
  @default_sender = opts[:default_sender]
  @url      = opts[:url] || "http://api.myvaluefirst.com/psms/servlet/psms.Eservice2"
  @version  = opts[:version] || '1.2'
end

Instance Attribute Details

#default_senderObject

Returns the value of attribute default_sender.



3
4
5
# File 'lib/valuefirst/config.rb', line 3

def default_sender
  @default_sender
end

#passwordObject

Returns the value of attribute password.



3
4
5
# File 'lib/valuefirst/config.rb', line 3

def password
  @password
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/valuefirst/config.rb', line 3

def url
  @url
end

#usernameObject

Returns the value of attribute username.



3
4
5
# File 'lib/valuefirst/config.rb', line 3

def username
  @username
end

#versionObject

Returns the value of attribute version.



3
4
5
# File 'lib/valuefirst/config.rb', line 3

def version
  @version
end

Instance Method Details

#validateObject



13
14
15
16
17
18
19
20
21
# File 'lib/valuefirst/config.rb', line 13

def validate
  errors = []
  errors << "Invalid username" if @username.nil? || @username.empty? 
  errors << "Invalid password" if @password.nil? || @password.empty?
  errors << "API version not supported" unless @version == '1.2'
  unless errors.empty?
    raise ArgumentError, "#{errors.join(', ')}"
  end
end