recras 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/recras/invoice.rb +52 -0
- data/lib/recras/payment.rb +30 -0
- data/lib/recras/payment_method.rb +32 -0
- data/lib/recras/product.rb +201 -0
- data/lib/recras/version.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63217d280e4a3d2f4ce009fc506363780ae8b45c
|
4
|
+
data.tar.gz: 38706ea363b871e407ebbde5c7a969d505e84392
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a51bf13ddc061bfa963f9ef46115203e580cc17c40373780d4e92a27a5ce8d35fbca500c35f0d027478abe7a557791693c71d485ff4e441f38c69eee9f02362e
|
7
|
+
data.tar.gz: e3de794bb2bc7faa2a9683487d811ffe2f357a3f84df52e1d811092d5f3b77d6ad57a56f5932c544d478922b61999ae0027d4fc140d2342e5db8e2fca41b7d87
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Recras
|
2
|
+
|
3
|
+
# links to 'arrangement_regels' in the API
|
4
|
+
# http://recras.github.io/docs/endpoints/facturen.html
|
5
|
+
class Invoice
|
6
|
+
extend Recras
|
7
|
+
# @note The is a required parameter.
|
8
|
+
|
9
|
+
attr_accessor :id
|
10
|
+
attr_accessor :status
|
11
|
+
attr_accessor :message
|
12
|
+
attr_accessor :customer_id
|
13
|
+
attr_accessor :payment_url
|
14
|
+
|
15
|
+
# Initializer to transform a +Hash+ into an Client object
|
16
|
+
# @param [Hash] args
|
17
|
+
def initialize(args=nil)
|
18
|
+
required_args = []
|
19
|
+
return if args.nil?
|
20
|
+
args.each do |k,v|
|
21
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# translates the mapping between the Recras API
|
26
|
+
# and the terms used in this gem
|
27
|
+
def self.attribute_mapping
|
28
|
+
[
|
29
|
+
["id", "id"],
|
30
|
+
["status", "status"]
|
31
|
+
]
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def make_payment(status: "concept", comment: "", payment_method_id: nil, amount: 0.0)
|
36
|
+
body_data = {
|
37
|
+
factuur_id: id,
|
38
|
+
betaalmethode_id: payment_method_id,
|
39
|
+
bedrag: amount
|
40
|
+
}
|
41
|
+
json = client.make_request("facturen/#{id}/betalingen", body: body_data.to_json, http_method: :post)
|
42
|
+
if json.is_a?(Hash) && json["error"]
|
43
|
+
raise RecrasError.new(self), json["error"]["message"]
|
44
|
+
else
|
45
|
+
payment = Recras.parse_json(json: json, endpoint: "betalingen")
|
46
|
+
return payment
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Recras
|
2
|
+
|
3
|
+
class Payment
|
4
|
+
extend Recras
|
5
|
+
# @note The is a required parameter.
|
6
|
+
|
7
|
+
attr_accessor :id
|
8
|
+
attr_accessor :status
|
9
|
+
|
10
|
+
# Initializer to transform a +Hash+ into an Client object
|
11
|
+
# @param [Hash] args
|
12
|
+
def initialize(args=nil)
|
13
|
+
required_args = []
|
14
|
+
return if args.nil?
|
15
|
+
args.each do |k,v|
|
16
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# translates the mapping between the Recras API
|
21
|
+
# and the terms used in this gem
|
22
|
+
def self.attribute_mapping
|
23
|
+
[
|
24
|
+
["id", "id"],
|
25
|
+
["status", "status"]
|
26
|
+
]
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Recras
|
2
|
+
|
3
|
+
# links to 'arrangement_regels' in the API
|
4
|
+
# http://recras.github.io/docs/endpoints/betaalmethoden.html
|
5
|
+
class PaymentMethod
|
6
|
+
extend Recras
|
7
|
+
# @note The is a required parameter.
|
8
|
+
|
9
|
+
attr_accessor :id
|
10
|
+
attr_accessor :name
|
11
|
+
|
12
|
+
# Initializer to transform a +Hash+ into an Client object
|
13
|
+
# @param [Hash] args
|
14
|
+
def initialize(args=nil)
|
15
|
+
required_args = []
|
16
|
+
return if args.nil?
|
17
|
+
args.each do |k,v|
|
18
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# translates the mapping between the Recras API
|
23
|
+
# and the terms used in this gem
|
24
|
+
def self.attribute_mapping
|
25
|
+
[
|
26
|
+
["id", "id"],
|
27
|
+
["naam", "name"]
|
28
|
+
]
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,201 @@
|
|
1
|
+
module Recras
|
2
|
+
|
3
|
+
# links to 'arrangementen' in the API
|
4
|
+
# http://recras.github.io/docs/endpoints/arrangementen.html
|
5
|
+
# class Combination
|
6
|
+
# extend Recras
|
7
|
+
# # @note The is a required parameter.
|
8
|
+
|
9
|
+
# attr_accessor :id
|
10
|
+
# attr_accessor :name
|
11
|
+
# attr_accessor :welcome_location
|
12
|
+
# attr_accessor :visible_online
|
13
|
+
# attr_accessor :max_number_of_people
|
14
|
+
# attr_accessor :number_of_people
|
15
|
+
# attr_accessor :allowed_to_pay_later
|
16
|
+
# attr_accessor :combination_items
|
17
|
+
# attr_accessor :itineraries
|
18
|
+
# attr_accessor :description
|
19
|
+
# attr_accessor :price_per_person_incl_vat
|
20
|
+
# attr_accessor :price_total_incl_vat
|
21
|
+
# attr_accessor :seperate_planning
|
22
|
+
# attr_accessor :contact_form_id
|
23
|
+
# attr_accessor :client
|
24
|
+
# attr_accessor :json
|
25
|
+
|
26
|
+
# # Initializer to transform a +Hash+ into an Combination object
|
27
|
+
# # @param [Hash] args
|
28
|
+
# def initialize(args=nil)
|
29
|
+
# required_args = []
|
30
|
+
# for arg in required_args
|
31
|
+
# if args.nil? || args[arg].nil?
|
32
|
+
# raise RecrasError.new(self), "Insufficient login credentials. Please provide @username, @password"
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
|
36
|
+
# return if args.nil?
|
37
|
+
# args.each do |k,v|
|
38
|
+
# instance_variable_set("@#{k}", v) unless v.nil?
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
# # returns a Recras::ContactForm
|
45
|
+
# def contact_form
|
46
|
+
# json = client.make_request("contactformulieren/#{contact_form_id}")
|
47
|
+
# cf = Recras.parse_json(json: json, endpoint: "contactformulier", client: client)
|
48
|
+
# return cf
|
49
|
+
# end
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
# # returns a list of available days (in string format) for a given campaign
|
54
|
+
# # example: combination.available_days(combination_items: [{combination_item_id: 1, number_of_people: 2}])
|
55
|
+
# # If no combination_items are given, assume that you want each item to be booked. In that scenario,
|
56
|
+
# # also use the 'number_of_people' argument. E.g.: @combination.available_days(number_of_people: 2).
|
57
|
+
# def available_days(items: [], number_of_people: nil, from_time: Date.today, until_time: (Time.now + 3600*24*7))
|
58
|
+
# if items && items.any?
|
59
|
+
# begin
|
60
|
+
# puts "starting product_items (#{items})"
|
61
|
+
# product_items = convert_items(items, number_of_people)
|
62
|
+
# rescue
|
63
|
+
# # no items
|
64
|
+
# end
|
65
|
+
# end
|
66
|
+
# if product_items && product_items.any?
|
67
|
+
# body_data = {
|
68
|
+
# arrangement_id: id,
|
69
|
+
# producten: product_items,
|
70
|
+
# begin: from_time.strftime("%Y-%m-%d"),
|
71
|
+
# eind: until_time.strftime("%Y-%m-%d")
|
72
|
+
# }
|
73
|
+
# elsif number_of_people
|
74
|
+
# body_data = {
|
75
|
+
# arrangement_id: id,
|
76
|
+
# begin: from_time.strftime("%Y-%m-%d"),
|
77
|
+
# eind: until_time.strftime("%Y-%m-%d")
|
78
|
+
# }
|
79
|
+
# else
|
80
|
+
# raise RecrasError.new(self), "Insufficient details provided. Either combination_items or number_of_people are required."
|
81
|
+
# end
|
82
|
+
# # make request
|
83
|
+
# json = client.make_request("onlineboeking/beschikbaredagen", body: body_data.to_json, http_method: :post)
|
84
|
+
|
85
|
+
|
86
|
+
# if json.is_a?(Hash) && json["error"]
|
87
|
+
# raise RecrasError.new(self), json["message"]
|
88
|
+
# else
|
89
|
+
# return json
|
90
|
+
# end
|
91
|
+
|
92
|
+
# end
|
93
|
+
|
94
|
+
|
95
|
+
# # returns a list of available days (in string format) for a given campaign
|
96
|
+
# # exampel: combination.available_days(combination_items: [{combination_item_id: 1, number_of_people: 2}])
|
97
|
+
# # If no combination_items are given, assume that you want each item to be booked. In that scenario,
|
98
|
+
# # also use the 'number_of_people' argument. E.g.: @combination.available_days(number_of_people: 2).
|
99
|
+
# def available_times(items: [], number_of_people: nil, date: nil)
|
100
|
+
# product_items = convert_items(items, number_of_people)
|
101
|
+
|
102
|
+
# # convert date
|
103
|
+
# date = convert_date(date)
|
104
|
+
|
105
|
+
# if product_items.any?
|
106
|
+
# body_data = { arrangement_id: id, producten: product_items, datum: date }
|
107
|
+
# json = client.make_request("onlineboeking/beschikbaretijden", body: body_data.to_json, http_method: :post)
|
108
|
+
|
109
|
+
# if json.is_a?(Hash) && json["error"]
|
110
|
+
# raise RecrasError.new(self), json["error"]["message"]
|
111
|
+
# else
|
112
|
+
# return json
|
113
|
+
# end
|
114
|
+
# else
|
115
|
+
# raise RecrasError.new(self), "Insufficient details provided. Either combination_items or number_of_people are required."
|
116
|
+
# end
|
117
|
+
# end
|
118
|
+
|
119
|
+
|
120
|
+
# # make a reservation for this combination
|
121
|
+
# def book(items: [], number_of_people: nil, date: nil, payment_method: "factuur", contact_form_details: {})
|
122
|
+
|
123
|
+
# product_items = convert_items(items, number_of_people)
|
124
|
+
# date = convert_date(date)
|
125
|
+
|
126
|
+
# if product_items.any?
|
127
|
+
# body_data = {
|
128
|
+
# arrangement_id: id,
|
129
|
+
# producten: product_items,
|
130
|
+
# begin: date,
|
131
|
+
# betaalmethode: payment_method,
|
132
|
+
# contactformulier: contact_form_details
|
133
|
+
# }
|
134
|
+
# json = client.make_request("onlineboeking/reserveer", body: body_data.to_json, http_method: :post)
|
135
|
+
|
136
|
+
# if json.is_a?(Hash) && json["error"]
|
137
|
+
# raise RecrasError.new(self), json["error"]["message"]
|
138
|
+
# else
|
139
|
+
# booking = Recras.parse_json(json: json, endpoint: "booking")
|
140
|
+
# return booking
|
141
|
+
# end
|
142
|
+
# else
|
143
|
+
# raise RecrasError.new(self), "Insufficient details provided. Either combination_items or number_of_people are required."
|
144
|
+
# end
|
145
|
+
|
146
|
+
# end
|
147
|
+
# alias_method :make_booking, :book
|
148
|
+
|
149
|
+
# # returns an array of combination_items
|
150
|
+
# # def combination_items
|
151
|
+
# # result = make_request("arrangementen")
|
152
|
+
# # a = []
|
153
|
+
# # for json in result
|
154
|
+
# # a << Recras.parse_json(json: json, endpoint: "arrangementen")
|
155
|
+
# # end
|
156
|
+
# # return a
|
157
|
+
# # end
|
158
|
+
|
159
|
+
# # translates the mapping between the Recras API
|
160
|
+
# # and the terms used in this gem
|
161
|
+
# def self.attribute_mapping
|
162
|
+
# [["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"]]
|
163
|
+
# end
|
164
|
+
|
165
|
+
# private
|
166
|
+
|
167
|
+
# def convert_date(date)
|
168
|
+
# if date.is_a?(Time)
|
169
|
+
# return date.iso8601
|
170
|
+
# elsif date.is_a?(String)
|
171
|
+
# return Time.parse(date).iso8601
|
172
|
+
# else
|
173
|
+
# raise RecrasError.new(self), "Date is required and must be of type Time or String (ISO 8601)."
|
174
|
+
# end
|
175
|
+
# end
|
176
|
+
|
177
|
+
# def convert_items(items, number_of_people)
|
178
|
+
# if items && items.any?
|
179
|
+
# # TODO
|
180
|
+
# elsif number_of_people && number_of_people > 0
|
181
|
+
# # assume that all the items will be chose the same amount
|
182
|
+
# items = []
|
183
|
+
# for combination_item in combination_items
|
184
|
+
# items << {combination_item_id: combination_item.id, number_of_people: number_of_people}
|
185
|
+
# end
|
186
|
+
# end
|
187
|
+
|
188
|
+
# if items && items.any?
|
189
|
+
# mappings = {combination_item_id: "arrangementsregel_id", number_of_people: "aantal"}
|
190
|
+
# product_items = []
|
191
|
+
# for item in items
|
192
|
+
# product_items << item.map {|k, v| [mappings[k], v] }.to_h
|
193
|
+
# end
|
194
|
+
# return product_items
|
195
|
+
# end
|
196
|
+
|
197
|
+
# return items
|
198
|
+
# end
|
199
|
+
|
200
|
+
# end
|
201
|
+
end
|
data/lib/recras/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recras
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henk Meijer
|
@@ -119,8 +119,12 @@ files:
|
|
119
119
|
- lib/recras/config.rb
|
120
120
|
- lib/recras/contact_form.rb
|
121
121
|
- lib/recras/contact_form_field.rb
|
122
|
+
- lib/recras/invoice.rb
|
122
123
|
- lib/recras/itinerary.rb
|
124
|
+
- lib/recras/payment.rb
|
125
|
+
- lib/recras/payment_method.rb
|
123
126
|
- lib/recras/person.rb
|
127
|
+
- lib/recras/product.rb
|
124
128
|
- lib/recras/recras_error.rb
|
125
129
|
- lib/recras/version.rb
|
126
130
|
- recras.gemspec
|