renamed artsiteproxy to sources
This commit is contained in:
8
app/assets/javascripts/sources.js
Normal file
8
app/assets/javascripts/sources.js
Normal file
@@ -0,0 +1,8 @@
|
||||
(function() {
|
||||
Danbooru.Sources = {};
|
||||
|
||||
Danbooru.Sources.get = function(url) {
|
||||
|
||||
}
|
||||
})();
|
||||
|
||||
9
app/controllers/sources_controller.rb
Normal file
9
app/controllers/sources_controller.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class SourcesController < ApplicationController
|
||||
# before_filter :member_only
|
||||
respond_to :json
|
||||
|
||||
def show
|
||||
@source = Sources::Site.new(params[:url])
|
||||
respond_with(@source)
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
module ArtSiteProxies
|
||||
class Proxy
|
||||
module Sources
|
||||
class Site
|
||||
attr_reader :url, :strategy
|
||||
delegate :artist_name, :profile_url, :image_url, :tags, :to => :strategy
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module ArtSiteProxies
|
||||
module Sources
|
||||
module Strategies
|
||||
class Base
|
||||
attr_reader :url, :agent
|
||||
@@ -1,4 +1,4 @@
|
||||
module ArtSiteProxies
|
||||
module Sources
|
||||
module Strategies
|
||||
class Default < Base
|
||||
def artist_name
|
||||
@@ -16,6 +16,10 @@ module ArtSiteProxies
|
||||
def tags
|
||||
[]
|
||||
end
|
||||
|
||||
protected
|
||||
def create_agent
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
25
app/logical/sources/strategies/fc2.rb
Normal file
25
app/logical/sources/strategies/fc2.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class Fc2 < Base
|
||||
def artist_name
|
||||
"?"
|
||||
end
|
||||
|
||||
def profile_url
|
||||
url
|
||||
end
|
||||
|
||||
def image_url
|
||||
url
|
||||
end
|
||||
|
||||
def tags
|
||||
[]
|
||||
end
|
||||
|
||||
protected
|
||||
def create_agent
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
25
app/logical/sources/strategies/nico_seiga.rb
Normal file
25
app/logical/sources/strategies/nico_seiga.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class NicoSeiga < Base
|
||||
def artist_name
|
||||
"?"
|
||||
end
|
||||
|
||||
def profile_url
|
||||
url
|
||||
end
|
||||
|
||||
def image_url
|
||||
url
|
||||
end
|
||||
|
||||
def tags
|
||||
[]
|
||||
end
|
||||
|
||||
protected
|
||||
def create_agent
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
25
app/logical/sources/strategies/pixa.rb
Normal file
25
app/logical/sources/strategies/pixa.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class Pixa < Base
|
||||
def artist_name
|
||||
"?"
|
||||
end
|
||||
|
||||
def profile_url
|
||||
url
|
||||
end
|
||||
|
||||
def image_url
|
||||
url
|
||||
end
|
||||
|
||||
def tags
|
||||
[]
|
||||
end
|
||||
|
||||
protected
|
||||
def create_agent
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,4 +1,4 @@
|
||||
module ArtSiteProxies
|
||||
module Sources
|
||||
module Strategies
|
||||
class Pixiv < Base
|
||||
attr_reader :artist_name, :profile_url, :image_url, :tags
|
||||
@@ -29,7 +29,7 @@ module ArtSiteProxies
|
||||
end
|
||||
|
||||
if links.any?
|
||||
profile_url = links[0]["href"]
|
||||
profile_url = "http://www.pixiv.net/" + links[0]["href"]
|
||||
children = links[0].children
|
||||
artist = children[0]["alt"]
|
||||
return [artist, profile_url]
|
||||
@@ -54,7 +54,7 @@ module ArtSiteProxies
|
||||
|
||||
if links.any?
|
||||
links.map do |node|
|
||||
[node.inner_text, node.attr("href")]
|
||||
[node.inner_text, "http://www.pixiv.net/" + node.attr("href")]
|
||||
end
|
||||
else
|
||||
[]
|
||||
25
app/logical/sources/strategies/tinami.rb
Normal file
25
app/logical/sources/strategies/tinami.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class Tinami < Base
|
||||
def artist_name
|
||||
"?"
|
||||
end
|
||||
|
||||
def profile_url
|
||||
url
|
||||
end
|
||||
|
||||
def image_url
|
||||
url
|
||||
end
|
||||
|
||||
def tags
|
||||
[]
|
||||
end
|
||||
|
||||
protected
|
||||
def create_agent
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/views/sources/show.json.erb
Normal file
6
app/views/sources/show.json.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
({
|
||||
"artist_name": "<%= j @source.artist_name %>",
|
||||
"profile_url": "<%= j @source.profile_url %>",
|
||||
"image_url": "<%= j @source.image_url %>",
|
||||
"tags": <%= @source.tags.to_json.html_safe %>
|
||||
});
|
||||
@@ -32,6 +32,7 @@ Danbooru::Application.routes.draw do
|
||||
resources :advertisements do
|
||||
resources :hits, :controller => "advertisement_hits", :only => [:create]
|
||||
end
|
||||
resource :art_site_proxy, :only => [:show]
|
||||
resources :artists do
|
||||
member do
|
||||
put :revert
|
||||
|
||||
@@ -5,9 +5,9 @@ require 'test_helper'
|
||||
class PixivProxyTest < ActiveSupport::TestCase
|
||||
context "The proxy" do
|
||||
should "get a single post" do
|
||||
proxy = ArtSiteProxies::Proxy.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=9646484")
|
||||
proxy = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=9646484")
|
||||
|
||||
assert_equal("member.php?id=4015", proxy.profile_url)
|
||||
assert_equal("http://www.pixiv.net/member.php?id=4015", proxy.profile_url)
|
||||
assert(proxy.tags.size > 0)
|
||||
first_tag = proxy.tags.first
|
||||
assert_equal(2, first_tag.size)
|
||||
|
||||
Reference in New Issue
Block a user