use Neopets::User for username-based closet imports
This commit is contained in:
parent
63f503e7a4
commit
4e7e98beca
5 changed files with 22 additions and 21 deletions
4
Gemfile
4
Gemfile
|
@ -33,12 +33,14 @@ gem 'right_aws', '~> 2.1.0'
|
||||||
|
|
||||||
gem "character-encodings", "~> 0.4.1", :platforms => :ruby_18
|
gem "character-encodings", "~> 0.4.1", :platforms => :ruby_18
|
||||||
|
|
||||||
gem "nokogiri", "~> 1.5.0"
|
gem "nokogiri", "~> 1.5.2"
|
||||||
|
|
||||||
gem 'sanitize', '~> 2.0.3'
|
gem 'sanitize', '~> 2.0.3'
|
||||||
|
|
||||||
gem 'newrelic_rpm'
|
gem 'newrelic_rpm'
|
||||||
|
|
||||||
|
gem 'neopets', :git => 'git://github.com/matchu/neopets.git'
|
||||||
|
|
||||||
group :development_async do
|
group :development_async do
|
||||||
# async wrappers
|
# async wrappers
|
||||||
gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git'
|
gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git'
|
||||||
|
|
12
Gemfile.lock
12
Gemfile.lock
|
@ -29,6 +29,13 @@ GIT
|
||||||
em-synchrony (1.0.0)
|
em-synchrony (1.0.0)
|
||||||
eventmachine (>= 1.0.0.beta.1)
|
eventmachine (>= 1.0.0.beta.1)
|
||||||
|
|
||||||
|
GIT
|
||||||
|
remote: git://github.com/matchu/neopets.git
|
||||||
|
revision: c00b44ab75064815c5d433f0053bbf612c8465fd
|
||||||
|
specs:
|
||||||
|
neopets (0.0.1)
|
||||||
|
nokogiri (~> 1.5.2)
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/oldmoe/mysqlplus.git
|
remote: git://github.com/oldmoe/mysqlplus.git
|
||||||
revision: 3dbaa7c00ff0bb75ad9538cdef176c72de35d231
|
revision: 3dbaa7c00ff0bb75ad9538cdef176c72de35d231
|
||||||
|
@ -118,7 +125,7 @@ GEM
|
||||||
msgpack (0.4.6)
|
msgpack (0.4.6)
|
||||||
mysql2 (0.2.6)
|
mysql2 (0.2.6)
|
||||||
newrelic_rpm (3.3.3)
|
newrelic_rpm (3.3.3)
|
||||||
nokogiri (1.5.0)
|
nokogiri (1.5.2)
|
||||||
open4 (1.3.0)
|
open4 (1.3.0)
|
||||||
openneo-auth-signatory (0.1.0)
|
openneo-auth-signatory (0.1.0)
|
||||||
ruby-hmac
|
ruby-hmac
|
||||||
|
@ -221,8 +228,9 @@ DEPENDENCIES
|
||||||
msgpack (~> 0.4.3)
|
msgpack (~> 0.4.3)
|
||||||
mysql2 (< 0.3)
|
mysql2 (< 0.3)
|
||||||
mysqlplus!
|
mysqlplus!
|
||||||
|
neopets!
|
||||||
newrelic_rpm
|
newrelic_rpm
|
||||||
nokogiri (~> 1.5.0)
|
nokogiri (~> 1.5.2)
|
||||||
openneo-auth-signatory (~> 0.1.0)
|
openneo-auth-signatory (~> 0.1.0)
|
||||||
rack-fiber_pool
|
rack-fiber_pool
|
||||||
rails (= 3.0.5)
|
rails (= 3.0.5)
|
||||||
|
|
|
@ -12,17 +12,15 @@ class NeopetsUser
|
||||||
end
|
end
|
||||||
|
|
||||||
def load!
|
def load!
|
||||||
doc = Nokogiri::HTML(open(url))
|
user = Neopets::User.new(@username)
|
||||||
|
|
||||||
unless pets_wrapper = doc.at('#userneopets')
|
begin
|
||||||
raise NotFound, "Could not find user #{username}"
|
pets = user.pets
|
||||||
end
|
rescue Neopets::User::Error => e
|
||||||
|
raise NotFound, e.message
|
||||||
pets = pets_wrapper.css('a[href^="/petlookup.phtml"]').map do |link|
|
|
||||||
name = link['href'].split('=').last
|
|
||||||
Pet.find_or_initialize_by_name(name)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
pets = pets.map { |pet| Pet.find_or_initialize_by_name(pet.name) }
|
||||||
items = pets.each(&:load!).map(&:items).flatten
|
items = pets.each(&:load!).map(&:items).flatten
|
||||||
item_ids = items.map(&:id)
|
item_ids = items.map(&:id)
|
||||||
|
|
||||||
|
@ -46,13 +44,6 @@ class NeopetsUser
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
class NotFound < RuntimeError; end
|
||||||
|
|
||||||
URL_PREFIX = 'http://www.neopets.com/userlookup.phtml?user='
|
|
||||||
def url
|
|
||||||
URL_PREFIX + @username
|
|
||||||
end
|
|
||||||
|
|
||||||
class NotFound < RuntimeError;end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
BIN
vendor/cache/nokogiri-1.5.0.gem
vendored
BIN
vendor/cache/nokogiri-1.5.0.gem
vendored
Binary file not shown.
BIN
vendor/cache/nokogiri-1.5.2.gem
vendored
Normal file
BIN
vendor/cache/nokogiri-1.5.2.gem
vendored
Normal file
Binary file not shown.
Loading…
Reference in a new issue