Module: PrioTicket
- Defined in:
- lib/prioticket.rb,
lib/prioticket/api.rb,
lib/prioticket/engine.rb,
lib/prioticket/ticket.rb,
lib/prioticket/booking.rb,
lib/prioticket/version.rb,
lib/prioticket/reservation.rb,
lib/prioticket/ticket_list.rb,
lib/prioticket/availabilities.rb,
lib/prioticket/ticket_details.rb
Defined Under Namespace
Modules: Config Classes: API, Availabilities, Booking, Engine, Reservation, Ticket, TicketDetails, TicketList
Constant Summary collapse
- VERSION =
"0.1.2"
Class Method Summary collapse
-
.expected_date_format ⇒ type
Formats time in ISO-8601.
-
.openstruct_to_hash(object, hash = {}) ⇒ Object
Converts OpenStruct back to a hash.
-
.parse_json_value(obj, k, v) ⇒ Object
Takes a hash and assignes it to the proper attributes.
-
.parsed_date(date) ⇒ type
Formats time in ISO-8601 Expected output: 2016-05-12T14:00:00+04:00 Not expected: 2016-05-12T10:00:00+08:00 / 2016-05-12T18:00:00+00:00.
-
.set_credentials_from_environment ⇒ Object
For testing purpose only: set the username and password in environment variables to make the tests pass with your test credentials.
Class Method Details
.expected_date_format ⇒ type
Formats time in ISO-8601
55 56 57 |
# File 'lib/prioticket.rb', line 55 def self.expected_date_format '%Y-%m-%dT%H:%M:%S%z' end |
.openstruct_to_hash(object, hash = {}) ⇒ Object
Converts OpenStruct back to a hash
60 61 62 63 64 65 |
# File 'lib/prioticket.rb', line 60 def self.openstruct_to_hash(object, hash = {}) object.each_pair do |key, value| hash[key] = value.is_a?(OpenStruct) ? openstruct_to_hash(value) : value end hash end |
.parse_json_value(obj, k, v) ⇒ Object
Takes a hash and assignes it to the proper attributes.
-
Integers will be parsed as floats
-
Floats will be parsed as floats
-
Boolean values will bu parsed as such
-
Hash and Array will bet a type of ‘OpenStruct’
-
DateTime will be a type of DateType
-
All other values will be used as string
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/prioticket.rb', line 76 def self.parse_json_value(obj, k,v) unless v.nil? # "2018-03-24T00:00:00+01:00" is_integer = !!Integer(v) rescue false is_float = !!Float(v) rescue false is_date_time = !!DateTime.strptime(v, expected_date_format) rescue false puts "#{k} (#{v})" if ["true", "false"].include?(v) puts "is boolean" val = (v == 'true') elsif is_date_time puts "is date_time" val = DateTime.strptime(v, expected_date_format) elsif is_integer puts "is integer" val = v.to_i elsif is_float puts "is integer" val = v.to_f elsif [Hash, Array].include?(v.class) puts "is hash or array" val = JSON.parse(v.to_json, object_class: OpenStruct) else puts "is undefined class" val = v end obj.instance_variable_set("@#{k}", val) end end |
.parsed_date(date) ⇒ type
Formats time in ISO-8601 Expected output: 2016-05-12T14:00:00+04:00 Not expected: 2016-05-12T10:00:00+08:00 / 2016-05-12T18:00:00+00:00
42 43 44 45 46 47 48 49 |
# File 'lib/prioticket.rb', line 42 def self.parsed_date(date) if date.is_a?(String) date elsif [DateTime, Time].include?(date.class) # date.strftime(expected_date_format) date.strftime('%Y-%m-%d') end end |
.set_credentials_from_environment ⇒ Object
For testing purpose only: set the username and password in environment variables to make the tests pass with your test credentials.
29 30 31 32 33 34 |
# File 'lib/prioticket.rb', line 29 def self.set_credentials_from_environment # puts "Setting API Key: #{ENV["PRIOTICKET_API_KEY"]}" Config.api_key = ENV["PRIOTICKET_API_KEY"] Config.environment = :test Config.verbose = false end |