Class: RussianPost::Tracking

Inherits:
Object
  • Object
show all
Defined in:
lib/russian_post/tracking.rb

Constant Summary collapse

TRACKING_PAGE =
'http://www.russianpost.ru/rp/servise/ru/home/postuslug/trackingpo'
COLUMNS =
[:type, :date, :zip_code, :location, :message, :weight, :declared_cost,
:delivery_cash, :destination_zip_code, :destination_location]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tracking_code, options = {}) ⇒ Tracking

Returns a new instance of Tracking.



15
16
17
18
19
# File 'lib/russian_post/tracking.rb', line 15

def initialize(tracking_code, options = {})
  @barcode = tracking_code.strip.upcase
  @agent   = Mechanize.new
  @options = options || {}
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



9
10
11
# File 'lib/russian_post/tracking.rb', line 9

def agent
  @agent
end

#barcodeObject (readonly)

Returns the value of attribute barcode.



9
10
11
# File 'lib/russian_post/tracking.rb', line 9

def barcode
  @barcode
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/russian_post/tracking.rb', line 9

def options
  @options
end

Instance Method Details

#trackObject



21
22
23
24
25
26
27
28
# File 'lib/russian_post/tracking.rb', line 21

def track
  initial_page = fetch_initial_page
  tracking_page = fetch_tracking_data(initial_page)

  check_validity!(tracking_page)

  parse_tracking_table(tracking_table(tracking_page))
end