prioticket 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8270ce77d4f2db94fbdd7ba0393af31199f9863
4
- data.tar.gz: 496fdc625a0d8006ed9734bed00e055d108e5028
3
+ metadata.gz: d659c0c31f33dc4aaaaffd3f544483e266bf1047
4
+ data.tar.gz: a5ef93472f859709ddd626cd38c80d81fbeb1824
5
5
  SHA512:
6
- metadata.gz: 55f87f2ad13a09ed5ad7f9e08636f7f7b5a7f26b4dcea6b078e4758eb16b17a0e74342a6be42670b2a2f2ea988a71d8ac6c7a004c490f5a5f35a15ec8ccd3a10
7
- data.tar.gz: 11d934e649cb210de50288c330f7a73355400579760f1f0b2626c2592b5bab68e31a254a04175904139e41c3ffce129a0187a726bbb8ddd6e913894564acbf52
6
+ metadata.gz: c8542437198a31aff0a74f0353f00079ccac003c79b05566c6c9b9670cbf7340528530539111e204ddaa25ac15ad2b4f2279b8b06c4ce5f99ecd03472602b5c3
7
+ data.tar.gz: cdff7e65a59fd24f124404d24f07ae85d64b0fbfac2d5c7a4e8b9f19d82a619b96c90f0af22e31e782ba63fa66568e57bc24e884e074cc359619ecc28c447add
data/README.md CHANGED
@@ -7,6 +7,8 @@ This gem works as a simple Ruby wrapper for the PrioTicket API. All the API func
7
7
 
8
8
  Instead of working with JSON, you work with Ruby Classes and intuitive methods.
9
9
 
10
+ **This gem communicates with the API Version 2.4.**
11
+
10
12
  ## Installation
11
13
 
12
14
  Add this line to your application's Gemfile:
@@ -111,6 +113,16 @@ To reserve a date, use the `PrioTicket::Reservation` class:
111
113
  @reservation.booking_status #=> "Cancelled"
112
114
  ```
113
115
 
116
+ A direct way to cancel a reservation, is to call the class method `.cancel`:
117
+ ```ruby
118
+ PrioTicket::Reservation.cancel(
119
+ distributor_id: 1234,
120
+ reservation_reference: "YYY2067115376XXX",
121
+ distributor_reference: "TEST_RESERVATION",
122
+ identifier: "my-unique-order-abc-123"
123
+ )
124
+ ```
125
+
114
126
  ### Booking
115
127
  To make a booking, please take note of the official API Documentation: for tickets of type_2 and type_3, a `from_date_time` and `to_date_time` must be present.
116
128
 
data/lib/prioticket.rb CHANGED
@@ -43,8 +43,8 @@ module PrioTicket
43
43
  if date.is_a?(String)
44
44
  date
45
45
  elsif [DateTime, Time].include?(date.class)
46
- date.strftime(expected_date_format)
47
- # date.strftime('%Y-%m-%d')
46
+ # date.strftime(expected_date_format)
47
+ date.strftime('%Y-%m-%d')
48
48
  end
49
49
  end
50
50
 
@@ -79,17 +79,24 @@ module PrioTicket
79
79
  is_integer = !!Integer(v) rescue false
80
80
  is_float = !!Float(v) rescue false
81
81
  is_date_time = !!DateTime.strptime(v, expected_date_format) rescue false
82
+ puts "#{k} (#{v})"
82
83
  if ["true", "false"].include?(v)
84
+ puts "is boolean"
83
85
  val = (v == 'true')
84
- elsif is_integer
85
- val = v.to_i
86
86
  elsif is_date_time
87
+ puts "is date_time"
87
88
  val = DateTime.strptime(v, expected_date_format)
89
+ elsif is_integer
90
+ puts "is integer"
91
+ val = v.to_i
88
92
  elsif is_float
93
+ puts "is integer"
89
94
  val = v.to_f
90
95
  elsif [Hash, Array].include?(v.class)
96
+ puts "is hash or array"
91
97
  val = JSON.parse(v.to_json, object_class: OpenStruct)
92
98
  else
99
+ puts "is undefined class"
93
100
  val = v
94
101
  end
95
102
  obj.instance_variable_set("@#{k}", val)
@@ -97,13 +104,3 @@ module PrioTicket
97
104
  end
98
105
 
99
106
  end
100
-
101
-
102
-
103
-
104
- # docs:
105
- # WNYE9On0Jqn/fivlUVgeyeYckLubVqxJ5mryhfBOfKk=
106
-
107
-
108
- # real:
109
- # OTU3IqrnoXVn5QvUsZIoTfKIyOEzOo9BFmWFQFtZbHk=
@@ -35,7 +35,7 @@ module PrioTicket
35
35
  step_2_string = step_1_string.encode('utf-8')
36
36
 
37
37
  # 3. Compute the SHA-256 hash for the byte array from step 2. The result will be a byte array.
38
- step_3_string = Digest::SHA256.digest(step_2_string).strip
38
+ step_3_string = Digest::SHA256.digest(step_2_string)
39
39
 
40
40
  # 4. Base64 encode the byte array as computed in step 3.
41
41
  # This string will be the x-request-authentication key for this request.
@@ -43,6 +43,7 @@ module PrioTicket
43
43
 
44
44
  return step_4_string
45
45
  end
46
+ Base64.encode64(Digest::SHA256.digest("4d07aa49a1ce9571cbd66d6383e65d46151272:PK1-MN2U-RS27-SWX").strip).strip
46
47
 
47
48
  #
48
49
  # Computes the request header
@@ -165,8 +165,11 @@ module PrioTicket
165
165
  if ticket
166
166
  if [2,3].include?(ticket.ticket_class)
167
167
  unless booking_type.from_date_time && booking_type.to_date_time
168
- err_msg = "The `booking_type` attribute requires a from_date_time and to_date_time for a ticket of ticket_class #{ticket.ticket_class}."
169
- raise PrioTicketError.new(err_msg)
168
+ unless booking_type.reservation_reference && booking_type.reservation_reference != ''
169
+ puts booking_type.inspect
170
+ err_msg = "The `booking_type` attribute requires a from_date_time and to_date_time for a ticket of ticket_class #{ticket.ticket_class}."
171
+ raise PrioTicketError.new(err_msg)
172
+ end
170
173
  end
171
174
  end
172
175
  end
@@ -34,6 +34,12 @@ module PrioTicket
34
34
  end
35
35
 
36
36
 
37
+ def cancelled
38
+ booking_status == "Cancelled" || cancellation_date_time
39
+ end
40
+ alias_method :cancelled?, :success
41
+
42
+
37
43
  #
38
44
  # Sends the reservation request tot the API
39
45
  #
@@ -50,6 +56,17 @@ module PrioTicket
50
56
  parse_result(result)
51
57
  end
52
58
 
59
+ def self.cancel(distributor_id: nil, reservation_reference: nil, distributor_reference: nil, identifier: nil)
60
+ reservation = PrioTicket::Reservation.new(
61
+ distributor_id: distributor_id,
62
+ reservation_reference: reservation_reference,
63
+ distributor_reference: distributor_reference,
64
+ identifier: identifier
65
+ )
66
+ reservation.cancel
67
+ return reservation
68
+ end
69
+
53
70
  private
54
71
 
55
72
  #
@@ -1,3 +1,3 @@
1
1
  module PrioTicket
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prioticket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henk Meijer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-27 00:00:00.000000000 Z
11
+ date: 2018-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: digest
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  version: '0'
144
144
  requirements: []
145
145
  rubyforge_project:
146
- rubygems_version: 2.4.5.1
146
+ rubygems_version: 2.6.14
147
147
  signing_key:
148
148
  specification_version: 4
149
149
  summary: Ruby implementation of the PrioTicket API