Class: AmazonSellerCentral::OrdersPage
- Inherits:
-
Page
- Object
- Page
- AmazonSellerCentral::OrdersPage
show all
- Defined in:
- lib/amazon_seller_central/orders_page.rb
Constant Summary
collapse
- DATE_CELL_INDEX =
1
- ORDER_CELL_INDEX =
2
- STATUS_CELL_INDEX =
8
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Page
#has_next?, #last_page?, #next_page
Constructor Details
Returns a new instance of OrdersPage.
10
11
12
|
# File 'lib/amazon_seller_central/orders_page.rb', line 10
def initialize
@page_no = 0
end
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
8
9
10
|
# File 'lib/amazon_seller_central/orders_page.rb', line 8
def body
@body
end
|
Class Method Details
.has_next?(page) ⇒ Boolean
14
15
16
|
# File 'lib/amazon_seller_central/orders_page.rb', line 14
def self.has_next?(page)
has_next ||= page.search(".//div[@id='nextPage']").any?
end
|
.next_page(page, mech, uri_base) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/amazon_seller_central/orders_page.rb', line 18
def self.next_page(page, mech, uri_base)
next_page ||= begin
raise NoNextPageAvailableError unless has_next?
next_page = mech.agent.get("#{uri_base}&searchPageOffset=#{@page_no + 1}")
end
end
|
.order_row_to_object(row) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/amazon_seller_central/orders_page.rb', line 47
def self.order_row_to_object(row)
o = Order.new
row.css('td').each_with_index do |td, i|
txt = td.text.strip
case i
when DATE_CELL_INDEX
o.date = Time.parse(txt)
when ORDER_CELL_INDEX
o.order_id = txt.match(/^(\d{3}-\d+-\d+)\s/)[1]
when STATUS_CELL_INDEX
o.status = txt
end
end
o
end
|
.pending_orders ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/amazon_seller_central/orders_page.rb', line 26
def self.pending_orders
uri_base = 'https://sellercentral.amazon.com/gp/orders-v2/list/ref=ag_myo_dos4_home?ie=UTF8&showCancelled=0&searchType=OrderStatus&ignoreSearchType=1&statusFilter=Pending&searchFulfillers=mfn&preSelectedRange=30&searchDateOption=preSelected&sortBy=OrderStatusDescending&itemsPerPage=100'
mech = AmazonSellerCentral.mechanizer
mech.login_to_seller_central
page = mech.agent.get(uri_base)
pending_orders = []
begin
(page.parser.css('tr.list-row-odd') + page.parser.css('tr.list-row-even')).each do |row|
pending_orders << order_row_to_object(row)
end
if has_next?(page)
page = next_page(page, mech, uri_base)
had_next = true
else
had_next = false
end
end while had_next
pending_orders
end
|