Class: Goodwill::Account

Inherits:
Object
  • Object
show all
Includes:
Mechanize, URLPaths
Defined in:
lib/goodwill/account.rb

Constant Summary collapse

IN_PROG =
'https://www.shopgoodwill.com/buyers/myShop/AuctionsInProgress.asp'
PER_PAGE =
25

Constants included from URLPaths

URLPaths::ITEM_SEARCH_URL, URLPaths::LOGIN_URL, URLPaths::OPEN_ORDERS_URL, URLPaths::SEARCH_URL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mechanize

logged_in?, login, #mechanize, mechanize

Constructor Details

#initialize(username, password = '', threads = 10) ⇒ Account

Returns a new instance of Account.

[View source]

18
19
20
21
22
23
24
# File 'lib/goodwill/account.rb', line 18

def initialize(username, password = '', threads = 10)
  @username  = username
  @password  = password
  @threads   = threads
  Goodwill::Mechanize.username = @username
  Goodwill::Mechanize.password = @password
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.


16
17
18
# File 'lib/goodwill/account.rb', line 16

def password
  @password
end

#threadsObject (readonly)

Returns the value of attribute threads.


16
17
18
# File 'lib/goodwill/account.rb', line 16

def threads
  @threads
end

#usernameObject (readonly)

Returns the value of attribute username.


16
17
18
# File 'lib/goodwill/account.rb', line 16

def username
  @username
end

Instance Method Details

#bid(itemid, bid) ⇒ Object

[View source]

43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/goodwill/account.rb', line 43

def bid(itemid, bid)
  mechanize.get(ITEM_SEARCH_URL + itemid.to_s) do |page|
    form = page.form_with(action: 'https://www.shopgoodwill.com/reviewBidrcs.asp')
    form.maxbid = bid.to_f
    confirmation_page = form.submit
    confirmation_form = confirmation_page.form_with(action: 'https://www.shopgoodwill.com/reviewBidrcs.asp?state=2&puconf=Y')
    confirmation_form.buyerLogin = @username
    confirmation_form.buyerPasswd = @password
    butt = confirmation_form.submit
    butt.search('tr')[1].text.split.last.tr('$', '') == bid ? true : false
  end
end

#in_progressObject

[View source]

26
27
28
29
30
31
# File 'lib/goodwill/account.rb', line 26

def in_progress
  in_progress_page = mechanize.get(IN_PROG)
  Parallel.map(in_progress_page.search('table.mySG tbody tr'), in_threads: @threads) do |row|
    Goodwill::BiddingAuction.new(itemid_from_open_order_row(row), mechanize)
  end
end

#search(itemTitle) ⇒ Object

[View source]

33
34
35
36
37
38
39
40
41
# File 'lib/goodwill/account.rb', line 33

def search(itemTitle)
  search_page = mechanize.get(SEARCH_URL + itemTitle)
  pages(total_items(search_page)).times.map do |i|
    search_page = search_page.link_with(text: 'Next').click unless i == 0
    Parallel.map(search_page.search('table.productresults tbody > tr'), in_threads: @threads) do |row|
      Goodwill::Auction.new(itemid_from_search_row(row))
    end
  end.flatten
end