module PrioTicket
Constants
- VERSION
Public Class Methods
expected_date_format()
click to toggle source
Formats time in ISO-8601
@return [type] [description]
# File lib/prioticket.rb, line 55 def self.expected_date_format '%Y-%m-%dT%H:%M:%S%z' end
openstruct_to_hash(object, hash = {})
click to toggle source
Converts OpenStruct back to a hash
# 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)
click to toggle source
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
# 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)
click to toggle source
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
@return [type] [description]
# 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()
click to toggle source
For testing purpose only: set the username and password in environment variables to make the tests pass with your test credentials.
# 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