fix pixiv tests
This commit is contained in:
4
app/logical/sources/error.rb
Normal file
4
app/logical/sources/error.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
module Sources
|
||||
class Error < Exception
|
||||
end
|
||||
end
|
||||
@@ -1,8 +1,6 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
module Sources
|
||||
class Error < Exception ; end
|
||||
|
||||
class Site
|
||||
attr_reader :url, :strategy
|
||||
delegate :get, :referer_url, :site_name, :artist_name, :profile_url, :image_url, :tags, :artist_record, :unique_id, :page_count, :file_url, :ugoira_frame_data, :ugoira_width, :ugoira_height, :to => :strategy
|
||||
|
||||
@@ -250,8 +250,7 @@ module Sources
|
||||
|
||||
# Refer to http://danbooru.donmai.us/wiki_pages/58938 for documentation on the Pixiv API.
|
||||
def get_metadata_from_spapi!(illust_id)
|
||||
phpsessid = agent.cookies.select do |cookie| cookie.name == "PHPSESSID" end.first.value
|
||||
spapi_url = "http://spapi.pixiv.net/iphone/illust.php?illust_id=#{illust_id}&PHPSESSID=#{phpsessid}"
|
||||
spapi_url = "http://spapi.pixiv.net/iphone/illust.php?illust_id=#{illust_id}&PHPSESSID=#{PixivWebAgent.phpsessid(agent)}"
|
||||
|
||||
agent.get(spapi_url) do |response|
|
||||
metadata = CSV.parse(response.content.force_encoding("UTF-8")).first
|
||||
@@ -298,31 +297,6 @@ module Sources
|
||||
raise Sources::Error.new("Couldn't get illust ID from URL: #{url}")
|
||||
end
|
||||
end
|
||||
|
||||
def agent
|
||||
@agent ||= begin
|
||||
mech = Mechanize.new
|
||||
|
||||
phpsessid = Cache.get("pixiv-phpsessid")
|
||||
if phpsessid
|
||||
cookie = Mechanize::Cookie.new("PHPSESSID", phpsessid)
|
||||
cookie.domain = ".pixiv.net"
|
||||
cookie.path = "/"
|
||||
mech.cookie_jar.add(cookie)
|
||||
else
|
||||
mech.get("http://www.pixiv.net") do |page|
|
||||
page.form_with(:action => "/login.php") do |form|
|
||||
form['pixiv_id'] = Danbooru.config.pixiv_login
|
||||
form['pass'] = Danbooru.config.pixiv_password
|
||||
end.click_button
|
||||
end
|
||||
phpsessid = mech.cookie_jar.cookies.select{|c| c.name == "PHPSESSID"}.first
|
||||
Cache.put("pixiv-phpsessid", phpsessid.value, 1.month) if phpsessid
|
||||
end
|
||||
|
||||
mech
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user