Class: AmazonSellerCentral::InventoryPage

Inherits:
Page
  • Object
show all
Defined in:
lib/amazon_seller_central/inventory_page.rb

Defined Under Namespace

Classes: UnsupportedModification

Instance Attribute Summary

Attributes inherited from Page

#body

Instance Method Summary collapse

Methods inherited from Page

#last_page?

Constructor Details

#initialize(options = {}) ⇒ InventoryPage

Returns a new instance of InventoryPage.



3
4
5
6
7
8
# File 'lib/amazon_seller_central/inventory_page.rb', line 3

def initialize(options={})
  @listings_applied = false
  @page_no  = options.delete(:page_no)
  @uri_base = options.delete(:uri_base)
  super
end

Instance Method Details

#apply_listings(new_listings) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/amazon_seller_central/inventory_page.rb', line 44

def apply_listings(new_listings)
  if @listings_applied
    raise UnsupportedModification.new("Can't apply listing data twice from the same page object. Refetch this page before attempting to update listings")
  end

  form = @page.form_with(:name => 'itemSummaryForm')
  new_listings.each do |l|
    if listings(true).find(l.sku).price.nil? && l.price != nil
      raise UnsupportedModification.new("Can't set price for #{l.asin} to $#{l.price}, the listing is not yet complete and this library doesn't yet support completing listings")
    end

    form["inv|#{l.sku}|#{l.asin}"]   = l.quantity
    form["price|#{l.sku}|#{l.asin}"] = l.price 
  end
  form['formOperation'] = 'saveChanges'
  r = form.submit
  @listings_applied = true
  true
end

#has_next?Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
# File 'lib/amazon_seller_central/inventory_page.rb', line 10

def has_next?
  @has_next ||= begin
                  v = @page.search(".//div[@id='ila-page-next']")
                  v.first && v.first.attributes["class"].value !~ /ila-page-nextDisabled/
                end
end

#listings(rescan = false) ⇒ Object Also known as: parse



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/amazon_seller_central/inventory_page.rb', line 31

def listings(rescan=false)
  @listings = nil if rescan
  @listings ||= begin
                  set = ListingSet.new
                  # being more specific here breaks on some pages
                  @page.parser.css('tr').select{|r| r['id'] =~ /^sku-/ && r.css('td').size == 15 }.each do |row|
                    set << listing_row_to_object(row)
                  end
                  set
                end
end

#next_pageObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/amazon_seller_central/inventory_page.rb', line 17

def next_page
  @next_page ||= begin
                   raise NoNextPageAvailableError unless has_next?

                   next_page = @agent.agent.get("#{@uri_base}#{(@uri_base =~ /\?/) ? '&': '?'}searchPageOffset=#{@page_no + 1}")
                   InventoryPage.new(
                     :page => next_page,
                     :page_no => (@page_no + 1),
                     :uri_base => @uri_base,
                     :agent => @agent
                   )
                 end
end