我正在使用Shippinglogic從各個運營商提取數據。保存對象屬性?
我想要做的是保存拉到我的表的數據。
所以我嘗試這樣做,像這樣:
ups = Shippinglogic::UPS.new
self.attributes = ups.track(:tracking_number => number)
self.save
下面介紹一下ups.track
調用返回:
>> ups.track(:tracking_number => '1ZX2988X0386964132')
=> #<Shippinglogic::UPS::Track::Details:0x1093ba7e0 @origin_country="US", @service_type="GROUND", @destination_state="AL", @origin_state="KY", @signature_name=nil, @destination_city="BIRMINGHAM", @events=[#<Shippinglogic::UPS::Track::Details::Event:0x109383010 @country="US", @name="DELIVERED", @postal_code="35242", @city="BIRMINGHAM", @type="D", @state="AL", @occurred_at=Tue Aug 16 13:44:00 -0500 2011>, #<Shippinglogic::UPS::Track::Details::Event:0x109382d90 @country="US", @name="OUT FOR DELIVERY", @postal_code=nil, @city="BIRMINGHAM", @type="I", @state="AL", @occurred_at=Tue Aug 16 07:46:00 -0500 2011>, #<Shippinglogic::UPS::Track::Details::Event:0x1093b1dc0 @country="US", @name="ARRIVAL SCAN", @postal_code=nil, @city="BIRMINGHAM", @type="I", @state="AL", @occurred_at=Tue Aug 16 07:00:00 -0500 2011>, #<Shippinglogic::UPS::Track::Details::Event:0x109382c50 @country="US", @name="DEPARTURE SCAN", @postal_code=nil, @city="NASHVILLE", @type="I", @state="TN", @occurred_at=Tue Aug 16 03:45:00 -0500 2011>, #<Shippinglogic::UPS::Track::Details::Event:0x109382098 @country="US", @name="ARRIVAL SCAN", @postal_code=nil, @city="NASHVILLE", @type="I", @state="TN", @occurred_at=Tue Aug 16 00:19:00 -0500 2011>, #<Shippinglogic::UPS::Track::Details::Event:0x10937d0c0 @country="US", @name="DEPARTURE SCAN", @postal_code=nil, @city="LEXINGTON", @type="I", @state="KY", @occurred_at=Mon Aug 15 21:36:00 -0500 2011>, #<Shippinglogic::UPS::Track::Details::Event:0x109375e38 @country="US", @name="ORIGIN SCAN", @postal_code=nil, @city="LEXINGTON", @type="I", @state="KY", @occurred_at=Mon Aug 15 16:08:00 -0500 2011>, #<Shippinglogic::UPS::Track::Details::Event:0x109370bb8 @country="US", @name="BILLING INFORMATION RECEIVED", @postal_code=nil, @city=nil, @type="M", @state=nil, @occurred_at=Mon Aug 15 12:18:56 -0500 2011>], @origin_city="CAMPBELLSVILLE", @delivery_at=Tue Aug 16 13:44:00 -0500 2011, @status="DELIVERED", @destination_country="US">
但由Shippinglogic返回不保存到attributes
對象。
我該如何做到這一點?
我最初嘗試過,但在上面的例子中,'tracking.attributes'返回的唯一值是'{:tracking_number =>「1ZX2988X0386964132」}' – Shpigford
我明白了。我還讀過你的其他評論,看來你想避免必須逐一訪問屬性。但是你至少要檢查他們是否有價值?我想這就是問題中的代碼點,對(軌道返回的對象有很多其他值)?但是,您具體需要哪些屬性? – mikong
這就是Shippinglogic中的內容,可以輕鬆定製:https://github.com/binarylogic/shippinglogic/blob/master/lib/shippinglogic/ups/track.rb – Shpigford