rubyhexagon 2.0.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/rubyhexagon.rb +6 -26
- data/lib/rubyhexagon/api.rb +14 -7
- data/lib/rubyhexagon/api/post.rb +4 -71
- data/lib/rubyhexagon/post.rb +111 -257
- data/lib/rubyhexagon/post/{image.rb → file.rb} +30 -39
- data/lib/rubyhexagon/{api/post/flag.rb → post/preview.rb} +24 -14
- data/lib/rubyhexagon/post/sample.rb +65 -0
- data/lib/rubyhexagon/{api/post/tag_item.rb → post/score.rb} +32 -17
- metadata +7 -26
- data/lib/rubyhexagon/api/artist.rb +0 -42
- data/lib/rubyhexagon/api/pool.rb +0 -80
- data/lib/rubyhexagon/api/post/note.rb +0 -77
- data/lib/rubyhexagon/api/tag.rb +0 -71
- data/lib/rubyhexagon/api/tag/alias.rb +0 -46
- data/lib/rubyhexagon/api/tag/implication.rb +0 -46
- data/lib/rubyhexagon/api/user.rb +0 -67
- data/lib/rubyhexagon/artist.rb +0 -166
- data/lib/rubyhexagon/pool.rb +0 -151
- data/lib/rubyhexagon/post/flag.rb +0 -116
- data/lib/rubyhexagon/post/note.rb +0 -174
- data/lib/rubyhexagon/post/tag_item.rb +0 -114
- data/lib/rubyhexagon/search/posts.rb +0 -116
- data/lib/rubyhexagon/tag.rb +0 -109
- data/lib/rubyhexagon/tag/alias.rb +0 -116
- data/lib/rubyhexagon/tag/implication.rb +0 -121
- data/lib/rubyhexagon/tag/type.rb +0 -94
- data/lib/rubyhexagon/user.rb +0 -117
- data/lib/rubyhexagon/user/level.rb +0 -102
@@ -1,116 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright 2014-2018, 2020 Maxine Michalski <maxine@furfind.net>
|
4
|
-
#
|
5
|
-
# This file is part of rubyhexagon.
|
6
|
-
#
|
7
|
-
# rubyhexagon is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# rubyhexagon is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with rubyhexagon. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
|
19
|
-
module Rubyhexagon
|
20
|
-
# Module to hold search classes
|
21
|
-
#
|
22
|
-
# @author Maxine Michalski
|
23
|
-
# @since 1.0.0
|
24
|
-
module Search
|
25
|
-
# Class to hold methods for Post searches.
|
26
|
-
#
|
27
|
-
# @author Maxine Michalski
|
28
|
-
# @since 1.0.0
|
29
|
-
class Posts
|
30
|
-
# @author Maxine Michalski
|
31
|
-
#
|
32
|
-
# Retrieve a list of deleted post, with deletion reason. Only id and
|
33
|
-
# del_reason is present.
|
34
|
-
# This method accepts blocks and only returns one page without blocks
|
35
|
-
#
|
36
|
-
# @param page [Integer] page of deleted posts to return
|
37
|
-
#
|
38
|
-
# @return [Array<Post>] an array of deleted posts
|
39
|
-
def self.deleted(page = 1)
|
40
|
-
d = fetch_deleted(page)
|
41
|
-
while block_given? && d != []
|
42
|
-
d.each { |del| yield del }
|
43
|
-
page += 1
|
44
|
-
d = fetch_deleted(page)
|
45
|
-
end
|
46
|
-
d
|
47
|
-
end
|
48
|
-
|
49
|
-
# @author Maxine Michalski
|
50
|
-
#
|
51
|
-
# Retrieve a list of post data, which is filtered by arguments.
|
52
|
-
# This method requires a block to be passed to it!
|
53
|
-
#
|
54
|
-
# @param tags [String] this can be any request that can be done on e621
|
55
|
-
# too
|
56
|
-
# @param limit [Integer] number of posts to return. This has a hard limit
|
57
|
-
# of 320
|
58
|
-
# @param before_id [Integer] start post ID is lesser than this ID
|
59
|
-
#
|
60
|
-
# This method accepts blocks and only returns one page without blocks
|
61
|
-
#
|
62
|
-
# @return [Array<Post>] an array of posts
|
63
|
-
def self.list(tags, limit = 320)
|
64
|
-
parameters = { tags: tags, limit: limit }
|
65
|
-
posts = fetch_posts(parameters)
|
66
|
-
while block_given? && posts != []
|
67
|
-
posts.each { |post| yield post }
|
68
|
-
parameters[:before_id] = posts.last.nil? ? 0 : posts.last.id
|
69
|
-
posts = fetch_posts(parameters)
|
70
|
-
end
|
71
|
-
posts
|
72
|
-
end
|
73
|
-
|
74
|
-
# @author Maxine Michalski
|
75
|
-
#
|
76
|
-
# Fetch popular posts by day, week or month
|
77
|
-
#
|
78
|
-
# @param timespan [Symbol] can be :day, :week or :month
|
79
|
-
# @raise ArgumentError if no valid symbol is given
|
80
|
-
#
|
81
|
-
# @return [Array<Post>]
|
82
|
-
def self.popular(timespan = :day)
|
83
|
-
unless %i[day week month].include?(timespan)
|
84
|
-
raise ArgumentError, "Unknown time span: #{timespan}"
|
85
|
-
end
|
86
|
-
API.new.fetch('post', "popular_by_#{timespan}", {}).map do |post|
|
87
|
-
Post.new(post[:id]).show(post)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
# @author Maxine Michalski
|
92
|
-
#
|
93
|
-
# Helper function for deleted posts
|
94
|
-
#
|
95
|
-
# @return [Array<Post>] array of deleted posts
|
96
|
-
def self.fetch_deleted(page)
|
97
|
-
API.new.fetch('post', 'deleted_index', page: page).map do |post|
|
98
|
-
DeletedPost.new(post[:id], post[:delreason])
|
99
|
-
end
|
100
|
-
end
|
101
|
-
private_class_method :fetch_deleted
|
102
|
-
|
103
|
-
# @author Maxine Michalski
|
104
|
-
#
|
105
|
-
# Helper function for posts
|
106
|
-
#
|
107
|
-
# @return [Array<Post>] array of posts
|
108
|
-
def self.fetch_posts(parameters)
|
109
|
-
API.new.fetch('post', 'index', parameters).map do |data|
|
110
|
-
Post.new(data[:id]).show(data)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
private_class_method :fetch_posts
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
data/lib/rubyhexagon/tag.rb
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright 2014-2018, 2020 Maxine Michalski <maxine@furfind.net>
|
4
|
-
#
|
5
|
-
# This file is part of rubyhexagon.
|
6
|
-
#
|
7
|
-
# rubyhexagon is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# rubyhexagon is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with rubyhexagon. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
|
19
|
-
module Rubyhexagon
|
20
|
-
# Class to hold tag information.
|
21
|
-
#
|
22
|
-
# @author Maxine Michalski
|
23
|
-
# @api public
|
24
|
-
# @since 1.0.0
|
25
|
-
class Tag
|
26
|
-
# Tag ID
|
27
|
-
# @example Get Tag ID
|
28
|
-
# tag.id #=> Integer
|
29
|
-
# @return [Integer] id of tag
|
30
|
-
attr_reader :id
|
31
|
-
|
32
|
-
# Tag name
|
33
|
-
# @example Get tag name
|
34
|
-
# tag.name #=> String
|
35
|
-
# @return [String] name of tag
|
36
|
-
attr_reader :name
|
37
|
-
|
38
|
-
# Number of posts, this tag is assigned to
|
39
|
-
# @example Get post count of tag
|
40
|
-
# tag.count #=> Integer
|
41
|
-
# @return [Integer] number of posts that have this tag assigned to them
|
42
|
-
attr_reader :count
|
43
|
-
|
44
|
-
# Tag type
|
45
|
-
# @example Get tag type
|
46
|
-
# tag.type $=> E621::Tag::Type
|
47
|
-
# @return [E621::Tag::Type] type of this tag
|
48
|
-
attr_reader :type
|
49
|
-
|
50
|
-
# @author Maxine Michalski
|
51
|
-
#
|
52
|
-
# Initializer for Tag
|
53
|
-
#
|
54
|
-
# @raise InvalidIDError|ArgumentError
|
55
|
-
#
|
56
|
-
# @param tag [Hash] tag data
|
57
|
-
# @example Get new tag instance by ID
|
58
|
-
# Tag.new(id: 1) #=> E621::Tag
|
59
|
-
# @example Get new tag instance by name
|
60
|
-
# E621::Tag.new(name: 'feline') #=> E621::Tag
|
61
|
-
#
|
62
|
-
# @return the object
|
63
|
-
def initialize(tag)
|
64
|
-
raise ArgumentError, "#{tag.class} is not a Hash" unless tag.is_a?(Hash)
|
65
|
-
if tag[:id].nil? && tag[:name].nil?
|
66
|
-
raise ArgumentError, 'At least :id or :name must be given!'
|
67
|
-
end
|
68
|
-
tag[:type_locked] = false if tag[:type_locked].nil?
|
69
|
-
tag.each do |k, v|
|
70
|
-
if %i[id name count].include?(k)
|
71
|
-
if k == :id && !(v.is_a?(Integer) && v.positive?)
|
72
|
-
raise InvalidIDError, "ID out of range: #{v}"
|
73
|
-
end
|
74
|
-
instance_variable_set("@#{k}".to_sym, v)
|
75
|
-
elsif k == :type
|
76
|
-
@type = E621::Tag::Type.new(id: v, locked: tag[:type_locked])
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
# @author Maxine Michalski
|
82
|
-
#
|
83
|
-
# Turn object into a hash representation of itself
|
84
|
-
#
|
85
|
-
# @example Turn a User into a Hash
|
86
|
-
# Tag.new(id: 1).to_hash #=> { id: 1 }
|
87
|
-
# @return [Hash]
|
88
|
-
def to_hash
|
89
|
-
hash = {}
|
90
|
-
instance_variables.each do |i|
|
91
|
-
hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i))
|
92
|
-
end
|
93
|
-
hash
|
94
|
-
end
|
95
|
-
|
96
|
-
# @author Maxine Michalski
|
97
|
-
#
|
98
|
-
# Comparison operator for Tag, to override the default one
|
99
|
-
#
|
100
|
-
# @param other [Object] object that should be compared
|
101
|
-
# @example Compare two tags, that are unequal
|
102
|
-
# Tag.new(id: 1) == Tag.new(id: 2) #=> false
|
103
|
-
# @return [TrueClass, FalseClass] test result of comparison
|
104
|
-
def ==(other)
|
105
|
-
return false unless other.is_a?(Tag)
|
106
|
-
@id == other.id && @name == other.name && @type == other.type
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
@@ -1,116 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright 2014-2018, 2020 Maxine Michalski <maxine@furfind.net>
|
4
|
-
#
|
5
|
-
# This file is part of rubyhexagon.
|
6
|
-
#
|
7
|
-
# rubyhexagon is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# rubyhexagon is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with rubyhexagon. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
|
19
|
-
module Rubyhexagon
|
20
|
-
class Tag
|
21
|
-
# Class to hold alias information.
|
22
|
-
#
|
23
|
-
# @author Maxine Michalski
|
24
|
-
# @api public
|
25
|
-
# @since 2.0.0
|
26
|
-
class Alias
|
27
|
-
# Alias ID
|
28
|
-
# @example Get alias ID
|
29
|
-
# alias.id #=> Integer
|
30
|
-
# @return [Integer] id of alias
|
31
|
-
attr_reader :id
|
32
|
-
|
33
|
-
# Alias name
|
34
|
-
# @example Get alias name
|
35
|
-
# alias.name #=> String
|
36
|
-
# @return [String] name of alias
|
37
|
-
attr_reader :name
|
38
|
-
|
39
|
-
# Tag this alias is for
|
40
|
-
# @example Get aliased tag
|
41
|
-
# alias.alias_to #=> E621::Tag
|
42
|
-
# @return [E621::Tag] tag this alias is aliased to
|
43
|
-
attr_reader :alias_to
|
44
|
-
|
45
|
-
# @author Maxine Michalski
|
46
|
-
#
|
47
|
-
# Initializer for Alias
|
48
|
-
#
|
49
|
-
# @raise InvalidIDError if alias ID is not valid
|
50
|
-
# @raise ArgumentError hash not valid
|
51
|
-
#
|
52
|
-
# @param ali [Hash] alias data, fetched from e621
|
53
|
-
# @option ali [Integer] :id alias ID
|
54
|
-
# @option ali [String] :name alias for tag
|
55
|
-
# @option ali [Integer] :alias_id ID of tag to alias
|
56
|
-
# @option ali [TrueClass|FalseClass] :pending statud
|
57
|
-
# @example Get alias isntance
|
58
|
-
# E621::Tag::Alias.new(id: 1, name: 'test', alias_id: 1,
|
59
|
-
# pending: false) #=> E621::Tag::Alias instance
|
60
|
-
# @return the object
|
61
|
-
def initialize(ali)
|
62
|
-
raise ArgumentError, "#{ali.class} is not a Hash" unless ali.is_a?(Hash)
|
63
|
-
if ali.keys != %i[id name alias_id pending]
|
64
|
-
mis = %i[id name alias_id pending] - ali.keys
|
65
|
-
raise ArgumentError, "Missing key#{mis.count > 1 ? 's' : ''}: #{mis}"
|
66
|
-
end
|
67
|
-
ali.each do |k, v|
|
68
|
-
if %i[id name pending].include?(k)
|
69
|
-
if k == :id && !(v.is_a?(Integer) && v.positive?)
|
70
|
-
raise InvalidIDError, "Invalid id: #{v}"
|
71
|
-
end
|
72
|
-
instance_variable_set("@#{k}".to_sym, v)
|
73
|
-
elsif k == :alias_id
|
74
|
-
@alias_to = E621::Tag.new(id: v)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
# @author Maxine Michalski
|
80
|
-
#
|
81
|
-
# Comparison method for Types, to give a more meaningful comparison
|
82
|
-
# @example Compare two tags, that are unequal
|
83
|
-
# Tag.new(id: 1) == Tag.new(id: 2) #=> false
|
84
|
-
# @return [TrueClass, FalseClass]
|
85
|
-
def ==(other)
|
86
|
-
other.is_a?(Alias) && @id == other.id
|
87
|
-
end
|
88
|
-
|
89
|
-
# @author Maxine Michalski
|
90
|
-
#
|
91
|
-
# Check if this alias is pending confirmation
|
92
|
-
# @example Is alias pending?
|
93
|
-
# alias.pending? #=> true or false
|
94
|
-
# @return [TrueClass] tag alias is pending
|
95
|
-
# @return [FalseClass] tag alias is not pending
|
96
|
-
def pending?
|
97
|
-
@pending
|
98
|
-
end
|
99
|
-
|
100
|
-
# @author Maxine Michalski
|
101
|
-
#
|
102
|
-
# Turn object into a hash representation of itself
|
103
|
-
#
|
104
|
-
# @example Turn an Alias into a Hash
|
105
|
-
# Tag.new(id: 1).to_hash #=> { id: 1 }
|
106
|
-
# @return [Hash]
|
107
|
-
def to_hash
|
108
|
-
hash = {}
|
109
|
-
instance_variables.each do |i|
|
110
|
-
hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i))
|
111
|
-
end
|
112
|
-
hash
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright 2014-2018, 2020 Maxine Michalski <maxine@furfind.net>
|
4
|
-
#
|
5
|
-
# This file is part of rubyhexagon.
|
6
|
-
#
|
7
|
-
# rubyhexagon is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# rubyhexagon is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with rubyhexagon. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
|
19
|
-
module Rubyhexagon
|
20
|
-
class Tag
|
21
|
-
# Class to hold implication information.
|
22
|
-
#
|
23
|
-
# @author Maxine Michalski
|
24
|
-
# @api public
|
25
|
-
# @since 2.0.0
|
26
|
-
class Implication
|
27
|
-
# Implication ID
|
28
|
-
# @example Get implication ID
|
29
|
-
# implication.id #=> Integer
|
30
|
-
# @return [Integer] id of implication
|
31
|
-
attr_reader :id
|
32
|
-
|
33
|
-
# Tag that implies another tag
|
34
|
-
# @example Get implying tag
|
35
|
-
# implication.tag #=> E621::Tag
|
36
|
-
# @return [E621::Tag] implying tag
|
37
|
-
attr_reader :tag
|
38
|
-
|
39
|
-
# Tag that is implied
|
40
|
-
# @example Get implied tag
|
41
|
-
# implication.implied #=> E621::Tag
|
42
|
-
# @return [E621::Tag] implied tag
|
43
|
-
attr_reader :implies
|
44
|
-
|
45
|
-
# @author Maxine Michalski
|
46
|
-
#
|
47
|
-
# Initializer for Implication
|
48
|
-
#
|
49
|
-
# @raise InvalidIDError if implication ID is not valid
|
50
|
-
# @raise ArgumentError hash not valid
|
51
|
-
#
|
52
|
-
# @param imply [Hash] implication data, fetched from e621
|
53
|
-
# @option imply [Integer] :id implication ID
|
54
|
-
# @option imply [Integer] :consequent_id implying tag ID
|
55
|
-
# @option imply [Integer] :predicate_id implied tag ID
|
56
|
-
# @option imply [TrueClass|FalseClass] :pending statud
|
57
|
-
# @example Get new implication instance
|
58
|
-
# E621::Tag::Implication.new(id: 1, consequent_id: 1, predicate_id: 2,
|
59
|
-
# pending: false) #=> E621::Tag::Implication
|
60
|
-
# @return the object
|
61
|
-
def initialize(imply)
|
62
|
-
unless imply.is_a?(Hash)
|
63
|
-
raise ArgumentError, "#{imply.class} is not a Hash"
|
64
|
-
end
|
65
|
-
if imply.keys != %i[id consequent_id predicate_id pending]
|
66
|
-
mis = %i[id consequent_id predicate_id pending] - imply.keys
|
67
|
-
raise ArgumentError, "Missing key#{mis.count > 1 ? 's' : ''}: #{mis}"
|
68
|
-
end
|
69
|
-
imply.each do |k, v|
|
70
|
-
if %i[id pending].include?(k)
|
71
|
-
if k == :id && !(v.is_a?(Integer) && v.positive?)
|
72
|
-
raise InvalidIDError, "Invalid id: #{v}"
|
73
|
-
end
|
74
|
-
instance_variable_set("@#{k}".to_sym, v)
|
75
|
-
elsif k == :consequent_id
|
76
|
-
@tag = E621::Tag.new(id: v)
|
77
|
-
elsif k == :predicate_id
|
78
|
-
@implies = E621::Tag.new(id: v)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
# @author Maxine Michalski
|
84
|
-
#
|
85
|
-
# Comparison method for Types, to give a more meaningful comparison
|
86
|
-
# @example Compare two tags, that are unequal
|
87
|
-
# Tag.new(id: 1) == Tag.new(id: 2) #=> false
|
88
|
-
# @return [TrueClass, FalseClass]
|
89
|
-
def ==(other)
|
90
|
-
other.is_a?(Implication) && @id == other.id
|
91
|
-
end
|
92
|
-
|
93
|
-
# @author Maxine Michalski
|
94
|
-
#
|
95
|
-
# Check if this implication is pending confirmation
|
96
|
-
#
|
97
|
-
# @example Is implication pending?
|
98
|
-
# implication.pending? #=> true or false
|
99
|
-
# @return [TrueClass] tag implication is pending
|
100
|
-
# @return [FalseClass] tag implication is not pending
|
101
|
-
def pending?
|
102
|
-
@pending
|
103
|
-
end
|
104
|
-
|
105
|
-
# @author Maxine Michalski
|
106
|
-
#
|
107
|
-
# Turn object into a hash representation of itself
|
108
|
-
#
|
109
|
-
# @example Turn a User into a Hash
|
110
|
-
# Tag.new(id: 1).to_hash #=> { id: 1 }
|
111
|
-
# @return [Hash]
|
112
|
-
def to_hash
|
113
|
-
hash = {}
|
114
|
-
instance_variables.each do |i|
|
115
|
-
hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i))
|
116
|
-
end
|
117
|
-
hash
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|