Class: Recras::Combination
- Inherits:
-
Object
- Object
- Recras::Combination
- Extended by:
- Recras
- Defined in:
- lib/recras/combination.rb
Overview
links to ‘arrangementen’ in the API recras.github.io/docs/endpoints/arrangementen.html
Constant Summary
Constants included from Recras
Instance Attribute Summary collapse
-
#allowed_to_pay_later ⇒ Object
Returns the value of attribute allowed_to_pay_later.
-
#client ⇒ Object
Returns the value of attribute client.
-
#combination_items ⇒ Object
Returns the value of attribute combination_items.
-
#contact_form_id ⇒ Object
Returns the value of attribute contact_form_id.
-
#description ⇒ Object
Returns the value of attribute description.
- #id ⇒ Object
-
#itineraries ⇒ Object
Returns the value of attribute itineraries.
-
#json ⇒ Object
Returns the value of attribute json.
-
#max_number_of_people ⇒ Object
Returns the value of attribute max_number_of_people.
-
#name ⇒ Object
Returns the value of attribute name.
-
#number_of_people ⇒ Object
Returns the value of attribute number_of_people.
-
#price_per_person_incl_vat ⇒ Object
Returns the value of attribute price_per_person_incl_vat.
-
#price_total_incl_vat ⇒ Object
Returns the value of attribute price_total_incl_vat.
-
#seperate_planning ⇒ Object
Returns the value of attribute seperate_planning.
-
#visible_online ⇒ Object
Returns the value of attribute visible_online.
-
#welcome_location ⇒ Object
Returns the value of attribute welcome_location.
Class Method Summary collapse
-
.attribute_mapping ⇒ Object
translates the mapping between the Recras API and the terms used in this gem.
Instance Method Summary collapse
-
#available_days(items: [], number_of_people: nil, from_time: Date.today, until_time: (Time.now + 3600*24*7)) ⇒ Object
returns a list of available days (in string format) for a given campaign example: combination.available_days(combination_items: [1, number_of_people: 2]) If no combination_items are given, assume that you want each item to be booked.
-
#available_times(items: [], number_of_people: nil, date: nil) ⇒ Object
returns a list of available days (in string format) for a given campaign exampel: combination.available_days(combination_items: [1, number_of_people: 2]) If no combination_items are given, assume that you want each item to be booked.
-
#book(items: [], marked_as_paid: false, number_of_people: nil, date: nil, payment_method: "factuur", status: "reservering", contact_form_details: {}) ⇒ Object
(also: #make_booking)
make a reservation for this combination.
-
#contact_form ⇒ Object
returns a Recras::ContactForm.
-
#initialize(args = nil) ⇒ Combination
constructor
Initializer to transform a
Hash
into an Combination object.
Methods included from Recras
make_request, new_from_json, object_mappings, parse_json, url, version
Constructor Details
#initialize(args = nil) ⇒ Combination
Initializer to transform a Hash
into an Combination object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/recras/combination.rb', line 28 def initialize(args=nil) required_args = [] for arg in required_args if args.nil? || args[arg].nil? raise RecrasError.new(self), "Insufficient login credentials. Please provide @username, @password" end end return if args.nil? args.each do |k,v| instance_variable_set("@#{k}", v) unless v.nil? end end |
Instance Attribute Details
#allowed_to_pay_later ⇒ Object
Returns the value of attribute allowed_to_pay_later.
15 16 17 |
# File 'lib/recras/combination.rb', line 15 def allowed_to_pay_later @allowed_to_pay_later end |
#client ⇒ Object
Returns the value of attribute client.
23 24 25 |
# File 'lib/recras/combination.rb', line 23 def client @client end |
#combination_items ⇒ Object
Returns the value of attribute combination_items.
16 17 18 |
# File 'lib/recras/combination.rb', line 16 def combination_items @combination_items end |
#contact_form_id ⇒ Object
Returns the value of attribute contact_form_id.
22 23 24 |
# File 'lib/recras/combination.rb', line 22 def contact_form_id @contact_form_id end |
#description ⇒ Object
Returns the value of attribute description.
18 19 20 |
# File 'lib/recras/combination.rb', line 18 def description @description end |
#id ⇒ Object
The is a required parameter.
9 10 11 |
# File 'lib/recras/combination.rb', line 9 def id @id end |
#itineraries ⇒ Object
Returns the value of attribute itineraries.
17 18 19 |
# File 'lib/recras/combination.rb', line 17 def itineraries @itineraries end |
#json ⇒ Object
Returns the value of attribute json.
24 25 26 |
# File 'lib/recras/combination.rb', line 24 def json @json end |
#max_number_of_people ⇒ Object
Returns the value of attribute max_number_of_people.
13 14 15 |
# File 'lib/recras/combination.rb', line 13 def max_number_of_people @max_number_of_people end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/recras/combination.rb', line 10 def name @name end |
#number_of_people ⇒ Object
Returns the value of attribute number_of_people.
14 15 16 |
# File 'lib/recras/combination.rb', line 14 def number_of_people @number_of_people end |
#price_per_person_incl_vat ⇒ Object
Returns the value of attribute price_per_person_incl_vat.
19 20 21 |
# File 'lib/recras/combination.rb', line 19 def price_per_person_incl_vat @price_per_person_incl_vat end |
#price_total_incl_vat ⇒ Object
Returns the value of attribute price_total_incl_vat.
20 21 22 |
# File 'lib/recras/combination.rb', line 20 def price_total_incl_vat @price_total_incl_vat end |
#seperate_planning ⇒ Object
Returns the value of attribute seperate_planning.
21 22 23 |
# File 'lib/recras/combination.rb', line 21 def seperate_planning @seperate_planning end |
#visible_online ⇒ Object
Returns the value of attribute visible_online.
12 13 14 |
# File 'lib/recras/combination.rb', line 12 def visible_online @visible_online end |
#welcome_location ⇒ Object
Returns the value of attribute welcome_location.
11 12 13 |
# File 'lib/recras/combination.rb', line 11 def welcome_location @welcome_location end |
Class Method Details
.attribute_mapping ⇒ Object
translates the mapping between the Recras API and the terms used in this gem
163 164 165 |
# File 'lib/recras/combination.rb', line 163 def self.attribute_mapping [["id", "id"],["weergavenaam", "name"],["mag_online", "visible_online"],["aantal_personen", "number_of_people"], ["mag_online_geboekt_worden_achteraf_betalen", "allowed_to_pay_later"], ["regels", Recras::CombinationItem], ["programma", Recras::Itinerary], ["onlineboeking_contactformulier_id", "contact_form_id"], ["prijs_pp_inc","price_per_person_incl_vat"], ["prijs_totaal_inc","price_total_incl_vat"],["los_op_planning", "seperate_planning"],["uitgebreide_omschrijving","description"], ["maximum_aantal_personen_online","max_number_of_people"], ["ontvangstlocatie", "welcome_location"]] end |
Instance Method Details
#available_days(items: [], number_of_people: nil, from_time: Date.today, until_time: (Time.now + 3600*24*7)) ⇒ Object
returns a list of available days (in string format) for a given campaign example: combination.available_days(combination_items: [1, number_of_people: 2]) If no combination_items are given, assume that you want each item to be booked. In that scenario, also use the ‘number_of_people’ argument. E.g.: @combination.available_days(number_of_people: 2).
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/recras/combination.rb', line 57 def available_days(items: [], number_of_people: nil, from_time: Date.today, until_time: (Time.now + 3600*24*7)) if items && items.any? begin puts "starting product_items (#{items})" product_items = convert_items(items, number_of_people) rescue # no items end end if product_items && product_items.any? body_data = { arrangement_id: id, producten: product_items, begin: from_time.strftime("%Y-%m-%d"), eind: until_time.strftime("%Y-%m-%d") } elsif number_of_people body_data = { arrangement_id: id, begin: from_time.strftime("%Y-%m-%d"), eind: until_time.strftime("%Y-%m-%d") } else raise RecrasError.new(self), "Insufficient details provided. Either combination_items or number_of_people are required." end # make request json = client.make_request("onlineboeking/beschikbaredagen", body: body_data.to_json, http_method: :post) if json.is_a?(Hash) && json["error"] raise RecrasError.new(self), json["message"] else return json end end |
#available_times(items: [], number_of_people: nil, date: nil) ⇒ Object
returns a list of available days (in string format) for a given campaign exampel: combination.available_days(combination_items: [1, number_of_people: 2]) If no combination_items are given, assume that you want each item to be booked. In that scenario, also use the ‘number_of_people’ argument. E.g.: @combination.available_days(number_of_people: 2).
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/recras/combination.rb', line 99 def available_times(items: [], number_of_people: nil, date: nil) product_items = convert_items(items, number_of_people) # convert date date = convert_date(date) if product_items.any? body_data = { arrangement_id: id, producten: product_items, datum: date } json = client.make_request("onlineboeking/beschikbaretijden", body: body_data.to_json, http_method: :post) if json.is_a?(Hash) && json["error"] raise RecrasError.new(self), json["error"]["message"] else return json end else raise RecrasError.new(self), "Insufficient details provided. Either combination_items or number_of_people are required." end end |
#book(items: [], marked_as_paid: false, number_of_people: nil, date: nil, payment_method: "factuur", status: "reservering", contact_form_details: {}) ⇒ Object Also known as: make_booking
make a reservation for this combination
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/recras/combination.rb', line 121 def book(items: [], marked_as_paid: false, number_of_people: nil, date: nil, payment_method: "factuur", status: "reservering", contact_form_details: {}) product_items = convert_items(items, number_of_people) date = convert_date(date) if product_items.any? body_data = { arrangement_id: id, producten: product_items, begin: date, status: status, betaalmethode: payment_method, stuur_bevestiging_email: marked_as_paid, contactformulier: contact_form_details } json = client.make_request("onlineboeking/reserveer", body: body_data.to_json, http_method: :post) if json.is_a?(Hash) && json["error"] raise RecrasError.new(self), json["error"]["message"] else booking = Recras.parse_json(json: json, endpoint: "booking", client: client) return booking end else raise RecrasError.new(self), "Insufficient details provided. Either combination_items or number_of_people are required." end end |
#contact_form ⇒ Object
returns a Recras::ContactForm
45 46 47 48 49 |
# File 'lib/recras/combination.rb', line 45 def contact_form json = client.make_request("contactformulieren/#{contact_form_id}") cf = Recras.parse_json(json: json, endpoint: "contactformulier", client: client) return cf end |