goodwill 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTI1OWMzZGM5OGJhNGU3NDE4M2EzZmJlN2JmM2M1ODZlNjg1Y2M5Yg==
4
+ ZTdiMmFhNjFlNjYzZWQzOTI1ZmY4YTM0Zjc2ZmQyNTUyZGFiYTUyMQ==
5
5
  data.tar.gz: !binary |-
6
- MzIzZWFjZWRiZjM1MzVlZThiNzBkNWVmNTAwYzM4NDUwZDU3OWZjMg==
6
+ YWZlOTA3NDljN2ZmM2I3Y2Q2NzJiZWRhNzBjYjUyZmVlZGQ1MGJhNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDgxNWM3MTNhOTcwNDlmNDRiZDY0NjZiYTAxMzA0NjZkNTU1YjUxNDkxMjU1
10
- Yzg1ZmZkYzU1Y2E1ZDExNDY3ZjA0OGU5ZjMzYzFjMWYyOWUyZWZhZGRjYzBk
11
- MmQyOWFhNjIyMzBhMTZhZDhkNzRlYTE4YjcyNjQ3MTdmNDRhNmI=
9
+ ZGMwNzc0Y2U4NWUxNGZhMjcxZDkyNjc2OTdlNWRhZjdiNDVmNTU2YjIxMDg5
10
+ OGJiYzA4M2UxODNkODQ0YzFmN2RhMTVmZWMwOTg2MmMwY2Q3MDIxYjA0ZWRk
11
+ MzE5YzVlYWZiZDZhOTQ4MmZiNjE2YjdjYTViMjE4NTJjMDVjN2U=
12
12
  data.tar.gz: !binary |-
13
- ZmRkMDczZjYwMjYyMmU2NTUyNTYxNDgwYWVmMDE2MWUwYzcyMDM3MzYwYTFh
14
- Y2NjZThlNzQ2ZTFhNTVjYmRmMTVkNmQ4MWI0ZmZlMTRiYmNmOTRjMTQyMzVl
15
- YmFmYTQ3OWVjNzY5ODcyMDYxY2FjYWQ4OTUyNmMxNTFkYjhiZGQ=
13
+ MGUxNmVmMTFmY2M5NjhjOGM1NTI5MWZkNmIxZjI2YWY1YzdhMTFkMGEwMmFk
14
+ MWU2ZmFkOTkyMDMwNTUzZTNhMWNjMGVjZTU2YTA0MjAwNGVlMWZmODQzOTY3
15
+ YzBmNmY2ZGUzNDViMWQxNjMxNGNlNzA4YTVkNDQ0Njk3ODZiNWQ=
@@ -0,0 +1,11 @@
1
+ Documentation:
2
+ Enabled: false
3
+
4
+ Metrics/AbcSize:
5
+ Enabled: false
6
+
7
+ Metrics/LineLength:
8
+ Max: 200
9
+
10
+ Metrics/MethodLength:
11
+ Max: 20
@@ -2,6 +2,9 @@ language: ruby
2
2
  rvm:
3
3
  - 2.2.0
4
4
  before_install: gem install bundler -v 1.10.3
5
+ script:
6
+ - bundle exec rspec
7
+ - bundle exec rubocop
5
8
  deploy:
6
9
  provider: rubygems
7
10
  api_key:
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Inline docs](http://inch-ci.org/github/dudemcbacon/goodwill.svg?branch=master)](http://inch-ci.org/github/dudemcbacon/goodwill)
5
5
  # Goodwill
6
6
 
7
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/goodwill`. To experiment with that code, run `bin/console` for an interactive prompt.
7
+ Goodwill is a simple web scraper for ShopGoodwill.com. You can query login to your account, view your currently in progress auction, search for items, and even bid on new options. It also includes a small CLI for interacting with ShopGoodwill.com from the command-line.
8
8
 
9
9
  TODO: Delete this and the text above, and describe your gem
10
10
 
@@ -26,7 +26,22 @@ Or install it yourself as:
26
26
 
27
27
  ## Usage
28
28
 
29
- TODO: Write usage instructions here
29
+ ```ruby
30
+ gem 'goodwill'
31
+
32
+ account = Goodwill::Account.new('username', 'password')
33
+
34
+ pp account.search('famicom')
35
+ [#<Goodwill::Auction:0x007fbf50ec0c18
36
+ @bidding=false,
37
+ @bids="8",
38
+ @current="$66.00",
39
+ @end="",
40
+ @href="http://www.shopgoodwill.com/viewItem.asp?itemID=25576979",
41
+ @item="Two Nintendo Super Famicom Game Consoles 020",
42
+ @itemid="25576979",
43
+ @seller="Columbia Goodwill">]
44
+ ```
30
45
 
31
46
  ## Development
32
47
 
@@ -36,5 +51,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
36
51
 
37
52
  ## Contributing
38
53
 
39
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/goodwill.
40
-
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dudemcbacon/goodwill.
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new
5
7
 
6
- task :default => :spec
8
+ task default: :spec
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "goodwill"
3
+ require 'bundler/setup'
4
+ require 'goodwill'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "goodwill"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ['lib']
29
29
 
30
+ spec.add_development_dependency 'simplecov'
30
31
  spec.add_development_dependency 'rake', '~> 10.0'
31
32
  spec.add_development_dependency 'rspec', '~> 3.3'
32
33
  spec.add_development_dependency 'rubocop', '~> 0.34'
@@ -6,6 +6,9 @@ require 'mechanize'
6
6
  require 'parallel'
7
7
 
8
8
  module Goodwill
9
+ #
10
+ # Allows for basic account interaction
11
+ #
9
12
  class Account
10
13
  include Goodwill::Mechanize
11
14
  include URLPaths
@@ -30,8 +33,8 @@ module Goodwill
30
33
  end
31
34
  end
32
35
 
33
- def search(itemTitle)
34
- search_page = mechanize.get(SEARCH_URL + itemTitle)
36
+ def search(item_title)
37
+ search_page = mechanize.get(SEARCH_URL + item_title)
35
38
  pages(total_items(search_page)).times.map do |i|
36
39
  search_page = search_page.link_with(text: 'Next').click unless i == 0
37
40
  Parallel.map(search_page.search('table.productresults tbody > tr'), in_threads: @threads) do |row|
@@ -5,6 +5,9 @@ require 'goodwill/urlpaths'
5
5
  require 'goodwill/mechanize'
6
6
 
7
7
  module Goodwill
8
+ #
9
+ # A ShopGoodwill Auction
10
+ #
8
11
  class Auction
9
12
  include Goodwill::Mechanize
10
13
  include CSSPaths
@@ -27,22 +30,28 @@ module Goodwill
27
30
 
28
31
  @href = ITEM_SEARCH_URL + itemid.to_s
29
32
  item_page = mechanize.get(@href)
30
- @bids = item_page.search(BIDS_PATH).text[/\d+/]
31
- @current = item_page.search(CURRENT_PRICE_PATH).text
32
- @end = item_page.search(END_TIME_PATH).text
33
+ @bids = item_page.search(BIDS_PATH).text[/\d+/].to_i
34
+ @current = item_page.search(CURRENT_PRICE_PATH).text.tr('$', '').to_f
35
+ @end = DateTime.strptime(item_page.search(END_TIME_PATH).text, '%m/%d/%Y %l:%M:%S %p %Z')
33
36
  @item = item_page.search(ITEM_TITLE_PATH).text
34
37
  @seller = item_page.search(SELLER_PATH).text
35
38
  @bidding = false
36
39
  @shipping = calculate_shipping(@itemid, @zipcode, @state, @country)
37
40
  end
38
41
 
39
- def ==(another_auction)
40
- self.itemid == another_auction.itemid
42
+ def ==(other)
43
+ itemid == other.itemid
41
44
  end
42
45
 
43
46
  def to_hash
44
47
  hash = {}
45
- instance_variables.each {|var| hash[var.to_s.delete("@")] = instance_variable_get(var) }
48
+ instance_variables.each do |var|
49
+ if var == :@end
50
+ hash[var.to_s.delete('@')] = instance_variable_get(var).to_s
51
+ else
52
+ hash[var.to_s.delete('@')] = instance_variable_get(var)
53
+ end
54
+ end
46
55
  hash
47
56
  end
48
57
 
@@ -51,7 +60,7 @@ module Goodwill
51
60
  def calculate_shipping(itemid, zipcode, state, country)
52
61
  params = "?itemid=#{itemid}&zip=#{zipcode}&state=#{state}&country=#{country}"
53
62
  page = mechanize.get(SHIPPING_URL + params)
54
- page.search(SHIPPING_PATH).text
63
+ page.search(SHIPPING_PATH).text.tr('$', '').to_f
55
64
  end
56
65
  end
57
66
  end
@@ -1,3 +1,3 @@
1
1
  module Goodwill
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goodwill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Burnett
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-09 00:00:00.000000000 Z
11
+ date: 2015-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: simplecov
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rake
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -175,6 +189,7 @@ files:
175
189
  - .env
176
190
  - .gitignore
177
191
  - .rspec
192
+ - .rubocop.yml
178
193
  - .travis.yml
179
194
  - Gemfile
180
195
  - Gemfile.old