다양한 통신 업체의 데이터를 가져 오는 데 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">
그러나 attributes
에 저장하지 않습니다 Shippinglogic에 의해 반환되는 객체 .
어떻게하면됩니까?
처음에 시도했지만, 위의 예제에서'tracking.attributes'에 의해 반환되는 것은'{: tracking_number => "1ZX2988X0386964132"}' – Shpigford
입니다. 나는 또한 당신의 다른 코멘트를 읽었으며, 당신은 하나씩 속성에 접근하지 않아도되고 싶다고 생각합니다. 적어도 가치가 있는지 확인해 주시겠습니까? 그 질문에 당신의 코드의 요점, 오른쪽 (트랙에 의해 반환 된 개체가 다른 값을 많이 가지고) 같아요? 그러나 당신이 특별히 필요로하는 속성은 무엇입니까? – mikong
그게 이미 Shippinglogic에 있고, 쉽게 사용자 정의 할 수 있습니다 : https://github.com/binarylogic/shippinglogic/blob/master/lib/shippinglogic/ups/track.rb – Shpigford