改进API调用和响应

TheChamp帮我解决了一系列哈希问题。 谢谢。 现在我想改进一下。 观点真的很混乱

  1. 将代码移动到模型,因此只调用实例变量将显示所需的结果。 就像航class类型的一个变量,出发时间,价格结构等。
  2. 根据某些条件,将结果排序在模型本身中。 与价格一样,默认为最低价。
  3. 获取API响应需要花费大量时间。 缓存响应的各种选项有哪些,因此结果是即时的。 此外,需要检查哪些值以确保缓存是新鲜的。

这是我的代码库。 (供您考虑,API响应的一部分 – http://jsfiddle.net/PP9N5/ )

模型

class Cleartrip include HTTParty debug_output $stdout base_uri "api.staging.cleartrip.com/air/1.0/search" headers 'X-CT-API-KEY' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx' format :xml def self.get_flight response = get("?from=DEL&to=BLR&depart-date=2014-08-10&adults=1&children=0&infants=0") if response.success? response else raise response.message end end 

调节器

 # This does nothing expires_in 20.minutes, public: true @flight = Cleartrip.get_flight 

查看

 
# This gets the flight info
- || -

# this gets the type of fare, Refundable/ Non-refundable # This gets the fare structure -
# The pricing summary

赞赏一般准则。

谢谢。