class Recras::Client

Attributes

host[RW]
password[RW]

@return [String] Your Recras password

username[RW]

@note The is a required parameter.

Public Class Methods

new(args=nil) click to toggle source

Initializer to transform a Hash into an Client object

@param [Hash] args

# File lib/recras/client.rb, line 15
def initialize(args=nil)
  required_args = [] # [:username, :password]
  for arg in required_args
    if args.nil? || args[arg].nil?
      raise RecrasError.new(self), "Insufficient login credentials. Please provide @username, @password and @host"
    end
  end

  return if args.nil?
  args.each do |k,v|
    instance_variable_set("@#{k}", v) unless v.nil?
  end
end

Public Instance Methods

combination(id) click to toggle source

find a specific combination

# File lib/recras/client.rb, line 55
def combination(id)
  json = make_request("arrangementen/#{id}")
  return Recras.parse_json(json: json, endpoint: "arrangementen", client: self)
end
combinations() click to toggle source

returns an array of available combinations

# File lib/recras/client.rb, line 73
def combinations
  result = make_request("arrangementen")
  a = []
  for json in result
    a << Recras.parse_json(json: json, endpoint: "arrangementen", client: self)
  end
  return a
end
make_request(endpoint, body: {}, http_method: :get) click to toggle source

communicates with the server and returns either:

# File lib/recras/client.rb, line 33
def make_request(endpoint, body: {}, http_method: :get)
  Recras.make_request(endpoint, body: body, http_method: http_method, client: self)
end
me() click to toggle source

returns a Me object

# File lib/recras/client.rb, line 49
def me
  json = make_request("personeel/me")
  Recras.parse_json(json: json, endpoint: "personeel")
end
payment_methods() click to toggle source

returns an array of available combinations

# File lib/recras/client.rb, line 62
def payment_methods
  result = make_request("betaalmethoden")
  a = []
  for json in result
    a << Recras.parse_json(json: json, endpoint: "betaalmethoden")
  end
  return a
end
valid() click to toggle source

returns true if credentials are valid, false otherwise

# File lib/recras/client.rb, line 38
def valid
  begin
    me
    return true
  rescue RecrasError
    return false
  end
end
Also aliased as: valid?
valid?()
Alias for: valid