Ruby Class Example 

  • The class of api
    //www.trackingmore.com/api-class_ruby.html

        Installation:
            1. Download this Class to desired location
            2. Fill in Trackingmore-Api-Key in this Class in line "protected $apiKey = 'YOUR API KEY';"
            3. Require this class in your project.


    List all trackings
    url="http://api.trackingmore.com/v2/trackings/get?page=1&limit=25&created_at_min=1441314361&created_at_max=1477547238"
    postData = ""
    tracker  = Trackingmore.new()
    res      =tracker.tracker(url,postData,"GET")
    puts "Response #{res.code} #{res.message}: #{res.body}"
    
    Create a tracking item
    postData = {
        "tracking_number" => "EA152563251CN",
        "carrier_code" => "china-ems"
    }
    tracker = Trackingmore.new()
    res     = tracker.tracker(url,postData,"POST")
    puts "Response #{res.code} #{res.message}: #{res.body}"
    
    Create multiple trackings.
    url="http://api.trackingmore.com/v2/trackings/batch"
    postData = [
    {"tracking_number" => "RX478151565DE", "carrier_code" => "yanwen"},
    {"tracking_number" => "RX478151548DE", "carrier_code" => "yanwen"}
    ]
    tracker = Trackingmore.new()
    res     = tracker.tracker(url,postData,"POST")
    puts "Response #{res.code} #{res.message}: #{res.body}"
    
    Get tracking results of a single tracking.
    url="http://api.trackingmore.com/v2/trackings/yanwen/RX478151565DE"
    postData =""
    tracker  = Trackingmore.new()
    res      = tracker.tracker(url,postData,"GET")
    puts "Response #{res.code} #{res.message}: #{res.body}"
    
    Update Tracking item
    url="http://api.trackingmore.com/v2/trackings/yanwen/RX478151548DE"
    postData = {
        "title" => "new title",
        "customer_name" => "sandy",
        "customer_email" => "[email protected]",
        "order_id" => "#986574521568"
    }
    tracker = Trackingmore.new()
    res     = tracker.tracker(url,postData,"PUT")
    puts "Response #{res.code} #{res.message}: #{res.body}"
    
    Delete a tracking item
    url="http://api.trackingmore.com/v2/trackings/yanwen/RX478151548DE"
    postData =""
    tracker  = Trackingmore.new()
    res      = tracker.tracker(url,postData,"DELETE")
    puts "Response #{res.code} #{res.message}: #{res.body}"
    
    Get realtime tracking results of a single tracking
    url="http://api.trackingmore.com/v2/trackings/realtime"
    postData = {
        "tracking_number" => "WT7724609050001",
        "carrier_code" => "sfcservice"
    }
    tracker = Trackingmore.new()
    res = tracker.tracker(url,postData,"POST")
    puts "Response #{res.code} #{res.message}: #{res.body}"