recras 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c304fa9873e27a97cf05afcf7615653d2947a73d
4
+ data.tar.gz: fa2c66e1f46bf7d18f31b2325161fac8e639dcc3
5
+ SHA512:
6
+ metadata.gz: b3feab0297d08798da8d17254b01bb88e9301359c54979c4ef460984d7577921920ce100000ddd25819e28427066c79a85a124c945d9e9cf5687827ae68c12da
7
+ data.tar.gz: d4f302f753d332450015081b3d97669685fbd7fa1f084861cd94905997aefa44fc6f7bf980cb9b7fad7da2fd737b22ac8a79b531359d0c50f508a2cc63b3309a
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.3
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in recras.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Henk Meijer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,151 @@
1
+ # Recras
2
+
3
+ The Recras gem is a straight forward ruby binder for the Recras API V2. This gem covers a great portion of the native API functionality, but certainly not a 100%. Feel free to fork this project and make adjustments.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'recras'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install recras
21
+
22
+ ## Usage
23
+
24
+ To request two barcodes from two different ticket kinds (4 barcodes in total), you can do the following:
25
+
26
+ ### Setup
27
+ ```ruby
28
+ # Setup the Recras client with credentials
29
+ @recras_client = Recras::Client.new(username: 'beheer', password: 'demo')
30
+
31
+ # Check the credentials first
32
+ @recras_client.valid? #returns true or false
33
+
34
+ # Get details about current user
35
+ @recras_client.me # => #<Recras::Person:0x007fca5492ddf0 @id=1, @name="Joe Sixpack, @address="Street 1", @postal_code="1234 AB", @city="Amsterdam", @country_code="", @company_id=1, @phone="", @email="test@example.org">
36
+
37
+ ```
38
+
39
+ ### Combinations
40
+ The Recras system bundles different products together in 'combinations'. Their API uses the term 'arrangementen' for it.
41
+
42
+ A combination has a number of fields. __Not all the fields present in the native API are implemented. Feel free to add those and issue a pull request.__
43
+
44
+ - id
45
+ - name
46
+ - visible_online
47
+ - number_of_people
48
+ - allowed_to_pay_later
49
+ - combination_items
50
+ - contact_form_id
51
+ - client (returns the client object that made the request)
52
+
53
+
54
+ ```ruby
55
+ # List the clients combinations
56
+ @recras_client.combinations # => returns an array of <Recras::Combination> objects
57
+
58
+ # Find a single combination:
59
+ @recras_client.combination(4) => <Recras::Combination:0x007fc617cd1948 @id=4 ...>
60
+ ```
61
+
62
+ ### CombinationItem
63
+ Each combination has multiple combination_items. In the native API these are called 'arrangementregels'. When checking availability or making a reservation, you always have to enter both the combination **and** the individual combination_items+number_of_people.
64
+
65
+ Attributes:
66
+ - id
67
+ - location_id
68
+ - begins_at (ISO 8601 Date Time format)
69
+ - ends_at (ISO 8601 Date Time format)
70
+ - description
71
+ - number_of_people
72
+ - product_id
73
+
74
+ ```ruby
75
+ # You can find the combination_items only through a combination:
76
+ @combination = @recras_client.combinations.last
77
+ @combination_items = @combination.combination_items # => Array of <Recras::CombinationItem> objects
78
+ ```
79
+
80
+ ### Checking availability
81
+ Checking the availability is always a two-steps process:
82
+ 1. Check the available days for chosen combination
83
+ 2. Fetch the available times for chosen day
84
+
85
+ The `@combination.available_days` method takes several arguments:
86
+
87
+ ```ruby
88
+ available_days(items: [], number_of_people: nil, from_time: Date.today, until_time: (Time.now + 3600*24*7))
89
+ ```
90
+
91
+ - `items:` array of hashes. Example: `[{combination_item_id: 2, number_of_people: 1}, {combination_item_id: 5, number_of_people: 4}]`
92
+ - `number_of_people:` an integer greater than 0.
93
+ - `from_time` Start of date range
94
+ - `until_time` End of date range
95
+
96
+ __Important:__ If you don't supply the `items` argument, you have to enter a `number_of_people`. This gem than makes the assumption that you want each item in this combination to be chosen the same amount of times.
97
+ #### Checking available days
98
+ ```ruby
99
+ @combination.available_days(number_of_people: 2) #=> ["2017-04-11", "2017-04-12", "2017-04-13", "2017-04-14", "2017-04-15", "2017-04-17", "2017-04-18"]
100
+
101
+ ```
102
+
103
+ #### Checking available times
104
+ ```ruby
105
+ @combination.available_times(number_of_people: 2, date: "2018-04-11") #=> ["2017-04-14T11:00:00+02:00", "2017-04-14T11:30:00+02:00", "2017-04-14T12:00:00+02:00", "2017-04-14T12:30:00+02:00", "2017-04-14T13:00:00+02:00", "2017-04-14T13:30:00+02:00"]
106
+
107
+ ```
108
+
109
+ ### ContactForm
110
+ If you see the checkout page of any of Recras' clients, you'll notice that the consumer has to fill in a couple of fields in the last step before the booking. These fields are specific to the selected Combination (arrangement). To know which fields to show, how to label them and with which identifier to submit them, you use the `@combination.contact_form`. In it are `<Recras::ContactFormField>` objects.
111
+
112
+
113
+ ### Make a booking
114
+ Making a booking is not much different from checking times: you need to know when the consumer wants to book and wich items+quantity. It looks like this:
115
+ __Please note:__ in the example below, we assume that the consumer want to book 2 units of every CombinationItem in given combination.
116
+ ```ruby
117
+ contact_form_details: {
118
+ "contact.naam"=>"",
119
+ "contactpersoon.voornaam"=>"Voornaam",
120
+ "contactpersoon.achternaam"=>"Achternaam",
121
+ "contactpersoon.email1"=>"test@example.org",
122
+ "contactpersoon.telefoon1"=>"",
123
+ "contactpersoon.adres"=>"",
124
+ "contactpersoon.postcode"=>"",
125
+ "contactpersoon.plaats"=>"",
126
+ "veel_tekst_0"=>""
127
+ }
128
+
129
+ @combination.book(number_of_people: 2, date: "2017-04-14T13:00:00+02:00", contact_form_details: contact_form_details) # => #<Recras::Booking:0x007f99bab94c30 @id=8994, @status="reservering", @message="Boeking gemaakt", @customer_id=8986>
130
+ ```
131
+
132
+
133
+ ## Development
134
+
135
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
136
+
137
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
138
+
139
+ ## Contributing
140
+
141
+ Bug reports and pull requests are welcome on GitHub at https://github.com/henkm/wheretocard.
142
+
143
+
144
+ ## License
145
+
146
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
147
+
148
+ ## Credits and disclaimer
149
+
150
+ This gem is made with love by the smart people at [Eskes Media B.V.](http://www.eskesmedia.nl) and [dagjewegtickets.nl](https://www.dagjewegtickets.nl)
151
+ Recras is not involved with this project and has no affiliation with Eskes Media B.V. No rights can be derrived from using this gem.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "recras"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,116 @@
1
+ # load external dependencies first
2
+ require 'httparty'
3
+ require 'time'
4
+
5
+ # load own classes
6
+ require "recras/version"
7
+ require "recras/config"
8
+ require "recras/recras_error"
9
+ # require "recras/api" not needed anymore, is now in client.rb
10
+ require "recras/client"
11
+ require "recras/person"
12
+ require "recras/combination"
13
+ require "recras/combination_item"
14
+ require "recras/contact_form"
15
+ require "recras/contact_form_field"
16
+ require "recras/booking"
17
+
18
+ module Recras
19
+
20
+ API_VERSION = 2
21
+
22
+ # returns the version number
23
+ def self.version
24
+ VERSION
25
+ end
26
+
27
+ # this method maps the recras API objects to
28
+ # the names used by this gem
29
+ def self.object_mappings
30
+ [["personeel", Person], ["arrangement", Combination], ["contactformulier", ContactForm], ["velden", ContactFormField], ["booking", Booking]]
31
+ end
32
+
33
+ def self.url
34
+ "https://demo.recras.nl"
35
+ end
36
+
37
+ # initialize a new Person from given JSON.
38
+ def new_from_json(json)
39
+ params = {}
40
+
41
+ # set each attribute based on the mapping
42
+ self.attribute_mapping.each do |o,n|
43
+ # if o is a string, parse it
44
+ if n.is_a?(String)
45
+ # check if data type is specified (using @@ symbol)
46
+ if n.include?("@@")
47
+ if n.split("@@").last.downcase == 'time'
48
+ data = Time.new(n.split("@@").first)
49
+ # puts data.inspect
50
+ # raise ERR
51
+ else
52
+ data = n.split("@@").first
53
+ end
54
+ params[n.split("@@").first] = data
55
+ else
56
+ params[n] = json[o.to_s]
57
+ end
58
+
59
+ # else, o is a class. Call the 'parse_children' method on it
60
+ else
61
+ # puts "n is a #{n.class.name}"
62
+ # loop through all the children (for example: 'regels' on 'arrangementen')
63
+ if json[o]
64
+ children = []
65
+ for item in json[o]
66
+ children << n.new_from_json(item)
67
+ end
68
+ params[n.plural_name] = children
69
+ end
70
+ end
71
+ end
72
+ self.new(params)
73
+ end
74
+
75
+ def self.parse_json(json: nil, endpoint: nil, client: nil)
76
+ if json.is_a?(Hash) && json["error"]
77
+ if json["message"]
78
+ raise RecrasError.new(self), json["message"]
79
+ else
80
+ raise RecrasError.new(self), json["error"]["message"]
81
+ end
82
+ else
83
+ Recras.object_mappings.each do |key,klass|
84
+ if endpoint.match(key)
85
+ # puts "Making new #{klass.name} with data: #{json}"
86
+ obj = klass.new_from_json(json)
87
+ if client
88
+ obj.client = client
89
+ end
90
+ return obj
91
+ end
92
+ end
93
+ raise RecrasError.new(self), "Unknwon object '#{endpoint}'"
94
+ end
95
+ end
96
+
97
+ # communicates with the server and returns either:
98
+ # - an object (Person, Booking)
99
+ # - an error
100
+ # - a json object
101
+ def self.make_request(endpoint, body: {}, http_method: :get, client: nil)
102
+ url = "#{Recras.url}/api#{Recras::API_VERSION}/#{endpoint}"
103
+
104
+ auth = client ? {username: client.username, password: client.password} : nil
105
+
106
+ if http_method && http_method.to_s == 'post'
107
+ response = HTTParty.post(url, basic_auth: auth, body: body)
108
+ else
109
+ response = HTTParty.get(url, basic_auth: auth, body: body)
110
+ end
111
+
112
+ json = response.parsed_response
113
+ return json
114
+ end
115
+
116
+ end
@@ -0,0 +1,9 @@
1
+ module Recras
2
+ # this module handles the communication with the recras API
3
+ # it has no instance methods, only class methods.
4
+ class Api
5
+ def self.make_request(endpoint)
6
+
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,39 @@
1
+ module Recras
2
+
3
+ # links to 'arrangement_regels' in the API
4
+ # http://recras.github.io/docs/endpoints/contactformulieren.html
5
+ class Booking
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
+ ["message", "message"],
32
+ ["boeking_id", "id"],
33
+ ["klant_id", "customer_id"],
34
+ ["payment_url", "payment_url"]
35
+ ]
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,71 @@
1
+ module Recras
2
+
3
+ class Client
4
+ # @note The is a required parameter.
5
+ attr_accessor :username
6
+ # @return [String] Your Wheretocard password
7
+ attr_accessor :password
8
+
9
+
10
+ #
11
+ # Initializer to transform a +Hash+ into an Client object
12
+ #
13
+ # @param [Hash] args
14
+ def initialize(args=nil)
15
+ required_args = [:username, :password]
16
+ for arg in required_args
17
+ if args.nil? || args[arg].nil?
18
+ raise RecrasError.new(self), "Insufficient login credentials. Please provide @username, @password"
19
+ end
20
+ end
21
+
22
+ return if args.nil?
23
+ args.each do |k,v|
24
+ instance_variable_set("@#{k}", v) unless v.nil?
25
+ end
26
+ end
27
+
28
+ # communicates with the server and returns either:
29
+ # - an object (Person, Booking)
30
+ # - an error
31
+ # - a json object
32
+ def make_request(endpoint, body: {}, http_method: :get)
33
+ Recras.make_request(endpoint, body: body, http_method: http_method, client: self)
34
+ end
35
+
36
+ # returns true if credentials are valid, false otherwise
37
+ def valid
38
+ begin
39
+ me
40
+ return true
41
+ rescue RecrasError
42
+ return false
43
+ end
44
+ end
45
+ alias_method :valid?, :valid
46
+
47
+ # returns a Me object
48
+ def me
49
+ json = make_request("personeel/me")
50
+ Recras.parse_json(json: json, endpoint: "personeel")
51
+ end
52
+
53
+ # find a specific combination
54
+ def combination(id)
55
+ json = make_request("arrangementen/#{id}")
56
+ return Recras.parse_json(json: json, endpoint: "arrangementen", client: self)
57
+ end
58
+
59
+
60
+ # returns an array of available combinations
61
+ def combinations
62
+ result = make_request("arrangementen")
63
+ a = []
64
+ for json in result
65
+ a << Recras.parse_json(json: json, endpoint: "arrangementen", client: self)
66
+ end
67
+ return a
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,184 @@
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 :visible_online
12
+ attr_accessor :number_of_people
13
+ attr_accessor :allowed_to_pay_later
14
+ attr_accessor :combination_items
15
+ attr_accessor :contact_form_id
16
+ attr_accessor :client
17
+
18
+ # Initializer to transform a +Hash+ into an Combination object
19
+ # @param [Hash] args
20
+ def initialize(args=nil)
21
+ required_args = []
22
+ for arg in required_args
23
+ if args.nil? || args[arg].nil?
24
+ raise RecrasError.new(self), "Insufficient login credentials. Please provide @username, @password"
25
+ end
26
+ end
27
+
28
+ return if args.nil?
29
+ args.each do |k,v|
30
+ instance_variable_set("@#{k}", v) unless v.nil?
31
+ end
32
+ end
33
+
34
+ # find a combination
35
+ def self.find(id)
36
+ json = Recras.make_request("arrangementen/#{id}")
37
+ # puts json
38
+ return Recras.parse_json(json: json, endpoint: "arrangement")
39
+ end
40
+
41
+ # returns a Recras::ContactForm
42
+ def contact_form
43
+ json = client.make_request("contactformulieren/#{contact_form_id}")
44
+ cf = Recras.parse_json(json: json, endpoint: "contactformulier", client: client)
45
+ end
46
+
47
+
48
+
49
+ # returns a list of available days (in string format) for a given campaign
50
+ # exampel: combination.available_days(combination_items: [{combination_item_id: 1, number_of_people: 2}])
51
+ # If no combination_items are given, assume that you want each item to be booked. In that scenario,
52
+ # also use the 'number_of_people' argument. E.g.: @combination.available_days(number_of_people: 2).
53
+ def available_days(items: [], number_of_people: nil, from_time: Date.today, until_time: (Time.now + 3600*24*7))
54
+ product_items = convert_items(items, number_of_people)
55
+
56
+ if product_items.any?
57
+ body_data = {
58
+ arrangement_id: id,
59
+ producten: product_items,
60
+ begin: from_time.strftime("%Y-%m-%d"),
61
+ eind: until_time.strftime("%Y-%m-%d")
62
+ }
63
+
64
+ # make request
65
+ json = client.make_request("onlineboeking/beschikbaredagen", body: body_data.to_json, http_method: :post)
66
+
67
+ if json.is_a?(Hash) && json["error"]
68
+ raise RecrasError.new(self), json["error"]["message"]
69
+ else
70
+ return json
71
+ end
72
+ else
73
+ raise RecrasError.new(self), "Insufficient details provided. Either combination_items or number_of_people are required."
74
+ end
75
+ end
76
+
77
+
78
+ # returns a list of available days (in string format) for a given campaign
79
+ # exampel: combination.available_days(combination_items: [{combination_item_id: 1, number_of_people: 2}])
80
+ # If no combination_items are given, assume that you want each item to be booked. In that scenario,
81
+ # also use the 'number_of_people' argument. E.g.: @combination.available_days(number_of_people: 2).
82
+ def available_times(items: [], number_of_people: nil, date: nil)
83
+ product_items = convert_items(items, number_of_people)
84
+
85
+ # convert date
86
+ date = convert_date(date)
87
+
88
+ if product_items.any?
89
+ body_data = { arrangement_id: id, producten: product_items, datum: date }
90
+ json = client.make_request("onlineboeking/beschikbaretijden", body: body_data.to_json, http_method: :post)
91
+
92
+ if json.is_a?(Hash) && json["error"]
93
+ raise RecrasError.new(self), json["error"]["message"]
94
+ else
95
+ return json
96
+ end
97
+ else
98
+ raise RecrasError.new(self), "Insufficient details provided. Either combination_items or number_of_people are required."
99
+ end
100
+ end
101
+
102
+
103
+ # make a reservation for this combination
104
+ def book(items: [], number_of_people: nil, date: nil, payment_method: "factuur", contact_form_details: {})
105
+
106
+ product_items = convert_items(items, number_of_people)
107
+ date = convert_date(date)
108
+
109
+ if product_items.any?
110
+ body_data = {
111
+ arrangement_id: id,
112
+ producten: product_items,
113
+ begin: date,
114
+ betaalmethode: payment_method,
115
+ contactformulier: contact_form_details
116
+ }
117
+ json = client.make_request("onlineboeking/reserveer", body: body_data.to_json, http_method: :post)
118
+
119
+ if json.is_a?(Hash) && json["error"]
120
+ raise RecrasError.new(self), json["error"]["message"]
121
+ else
122
+ booking = Recras.parse_json(json: json, endpoint: "booking")
123
+ return booking
124
+ end
125
+ else
126
+ raise RecrasError.new(self), "Insufficient details provided. Either combination_items or number_of_people are required."
127
+ end
128
+
129
+ end
130
+ alias_method :make_booking, :book
131
+
132
+ # returns an array of combination_items
133
+ # def combination_items
134
+ # result = make_request("arrangementen")
135
+ # a = []
136
+ # for json in result
137
+ # a << Recras.parse_json(json: json, endpoint: "arrangementen")
138
+ # end
139
+ # return a
140
+ # end
141
+
142
+ # translates the mapping between the Recras API
143
+ # and the terms used in this gem
144
+ def self.attribute_mapping
145
+ [["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], ["onlineboeking_contactformulier_id", "contact_form_id"]]
146
+ end
147
+
148
+ private
149
+
150
+ def convert_date(date)
151
+ if date.is_a?(Time)
152
+ return date.iso8601
153
+ elsif date.is_a?(String)
154
+ return Time.parse(date).iso8601
155
+ else
156
+ raise RecrasError.new(self), "Date is required and must be of type Time or String (ISO 8601)."
157
+ end
158
+ end
159
+
160
+ def convert_items(items, number_of_people)
161
+ if items.any?
162
+ # TODO
163
+ elsif number_of_people && number_of_people > 0
164
+ # assume that all the items will be chose the same amount
165
+ items = []
166
+ for combination_item in combination_items
167
+ items << {combination_item_id: combination_item.id, number_of_people: number_of_people}
168
+ end
169
+ end
170
+
171
+ if items && items.any?
172
+ mappings = {combination_item_id: "arrangementsregel_id", number_of_people: "aantal"}
173
+ product_items = []
174
+ for item in items
175
+ product_items << item.map {|k, v| [mappings[k], v] }.to_h
176
+ end
177
+ return product_items
178
+ end
179
+
180
+ return items
181
+ end
182
+
183
+ end
184
+ end
@@ -0,0 +1,38 @@
1
+ module Recras
2
+
3
+ # links to 'arrangement_regels' in the API
4
+ # http://recras.github.io/docs/endpoints/arrangementen.html
5
+ class CombinationItem
6
+ extend Recras
7
+ # @note The is a required parameter.
8
+
9
+ attr_accessor :id
10
+ attr_accessor :location_id
11
+ attr_accessor :begins_at
12
+ attr_accessor :ends_at
13
+ attr_accessor :description
14
+ attr_accessor :number_of_people
15
+ attr_accessor :product_id
16
+
17
+ # Initializer to transform a +Hash+ into an Client object
18
+ # @param [Hash] args
19
+ def initialize(args=nil)
20
+ required_args = []
21
+ return if args.nil?
22
+ args.each do |k,v|
23
+ instance_variable_set("@#{k}", v) unless v.nil?
24
+ end
25
+ end
26
+
27
+ def self.plural_name
28
+ "combination_items"
29
+ end
30
+
31
+ # translates the mapping between the Recras API
32
+ # and the terms used in this gem
33
+ def self.attribute_mapping
34
+ [["id", "id"],["locatie_id", "location_id"],["begin", "begins_at@@time"],["eind", "ends_at@@time"], ["beschrijving", "description"], ["aantal_personen", "number_of_people"], ["product_id", "product_id"]]
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,8 @@
1
+ #
2
+ # Configuration object for storing some parameters required for making transactions
3
+ #
4
+ module Recras::Config
5
+ class << self
6
+ # config code here... (if needed)
7
+ end
8
+ end
@@ -0,0 +1,56 @@
1
+ module Recras
2
+
3
+ # links to 'arrangement_regels' in the API
4
+ # http://recras.github.io/docs/endpoints/contactformulieren.html
5
+ class ContactForm
6
+ extend Recras
7
+ # @note The is a required parameter.
8
+
9
+ attr_accessor :id
10
+ attr_accessor :name
11
+ attr_accessor :client
12
+ # attr_accessor :contact_form_fields
13
+
14
+ # Initializer to transform a +Hash+ into an Client object
15
+ # @param [Hash] args
16
+ def initialize(args=nil)
17
+ required_args = []
18
+ return if args.nil?
19
+ args.each do |k,v|
20
+ instance_variable_set("@#{k}", v) unless v.nil?
21
+ end
22
+ end
23
+
24
+ def self.plural_name
25
+ "contact_forms"
26
+ end
27
+
28
+ # returns an array of Recras::ContactFormField elements
29
+ def contact_form_fields
30
+ json = client.make_request("contactformulieren/#{id}/velden")
31
+ a = []
32
+ for element in json
33
+ a << Recras.parse_json(json: element, endpoint: "velden", client: client)
34
+ end
35
+ return a
36
+ end
37
+
38
+ # returns the minimum required attributes to make a valid
39
+ # booking. Only use this for testing purpose.
40
+ def default_values
41
+ a = {}
42
+ for field in contact_form_fields
43
+ a[field.field_identifier] = field.default_value
44
+ end
45
+ return a
46
+ end
47
+
48
+
49
+ # translates the mapping between the Recras API
50
+ # and the terms used in this gem
51
+ def self.attribute_mapping
52
+ [["id", "id"],["name", "name"]]
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,64 @@
1
+ module Recras
2
+
3
+ # links to 'arrangement_regels' in the API
4
+ # http://recras.github.io/docs/endpoints/contactformulieren.html
5
+ class ContactFormField
6
+ extend Recras
7
+ # @note The is a required parameter.
8
+
9
+ attr_accessor :id
10
+ attr_accessor :name
11
+ attr_accessor :contact_form_id
12
+ attr_accessor :input_type
13
+ attr_accessor :required
14
+ attr_accessor :options
15
+ attr_accessor :special_for_booking
16
+ attr_accessor :field_identifier
17
+ attr_accessor :contact_form
18
+ attr_accessor :client
19
+
20
+ # Initializer to transform a +Hash+ into an Client object
21
+ # @param [Hash] args
22
+ def initialize(args=nil)
23
+ required_args = []
24
+ return if args.nil?
25
+ args.each do |k,v|
26
+ instance_variable_set("@#{k}", v) unless v.nil?
27
+ end
28
+ end
29
+
30
+ # translates the mapping between the Recras API
31
+ # and the terms used in this gem
32
+ def self.attribute_mapping
33
+ [
34
+ ["id", "id"],
35
+ ["naam", "name"],
36
+ ["contactformulier_id", "contact_form_id"],
37
+ ["soort_invoer", "input_type"],
38
+ ["verplicht", "required"],
39
+ ["mogelijke_keuzes", "options"],
40
+ ["bijzonderheden_boeking", "special_for_booking"],
41
+ ["field_identifier", "field_identifier"]
42
+ ]
43
+ end
44
+
45
+ # returns default values for this field_identifier
46
+ def default_value
47
+ if field_identifier == "contactpersoon.email1"
48
+ return "test@example.org"
49
+ elsif field_identifier == "contactpersoon.naam"
50
+ return "Naamloos"
51
+ elsif field_identifier == "contactpersoon.voornaam"
52
+ return "Voornaam"
53
+ elsif field_identifier == "contactpersoon.achternaam"
54
+ return "Achternaam"
55
+ elsif field_identifier == "veel_tekst"
56
+ return "tekst"
57
+ else
58
+ # raise ERRR
59
+ return ""
60
+ end
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,48 @@
1
+ module Recras
2
+
3
+ class Person
4
+ extend Recras
5
+ # @note The is a required parameter.
6
+ attr_accessor :first_name
7
+ attr_accessor :id
8
+ attr_accessor :name
9
+ attr_accessor :address
10
+ attr_accessor :postal_code
11
+ attr_accessor :city
12
+ attr_accessor :country_code
13
+ attr_accessor :region_code
14
+ attr_accessor :vat_number
15
+ attr_accessor :company_id
16
+ attr_accessor :bank_account_number
17
+ attr_accessor :first_name
18
+ attr_accessor :last_name
19
+ attr_accessor :phone
20
+ attr_accessor :email
21
+
22
+
23
+ #
24
+ # Initializer to transform a +Hash+ into an Client object
25
+ #
26
+ # @param [Hash] args
27
+ def initialize(args=nil)
28
+ required_args = []
29
+ for arg in required_args
30
+ if args.nil? || args[arg].nil?
31
+ raise RecrasError.new(self), "Insufficient login credentials. Please provide @username, @password"
32
+ end
33
+ end
34
+
35
+ return if args.nil?
36
+ args.each do |k,v|
37
+ instance_variable_set("@#{k}", v) unless v.nil?
38
+ end
39
+ end
40
+
41
+ # translates the mapping between the Recras API
42
+ # and the terms used in this gem
43
+ def self.attribute_mapping
44
+ [["id", "id"],["displaynaam", "name"],["adres", "address"],["postcode", "postal_code"], ["plaats", "city"], ["landcode", "country_code"],["bedrijf_id", "company_id"],["telefoon1","phone"],["email1", "email"]]
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,7 @@
1
+ class RecrasError < StandardError
2
+ attr_reader :object
3
+
4
+ def initialize(object)
5
+ @object = object
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Recras
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'recras/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "recras"
8
+ spec.version = Recras::VERSION
9
+ spec.authors = ["Henk Meijer"]
10
+ spec.email = ["henk.meijer@eskesmedia.nl"]
11
+
12
+ spec.summary = %q{Ruby binder to the Recras API}
13
+ spec.description = %q{Ruby binder to the Recras API}
14
+ spec.homepage = "http://www.eskesmedia.nl/"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.13"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "vcr"
37
+ spec.add_development_dependency "fakeweb"
38
+
39
+ spec.add_dependency 'httparty'
40
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: recras
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Henk Meijer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: fakeweb
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: httparty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Ruby binder to the Recras API
98
+ email:
99
+ - henk.meijer@eskesmedia.nl
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - lib/recras.rb
114
+ - lib/recras/api.rb
115
+ - lib/recras/booking.rb
116
+ - lib/recras/client.rb
117
+ - lib/recras/combination.rb
118
+ - lib/recras/combination_item.rb
119
+ - lib/recras/config.rb
120
+ - lib/recras/contact_form.rb
121
+ - lib/recras/contact_form_field.rb
122
+ - lib/recras/person.rb
123
+ - lib/recras/recras_error.rb
124
+ - lib/recras/version.rb
125
+ - recras.gemspec
126
+ homepage: http://www.eskesmedia.nl/
127
+ licenses:
128
+ - MIT
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.4.5.1
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Ruby binder to the Recras API
150
+ test_files: []