Module: Xero::Api::Util
- Included in:
- Xero::Api
- Defined in:
- lib/xero/api/util.rb
Instance Method Summary collapse
- #add_params(route:, params:) ⇒ Object
- #entity_handler(entity) ⇒ Object
- #json_date(date) ⇒ Object
- #parse_json_date(datestring) ⇒ Object
- #snake_to_camel(sym) ⇒ Object
- #standard_date(date) ⇒ Object
Instance Method Details
#add_params(route:, params:) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/xero/api/util.rb', line 4 def add_params(route:, params:) uri = URI.parse(route) params.each do |p| new_query_ar = URI.decode_www_form(uri.query || '') << p.to_a uri.query = URI.encode_www_form(new_query_ar) end uri.to_s end |
#entity_handler(entity) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/xero/api/util.rb', line 30 def entity_handler(entity) if entity.is_a?(Symbol) snake_to_camel(entity) else entity end end |
#json_date(date) ⇒ Object
19 20 21 22 23 |
# File 'lib/xero/api/util.rb', line 19 def json_date(date) date.strftime("/Date(%s%L)/") rescue => e raise Xero::Api::Error, date_method_error_msg(e) end |
#parse_json_date(datestring) ⇒ Object
25 26 27 28 |
# File 'lib/xero/api/util.rb', line 25 def parse_json_date(datestring) seconds_since_epoch = datestring.scan(/[0-9]+/)[0].to_i / 1000.0 Time.at(seconds_since_epoch) end |
#snake_to_camel(sym) ⇒ Object
38 39 40 |
# File 'lib/xero/api/util.rb', line 38 def snake_to_camel(sym) sym.to_s.split('_').collect(&:capitalize).join end |