pixiv_api 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +8 -0
- data/Guardfile +14 -0
- data/LICENSE.txt +21 -0
- data/README.md +33 -0
- data/Rakefile +6 -0
- data/lib/pixiv_api.rb +22 -0
- data/lib/pixiv_api/array_response.rb +23 -0
- data/lib/pixiv_api/authentication.rb +60 -0
- data/lib/pixiv_api/client.rb +72 -0
- data/lib/pixiv_api/configuration.rb +48 -0
- data/lib/pixiv_api/pixiv_blob.rb +41 -0
- data/lib/pixiv_api/request.rb +18 -0
- data/lib/pixiv_api/request/favorite_users.rb +19 -0
- data/lib/pixiv_api/request/friends.rb +9 -0
- data/lib/pixiv_api/request/novels.rb +21 -0
- data/lib/pixiv_api/request/profiles.rb +9 -0
- data/lib/pixiv_api/request/promotions.rb +20 -0
- data/lib/pixiv_api/request/ranking.rb +9 -0
- data/lib/pixiv_api/request/search.rb +10 -0
- data/lib/pixiv_api/request/signup.rb +25 -0
- data/lib/pixiv_api/request/trends.rb +16 -0
- data/lib/pixiv_api/request/upload_work.rb +27 -0
- data/lib/pixiv_api/request/users.rb +13 -0
- data/lib/pixiv_api/request/util.rb +38 -0
- data/lib/pixiv_api/request/version.rb +9 -0
- data/lib/pixiv_api/request/works.rb +21 -0
- data/lib/pixiv_api/response.rb +134 -0
- data/lib/pixiv_api/response/action.rb +23 -0
- data/lib/pixiv_api/response/friend.rb +25 -0
- data/lib/pixiv_api/response/identity.rb +12 -0
- data/lib/pixiv_api/response/illustration.rb +6 -0
- data/lib/pixiv_api/response/manga.rb +6 -0
- data/lib/pixiv_api/response/novel.rb +15 -0
- data/lib/pixiv_api/response/pagination.rb +25 -0
- data/lib/pixiv_api/response/promotion.rb +11 -0
- data/lib/pixiv_api/response/request.rb +26 -0
- data/lib/pixiv_api/response/signup_validation_result.rb +7 -0
- data/lib/pixiv_api/response/tag.rb +9 -0
- data/lib/pixiv_api/response/ugoira.rb +18 -0
- data/lib/pixiv_api/response/upload_status.rb +7 -0
- data/lib/pixiv_api/response/upload_token.rb +7 -0
- data/lib/pixiv_api/response/user.rb +15 -0
- data/lib/pixiv_api/response/version.rb +7 -0
- data/lib/pixiv_api/response/work.rb +46 -0
- data/lib/pixiv_api/version.rb +3 -0
- data/pixiv_api.gemspec +32 -0
- data/spec/pixiv_api/authentication_spec.rb +57 -0
- data/spec/pixiv_api/client_spec.rb +28 -0
- data/spec/pixiv_api/configuration_spec.rb +41 -0
- data/spec/pixiv_api/pixiv_blob_spec.rb +23 -0
- data/spec/pixiv_api/request/favorite_users_spec.rb +47 -0
- data/spec/pixiv_api/request/friends_spec.rb +14 -0
- data/spec/pixiv_api/request/novels_spec.rb +37 -0
- data/spec/pixiv_api/request/profiles_spec.rb +13 -0
- data/spec/pixiv_api/request/signup_spec.rb +76 -0
- data/spec/pixiv_api/request/upload_work_spec.rb +41 -0
- data/spec/pixiv_api/request/users_spec.rb +32 -0
- data/spec/pixiv_api/request/works_spec.rb +16 -0
- data/spec/pixiv_api/version_spec.rb +7 -0
- data/spec/pixiv_api_spec.rb +8 -0
- metadata +275 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
module PixivApi
|
2
|
+
module Request
|
3
|
+
module Promotions
|
4
|
+
def promotions(site_id:, **args)
|
5
|
+
args.merge!(site_id: site_id)
|
6
|
+
objects_from_response(Response::Promotion, :get, '/v1/me/promotions.json', args)
|
7
|
+
end
|
8
|
+
|
9
|
+
def update_promotions(site_id:, **args)
|
10
|
+
args.merge!(site_id: site_id)
|
11
|
+
action_from_response(Response::Promotion, :put, '/v1/me/promotions.json', args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def delete_promotions(site_id:, **args)
|
15
|
+
args.merge!(site_id: site_id)
|
16
|
+
action_from_response(Response::Promotion, :delete, '/v1/me/promotions.json', args)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module PixivApi
|
2
|
+
module Request
|
3
|
+
module Signup
|
4
|
+
def signup_validation_send_mail(*args)
|
5
|
+
object_from_response(Response::SignupValidationResult, :get, 'v1/signup_validation/send_mail', args.extract_options!)
|
6
|
+
end
|
7
|
+
|
8
|
+
def signup_send_mail(*args)
|
9
|
+
object_from_response(Response::SignupValidationResult, :post, 'v1/signup/send_mail', args.extract_options!)
|
10
|
+
end
|
11
|
+
|
12
|
+
def signup_validation_check_code(*args)
|
13
|
+
object_from_response(Response::SignupValidationResult, :get, 'v1/signup_validation/check_code', args.extract_options!)
|
14
|
+
end
|
15
|
+
|
16
|
+
def signup_validation(*args)
|
17
|
+
object_from_response(Response::SignupValidationResult, :get, 'v1/signup_validation', args.extract_options!)
|
18
|
+
end
|
19
|
+
|
20
|
+
def signup(*args)
|
21
|
+
object_from_response(Response::SignupValidationResult, :post, 'v1/signup', args.extract_options!)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module PixivApi
|
2
|
+
module Request
|
3
|
+
module Trends
|
4
|
+
def trend_works(*args)
|
5
|
+
objects_from_response(Response::Work, :get, '/v1/trends/works.json', args.extract_options!)
|
6
|
+
end
|
7
|
+
|
8
|
+
def trend_tags(*args)
|
9
|
+
raise PixivApi::Client::UnsupportedApiError, 'route of /v1/trends/tags.json is deprecated.'
|
10
|
+
|
11
|
+
# arguments = Arguments.new(args)
|
12
|
+
# objects_from_response(Response::Tag, :get, '/v1/trends/tags.json', arguments.options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'mime/types'
|
2
|
+
|
3
|
+
module PixivApi
|
4
|
+
module Request
|
5
|
+
module UploadWork
|
6
|
+
def upload(files:, type:, age_limit:, sexual:, **args)
|
7
|
+
options = {
|
8
|
+
body: args.merge(
|
9
|
+
{
|
10
|
+
type: type,
|
11
|
+
age_limit: age_limit,
|
12
|
+
sexual: sexual,
|
13
|
+
files: files,
|
14
|
+
}
|
15
|
+
)
|
16
|
+
}
|
17
|
+
|
18
|
+
object_from_response(Response::UploadToken, :post, '/v1/upload/works', options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def upload_status(upload_token:)
|
22
|
+
options = { params: { upload_token: upload_token } }
|
23
|
+
object_from_response(Response::UploadStatus, :get, "/v1/upload/works/status.json", options)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module PixivApi
|
2
|
+
module Request
|
3
|
+
module Users
|
4
|
+
def me(*args)
|
5
|
+
object_from_response(Response::User, :get, '/v1/me.json', *args)
|
6
|
+
end
|
7
|
+
|
8
|
+
def user(user_id:, **args)
|
9
|
+
object_from_response(Response::User, :get, "/v1/users/#{user_id}.json", *args)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext/hash/slice'
|
3
|
+
|
4
|
+
module PixivApi
|
5
|
+
module Request
|
6
|
+
module Util
|
7
|
+
def object_from_response(klass, http_method, path, *opts)
|
8
|
+
response = request(http_method, path, *opts)
|
9
|
+
parsed = response.parsed['response']
|
10
|
+
parsed = parsed[0] if parsed.is_a?(Array)
|
11
|
+
|
12
|
+
klass.from_response(response, parsed)
|
13
|
+
end
|
14
|
+
|
15
|
+
def objects_from_response(klass, http_method, path, *opts)
|
16
|
+
response = request(http_method, path, *opts)
|
17
|
+
objects_from_array(response, klass, response.parsed['response'] || [])
|
18
|
+
end
|
19
|
+
|
20
|
+
def action_from_response(http_method, path, *opts)
|
21
|
+
response = request(http_method, path, *opts)
|
22
|
+
Response::Action.from_response(response)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def objects_from_array(response, klass, array)
|
28
|
+
ArrayResponse.from_response(response, klass, array)
|
29
|
+
end
|
30
|
+
|
31
|
+
def request(http_method, path, *opts)
|
32
|
+
options = opts.extract_options!
|
33
|
+
|
34
|
+
public_send(http_method, path, options.slice(:params, :body))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PixivApi
|
2
|
+
module Request
|
3
|
+
module Works
|
4
|
+
def my_works(*args)
|
5
|
+
objects_from_response(Response::Work, :get, '/v1/me/works.json', args.extract_options!)
|
6
|
+
end
|
7
|
+
|
8
|
+
def works(*args)
|
9
|
+
objects_from_response(Response::Work, :get, '/v1/works.json', args.extract_options!)
|
10
|
+
end
|
11
|
+
|
12
|
+
def user_works(user_id:, **args)
|
13
|
+
objects_from_response(Response::Work, :get, '/v1/me/works.json', args)
|
14
|
+
end
|
15
|
+
|
16
|
+
def work(id:, **args)
|
17
|
+
object_from_response(Response::Work, :get, "/v1/works/#{id}.json", args)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'memoizable'
|
2
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
3
|
+
|
4
|
+
module PixivApi
|
5
|
+
class Response
|
6
|
+
autoload :Action, 'pixiv_api/response/action'
|
7
|
+
autoload :User, 'pixiv_api/response/user'
|
8
|
+
autoload :Identity, 'pixiv_api/response/identity'
|
9
|
+
autoload :Work, 'pixiv_api/response/work'
|
10
|
+
autoload :Novel, 'pixiv_api/response/novel'
|
11
|
+
autoload :Manga, 'pixiv_api/response/manga'
|
12
|
+
autoload :Illustration, 'pixiv_api/response/illustration'
|
13
|
+
autoload :Tag, 'pixiv_api/response/tag'
|
14
|
+
autoload :Ugoira, 'pixiv_api/response/ugoira'
|
15
|
+
autoload :Friend, 'pixiv_api/response/friend'
|
16
|
+
autoload :Promotion, 'pixiv_api/response/promotion'
|
17
|
+
autoload :Pagination, 'pixiv_api/response/pagination'
|
18
|
+
autoload :Request, 'pixiv_api/response/request'
|
19
|
+
autoload :SignupValidationResult, 'pixiv_api/response/signup_validation_result'
|
20
|
+
autoload :Version, 'pixiv_api/response/version'
|
21
|
+
autoload :UploadToken, 'pixiv_api/response/upload_token'
|
22
|
+
autoload :UploadStatus, 'pixiv_api/response/upload_status'
|
23
|
+
|
24
|
+
include Memoizable
|
25
|
+
extend Forwardable
|
26
|
+
|
27
|
+
attr_reader :attributes, :response
|
28
|
+
alias_method :to_h, :attributes
|
29
|
+
|
30
|
+
def_delegators :@attributes, :fetch, :slice, :values_at
|
31
|
+
|
32
|
+
class << self
|
33
|
+
def from_response(response, *attributes)
|
34
|
+
new(response, *attributes)
|
35
|
+
end
|
36
|
+
|
37
|
+
def attr_reader(*attributes)
|
38
|
+
attributes.each do |attr|
|
39
|
+
define_attribute_method(attr)
|
40
|
+
define_predicate_method(attr)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def define_attribute_method(key1, klass = nil, key2 = nil)
|
45
|
+
define_method(key1) do
|
46
|
+
if klass.nil?
|
47
|
+
@attributes[key1]
|
48
|
+
else
|
49
|
+
if @attributes[key1]
|
50
|
+
dup = attributes_for_object(key1, key2)
|
51
|
+
klass.new(@response, dup)
|
52
|
+
else
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
memoize(key1)
|
59
|
+
end
|
60
|
+
|
61
|
+
def define_attributes_method(key1, klass = nil, key2 = nil)
|
62
|
+
define_method(key1) do
|
63
|
+
if klass.nil?
|
64
|
+
@attributes[key1]
|
65
|
+
else
|
66
|
+
@attributes[key1].map do |attr|
|
67
|
+
dup = attributes_for_object(key1, key2)
|
68
|
+
klass.new(@response, dup)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
memoize(key1)
|
74
|
+
end
|
75
|
+
|
76
|
+
def define_time_method(*attributes)
|
77
|
+
attributes.each do |attr|
|
78
|
+
define_method(attr) do
|
79
|
+
Time.parse(@attributes[attr])
|
80
|
+
end
|
81
|
+
|
82
|
+
memoize(attr)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def define_blob_method(key)
|
87
|
+
method_name = :"blob_#{key}"
|
88
|
+
|
89
|
+
define_method method_name do
|
90
|
+
fetch(key, {}).each_with_object({}) do |(key, value), memo|
|
91
|
+
memo[key] = PixivApi::PixivBlob.new(value)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
memoize(method_name)
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def define_predicate_method(key1, key2 = key1)
|
101
|
+
predicate_method = :"#{key1}?"
|
102
|
+
|
103
|
+
define_method(predicate_method) do ||
|
104
|
+
!!@attributes[key2]
|
105
|
+
end
|
106
|
+
|
107
|
+
memoize(predicate_method)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def initialize(response, attributes = {})
|
112
|
+
@response = response
|
113
|
+
@request = PixivApi::Response::Request.new(response)
|
114
|
+
@attributes = attributes.with_indifferent_access
|
115
|
+
end
|
116
|
+
|
117
|
+
def [](method)
|
118
|
+
public_send(method.to_sym)
|
119
|
+
rescue NoMethodError
|
120
|
+
nil
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
def attributes_for_object(key1, key2=nil)
|
126
|
+
if key2.nil?
|
127
|
+
@attributes[key1]
|
128
|
+
else
|
129
|
+
attributes = @attributes.dup
|
130
|
+
attributes.delete(key1).merge(key2 => attributes)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PixivApi
|
2
|
+
class Response
|
3
|
+
class Action < Response
|
4
|
+
attr_reader :status
|
5
|
+
|
6
|
+
def self.from_response(response)
|
7
|
+
new(response, response.parsed)
|
8
|
+
end
|
9
|
+
|
10
|
+
def errors
|
11
|
+
fetch('errors', {})
|
12
|
+
end
|
13
|
+
|
14
|
+
def success?
|
15
|
+
status == 'success'
|
16
|
+
end
|
17
|
+
|
18
|
+
def failure?
|
19
|
+
!success?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module PixivApi
|
2
|
+
class Response
|
3
|
+
class Friend < Identity
|
4
|
+
attr_reader :id, :account, :user_id, :name
|
5
|
+
|
6
|
+
define_blob_method :profile_image_urls
|
7
|
+
|
8
|
+
def initialize(response, attributes)
|
9
|
+
user_id = attributes['user'].delete('id')
|
10
|
+
|
11
|
+
merged = attributes['user'].merge(
|
12
|
+
id: attributes['id'],
|
13
|
+
user_id: user_id
|
14
|
+
)
|
15
|
+
|
16
|
+
super(response, merged)
|
17
|
+
end
|
18
|
+
|
19
|
+
def avatar_url
|
20
|
+
blob_profile_image_urls['px_50x50']
|
21
|
+
end
|
22
|
+
memoize(:avatar_url)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PixivApi
|
2
|
+
class Response
|
3
|
+
class Novel < Identity
|
4
|
+
attr_reader :id, :title, :caption, :tags, :stats,
|
5
|
+
:publicity, :age_limit, :is_liked, :favorite_id,
|
6
|
+
:page_count, :text_length, :series, :body
|
7
|
+
|
8
|
+
define_attribute_method :user, Response::User
|
9
|
+
|
10
|
+
define_blob_image_method :image_urls
|
11
|
+
|
12
|
+
define_time_method :created_time, :reuploaded_time
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|