Module: Cekresi
- Defined in:
- lib/cekresi.rb,
lib/cekresi/version.rb,
lib/cekresi/user_agent.rb,
lib/cekresi/cekresi_parser.rb
Defined Under Namespace
Classes: Parser
Constant Summary collapse
- VERSION =
"0.1.0"- USER_AGENTS =
[ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:34.0) Gecko/20100101 Firefox/34.0", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/7.1.2 Safari/537.85.11" ]
Class Method Summary collapse
Class Method Details
.fetch(tracking_number) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cekresi.rb', line 16 def self.fetch(tracking_number) url = "http://cekresi.com/?noresi=#{tracking_number}" session = ::Session.new(:poltergeist) session.driver.headers = {'User-Agent' => USER_AGENTS.sample} session.visit(url) session.find("#cekresi").click begin container_result = session.find(:xpath, "//div[@id='results']") if container_result if container_result.find(".top_title") result = Cekresi::Parser.parse(container_result) else result = {status: :not_found, message: container_result.text} end else result = {status: :not_found, message: 'Sorry your search not found'} end rescue ::ElementNotFound result = {status: :not_found, message: 'There is problem from cekresi.com, please try again'} end .reset_sessions! session.driver.quit return result end |