Class: Recras::Booking

Inherits:
Object
  • Object
show all
Extended by:
Recras
Defined in:
lib/recras/booking.rb

Overview

links to ‘arrangement_regels’ in the API recras.github.io/docs/endpoints/contactformulieren.html

Constant Summary

Constants included from Recras

API_VERSION, VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Recras

make_request, new_from_json, object_mappings, parse_json, url, version

Constructor Details

#initialize(args = nil) ⇒ Booking

Initializer to transform a Hash into an Client object

Parameters:

  • args (Hash) (defaults to: nil)


18
19
20
21
22
23
24
# File 'lib/recras/booking.rb', line 18

def initialize(args=nil)
  required_args = []
  return if args.nil?
  args.each do |k,v|
    instance_variable_set("@#{k}", v) unless v.nil?
  end
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



14
15
16
# File 'lib/recras/booking.rb', line 14

def client
  @client
end

#customer_idObject

Returns the value of attribute customer_id.



12
13
14
# File 'lib/recras/booking.rb', line 12

def customer_id
  @customer_id
end

#idObject

Note:

The is a required parameter.



9
10
11
# File 'lib/recras/booking.rb', line 9

def id
  @id
end

#messageObject

Returns the value of attribute message.



11
12
13
# File 'lib/recras/booking.rb', line 11

def message
  @message
end

#payment_urlObject

Returns the value of attribute payment_url.



13
14
15
# File 'lib/recras/booking.rb', line 13

def payment_url
  @payment_url
end

#statusObject

Returns the value of attribute status.



10
11
12
# File 'lib/recras/booking.rb', line 10

def status
  @status
end

Class Method Details

.attribute_mappingObject

translates the mapping between the Recras API and the terms used in this gem



28
29
30
31
32
33
34
35
36
37
# File 'lib/recras/booking.rb', line 28

def self.attribute_mapping
  [
    ["id", "id"],
    ["status", "status"],
    ["message", "message"], 
    ["boeking_id", "id"], 
    ["klant_id", "customer_id"], 
    ["payment_url", "payment_url"]
  ]
end

Instance Method Details

#make_invoice(status: 'concept') ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/recras/booking.rb', line 39

def make_invoice(status: 'concept')

  body_data = {
    boeking_id: id,
    status: status
  }
  json = client.make_request("facturen", body: body_data.to_json, http_method: :post)
  if json.is_a?(Hash) && json["error"]
    raise RecrasError.new(self), json["error"]["message"]
  else
    invoice = Recras.parse_json(json: json, endpoint: "facturen")
    return invoice
  end

end