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 "nokogiri", "~> 1.5.0"
|
||||
gem "nokogiri", "~> 1.5.2"
|
||||
|
||||
gem 'sanitize', '~> 2.0.3'
|
||||
|
||||
gem 'newrelic_rpm'
|
||||
|
||||
gem 'neopets', :git => 'git://github.com/matchu/neopets.git'
|
||||
|
||||
group :development_async do
|
||||
# async wrappers
|
||||
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)
|
||||
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
|
||||
remote: git://github.com/oldmoe/mysqlplus.git
|
||||
revision: 3dbaa7c00ff0bb75ad9538cdef176c72de35d231
|
||||
|
@ -118,7 +125,7 @@ GEM
|
|||
msgpack (0.4.6)
|
||||
mysql2 (0.2.6)
|
||||
newrelic_rpm (3.3.3)
|
||||
nokogiri (1.5.0)
|
||||
nokogiri (1.5.2)
|
||||
open4 (1.3.0)
|
||||
openneo-auth-signatory (0.1.0)
|
||||
ruby-hmac
|
||||
|
@ -221,8 +228,9 @@ DEPENDENCIES
|
|||
msgpack (~> 0.4.3)
|
||||
mysql2 (< 0.3)
|
||||
mysqlplus!
|
||||
neopets!
|
||||
newrelic_rpm
|
||||
nokogiri (~> 1.5.0)
|
||||
nokogiri (~> 1.5.2)
|
||||
openneo-auth-signatory (~> 0.1.0)
|
||||
rack-fiber_pool
|
||||
rails (= 3.0.5)
|
||||
|
|
|
@ -12,17 +12,15 @@ class NeopetsUser
|
|||
end
|
||||
|
||||
def load!
|
||||
doc = Nokogiri::HTML(open(url))
|
||||
user = Neopets::User.new(@username)
|
||||
|
||||
unless pets_wrapper = doc.at('#userneopets')
|
||||
raise NotFound, "Could not find user #{username}"
|
||||
end
|
||||
|
||||
pets = pets_wrapper.css('a[href^="/petlookup.phtml"]').map do |link|
|
||||
name = link['href'].split('=').last
|
||||
Pet.find_or_initialize_by_name(name)
|
||||
begin
|
||||
pets = user.pets
|
||||
rescue Neopets::User::Error => e
|
||||
raise NotFound, e.message
|
||||
end
|
||||
|
||||
pets = pets.map { |pet| Pet.find_or_initialize_by_name(pet.name) }
|
||||
items = pets.each(&:load!).map(&:items).flatten
|
||||
item_ids = items.map(&:id)
|
||||
|
||||
|
@ -46,13 +44,6 @@ class NeopetsUser
|
|||
false
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
URL_PREFIX = 'http://www.neopets.com/userlookup.phtml?user='
|
||||
def url
|
||||
URL_PREFIX + @username
|
||||
end
|
||||
|
||||
class NotFound < RuntimeError;end
|
||||
class NotFound < RuntimeError; 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