refactored source code, work on pixiv integration

This commit is contained in:
albert
2011-09-26 16:47:22 -04:00
parent 11b623c66b
commit 284141aace
19 changed files with 201 additions and 45 deletions

View File

@@ -1,18 +1,36 @@
module Sources
class Site
attr_reader :url, :strategy
delegate :artist_name, :profile_url, :image_url, :tags, :to => :strategy
delegate :get, :site_name, :artist_name, :artist_alias, :profile_url, :image_url, :tags, :artist_record, :unique_id, :to => :strategy
def self.strategies
[Strategies::Fc2, Strategies::NicoSeiga, Strategies::Pixa, Strategies::Pixiv, Strategies::Tinami, Strategies::Default]
end
def initialize(url)
@url = url
case url
when /pixiv\.net/
@strategy = Strategies::Pixiv.new(url)
else
@strategy = Strategies::Default.new(url)
Site.strategies.each do |strategy|
if strategy.url_match?(url)
@strategy = strategy.new(url)
break
end
end
end
def to_json
return {
:artist_name => artist_name,
:profile_url => profile_url,
:tags => tags,
:danbooru_name => artist_record.first.try(:name),
:danbooru_id => artist_record.first.try(:id),
:unique_id => unique_id
}.to_json
end
def available?
strategy.present?
end
end
end