module Billomat
A neat ruby library for interacting with the RESTfull API of billomat
Attributes
account[R]
api_path[RW]
domain_format[RW]
email[RW]
host_format[RW]
key[R]
password[RW]
port[RW]
protocol[RW]
Public Class Methods
account=(name)
click to toggle source
Sets the account name and updates all resources with the new domain
# File lib/billomat-rb.rb, line 15 def account=(name) resources.each do |klass| klass.site = klass.site_format % (host_format % [protocol, domain_format % name, ":#{port}", api_path]) end @account = name end
authenticate(email,password)
click to toggle source
Sets up basic authentication credentials for all resources. Removes all earlier authentication info
# File lib/billomat-rb.rb, line 24 def authenticate (email,password) resources.each do |klass| klass.email = email klass.password = password klass.headers.delete 'X-BillomatApiKey' end @email = email @password = password @key = nil end
key=(value)
click to toggle source
Sets the api key for all resource Removes all earlier authentication info
# File lib/billomat-rb.rb, line 37 def key=(value) resources.each do |klass| klass.headers['X-BillomatApiKey'] = value klass.headers['Accept'] = 'application/json' # hack :-( end @key = value @email = nil @password = nil end
resources()
click to toggle source
# File lib/billomat-rb.rb, line 66 def resources @resources ||= [] end
validate()
click to toggle source
Validates connection returns true when valid false when not
# File lib/billomat-rb.rb, line 49 def validate validate! rescue false end
validate!()
click to toggle source
Same as validate but raises http-error when connection is invalid
# File lib/billomat-rb.rb, line 55 def validate! if Billomat.account.nil? raise 'No Account set, use Billomat.account=' end if !Billomat.key.nil? || ( !Billomat.email.nil? && !Billomat.password.nil? ) !!Billomat::Myself.find else raise 'No authentication info set, set either Billomat.key XOR use Billomat.authenticate(email, password)' end end