rubyhexagon 2.0.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/lib/rubyhexagon/tag/type.rb
DELETED
@@ -1,94 +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 type information.
|
22
|
-
#
|
23
|
-
# @api private
|
24
|
-
# @author Maxine Michalski
|
25
|
-
# @since 1.0.0
|
26
|
-
class Type
|
27
|
-
# Type ID
|
28
|
-
# @return [Integer] id of type
|
29
|
-
attr_reader :id
|
30
|
-
|
31
|
-
# Type name
|
32
|
-
# @return [String] name of type
|
33
|
-
attr_reader :name
|
34
|
-
|
35
|
-
# @author Maxine Michalski
|
36
|
-
#
|
37
|
-
# Initializer for Type
|
38
|
-
#
|
39
|
-
# @param type [Hash] type data, fetched from e621
|
40
|
-
# @option type [Integer] :id Type ID (can be one of 0, 1, 3, 4 or 5
|
41
|
-
# @option locked [TrueClass|FalseClass] :locked status
|
42
|
-
#
|
43
|
-
# @return the object
|
44
|
-
def initialize(type)
|
45
|
-
unless type.is_a?(Hash)
|
46
|
-
raise ArgumentError, "#{type.class} is not a Hash"
|
47
|
-
end
|
48
|
-
raise ArgumentError, 'Missing :locked key' if type[:locked].nil?
|
49
|
-
unless [0, 1, 3, 4, 5].include?(type[:id])
|
50
|
-
raise InvalidIDError, "Unkown type id: #{type[:id].inspect}"
|
51
|
-
end
|
52
|
-
@id = type[:id]
|
53
|
-
@name = [:general, :artist, nil, :copyright, :character,
|
54
|
-
:species][@id]
|
55
|
-
@locked = type[:locked] ? true : false
|
56
|
-
end
|
57
|
-
|
58
|
-
# @author Maxine Michalski
|
59
|
-
#
|
60
|
-
# Comparison method for Types, to give a more meaningful comparison
|
61
|
-
#
|
62
|
-
# @return [TrueClass, FalseClass]
|
63
|
-
def ==(other)
|
64
|
-
other.is_a?(Type) && @id == other.id && @name == other.name &&
|
65
|
-
@locked == other.locked?
|
66
|
-
end
|
67
|
-
|
68
|
-
# @author Maxine Michalski
|
69
|
-
#
|
70
|
-
# Check if this type is locked for the tag who has it assigned
|
71
|
-
#
|
72
|
-
# @return [TrueClass] tag type is locked
|
73
|
-
# @return [FalseClass] tag type is not locked
|
74
|
-
def locked?
|
75
|
-
@locked
|
76
|
-
end
|
77
|
-
|
78
|
-
# @author Maxine Michalski
|
79
|
-
#
|
80
|
-
# Turn object into a hash representation of itself
|
81
|
-
#
|
82
|
-
# @example Turn a User into a Hash
|
83
|
-
# Tag.new(id: 1).to_hash #=> { id: 1 }
|
84
|
-
# @return [Hash]
|
85
|
-
def to_hash
|
86
|
-
hash = {}
|
87
|
-
instance_variables.each do |i|
|
88
|
-
hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i))
|
89
|
-
end
|
90
|
-
hash
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
data/lib/rubyhexagon/user.rb
DELETED
@@ -1,117 +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
|
-
require 'time'
|
20
|
-
|
21
|
-
module Rubyhexagon
|
22
|
-
# Class to hold user information for users on e621.
|
23
|
-
#
|
24
|
-
# @author Maxine Michalski
|
25
|
-
# @api public
|
26
|
-
# @since 1.0.0
|
27
|
-
class User
|
28
|
-
# User ID
|
29
|
-
# @example Get ID from user
|
30
|
-
# user.id #=> Integer
|
31
|
-
# @return [Integer] id of user
|
32
|
-
attr_reader :id
|
33
|
-
|
34
|
-
# User name
|
35
|
-
# @example Get name from user
|
36
|
-
# user.name #=> String
|
37
|
-
# @return [String] name of user
|
38
|
-
attr_reader :name
|
39
|
-
|
40
|
-
# User access level
|
41
|
-
# @example Get user access level
|
42
|
-
# user.level #=> E621::User::Level
|
43
|
-
# @return [E621::User::Level] level of access, this user holds
|
44
|
-
attr_reader :level
|
45
|
-
|
46
|
-
# Time user was created
|
47
|
-
# @example Get user creation time
|
48
|
-
# user.created_at #=> Time
|
49
|
-
# @return [Time] registration time of this user
|
50
|
-
attr_reader :created_at
|
51
|
-
|
52
|
-
# Avatar post that user chosen
|
53
|
-
# @example Get user avatar post
|
54
|
-
# user.avatar #=> E621::Post
|
55
|
-
# @return [E621::Post] avatar set by user
|
56
|
-
attr_reader :avatar
|
57
|
-
|
58
|
-
# Artists tags, that belong to user
|
59
|
-
# @example Get artist tags
|
60
|
-
# user.artist_tags #=> Array<E621::Tag>
|
61
|
-
# @return [Array<E621::Tag>] an array of artist tags, associated with user
|
62
|
-
attr_reader :artist_tags
|
63
|
-
|
64
|
-
# @author Maxine Michalski
|
65
|
-
#
|
66
|
-
# Initializer for User
|
67
|
-
#
|
68
|
-
# @example Get a new user instance
|
69
|
-
# User.new(:id) #=> E621::User instance
|
70
|
-
# @param user [Hash] user data, fetched from e621
|
71
|
-
#
|
72
|
-
# @return the object
|
73
|
-
def initialize(user)
|
74
|
-
raise ArgumentError, "#{user.class} is not a Hash" unless user.is_a?(Hash)
|
75
|
-
raise ArgumentError, 'Hash must include :id' if user[:id].nil?
|
76
|
-
user.each do |k, v|
|
77
|
-
if %i[id name].include?(k)
|
78
|
-
if k == :id && !(v.is_a?(Integer) && v.positive?)
|
79
|
-
raise InvalidIDError, "ID out of range: #{v}"
|
80
|
-
end
|
81
|
-
instance_variable_set("@#{k}".to_sym, v)
|
82
|
-
elsif %i[created_at].include?(k)
|
83
|
-
instance_variable_set("@#{k}".to_sym, Time.parse(v))
|
84
|
-
elsif k == :artist_tags
|
85
|
-
@artist_tags = v.map { |t| E621::Tag.new(name: t) }
|
86
|
-
elsif k == :avatar_id
|
87
|
-
@avatar = E621::Post.new(id: v)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# @author Maxine Michalski
|
93
|
-
#
|
94
|
-
# Turn object into a hash representation of itself
|
95
|
-
#
|
96
|
-
# @example Turn a User into a Hash
|
97
|
-
# User.new(id: 1).to_hash #=> { id: 1 }
|
98
|
-
# @return [Hash]
|
99
|
-
def to_hash
|
100
|
-
hash = {}
|
101
|
-
instance_variables.each do |i|
|
102
|
-
hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i))
|
103
|
-
end
|
104
|
-
hash
|
105
|
-
end
|
106
|
-
|
107
|
-
# @author Maxine Michalski
|
108
|
-
#
|
109
|
-
# Comparison method for User objects
|
110
|
-
# @example Check two different users
|
111
|
-
# User.new(id: 1) == User.new(id: 2) #=> false
|
112
|
-
# @return [TrueClass, FalseClass]
|
113
|
-
def ==(other)
|
114
|
-
other.is_a?(User) && @id == other.id
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
@@ -1,102 +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 User
|
21
|
-
# Class to hold level information.
|
22
|
-
#
|
23
|
-
# @api private
|
24
|
-
# @author Maxine Michalski
|
25
|
-
# @since 1.0.0
|
26
|
-
class Level
|
27
|
-
# User level ID
|
28
|
-
# @return [Integer] id of level
|
29
|
-
attr_reader :id
|
30
|
-
|
31
|
-
# User level name
|
32
|
-
# @return [String] name of level
|
33
|
-
attr_reader :name
|
34
|
-
|
35
|
-
# @author Maxine Michalski
|
36
|
-
#
|
37
|
-
# Initializer for Level a user can have
|
38
|
-
#
|
39
|
-
# @param level [Hash] level a user can have.
|
40
|
-
#
|
41
|
-
# @return the object
|
42
|
-
def initialize(level)
|
43
|
-
raise ArgumentError, 'No has given.' unless level.is_a?(Hash)
|
44
|
-
raise ArgumentError, 'Hash requires an :id key' if level[:id].nil?
|
45
|
-
unless [0, 10, 20, 30, 32, 33, 34, 40, 50].include?(level[:id])
|
46
|
-
raise InvalidIDError, "Unknown level ID: #{level[:id]}"
|
47
|
-
end
|
48
|
-
@id = level[:id]
|
49
|
-
@name = if @id.between?(31, 39)
|
50
|
-
[nil, nil, :contributor, :former_staff, :janitor][@id - 30]
|
51
|
-
else
|
52
|
-
%i[unactivated blocked member privileged mod admin][@id / 10]
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# @author Maxine Michalski
|
57
|
-
#
|
58
|
-
# Comparison method for Level objects
|
59
|
-
#
|
60
|
-
# @return [TrueClass, FalseClass]
|
61
|
-
def ==(other)
|
62
|
-
other.is_a?(Level) && @id == other.id && @name == other.name
|
63
|
-
end
|
64
|
-
|
65
|
-
# @author Maxine Michalski
|
66
|
-
#
|
67
|
-
# Turn object into a hash representation of itself
|
68
|
-
#
|
69
|
-
# @return [Hash]
|
70
|
-
def to_hash
|
71
|
-
{ id: @id, name: @name }
|
72
|
-
end
|
73
|
-
|
74
|
-
# @author Maxine Michalski
|
75
|
-
#
|
76
|
-
# Test function for level names
|
77
|
-
#
|
78
|
-
# @return [TrueClass|FalseClass]
|
79
|
-
def test
|
80
|
-
__callee__.to_s.sub(/\?/, '').to_sym == @name
|
81
|
-
end
|
82
|
-
# @see test
|
83
|
-
alias unactivated? test
|
84
|
-
# @see test
|
85
|
-
alias blocked? test
|
86
|
-
# @see test
|
87
|
-
alias member? test
|
88
|
-
# @see test
|
89
|
-
alias privileged? test
|
90
|
-
# @see test
|
91
|
-
alias contributor? test
|
92
|
-
# @see test
|
93
|
-
alias former_staff? test
|
94
|
-
# @see test
|
95
|
-
alias janitor? test
|
96
|
-
# @see test
|
97
|
-
alias mod? test
|
98
|
-
# @see test
|
99
|
-
alias admin? test
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|