Sha256: 09fa3f2d1366401912d58b438c232aa4270299d0899692bad3f7a4ef7899507f
Contents?: true
Size: 987 Bytes
Versions: 3
Compression:
Stored size: 987 Bytes
Contents
module ParcelApi # This module provides API requests to track the parcels and # return tracking information for a specific tracking reference. class Track PARCELTRACK_URL = '/ParcelTrack/2.0/parcels' # Creates a new ParcelApi::Track instance. def initialize(connection=nil) @connection ||= connection || ParcelApi::Client.connection end # Return details for a specific tracking reference. # @param tracking_reference [String] # @return Object of tracking details def details(tracking_reference) details_url = File.join(PARCELTRACK_URL, tracking_reference.to_s) response = @connection.get details_url events = response.body.tap do |d| d.delete('success') d['tracking_events'].map {|e| e['event_datetime'] = Time.parse(e['event_datetime'])} d['tracking_events'].sort_by! {|k| k['event_datetime'].to_i} end RecursiveOpenStruct.new(events, recurse_over_arrays: true) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
parcel_api-0.4.1 | lib/parcel_api/track.rb |
parcel_api-0.3.0 | lib/parcel_api/track.rb |
parcel_api-0.2.0 | lib/parcel_api/track.rb |