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.
@@ -1,77 +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 Post
21
- # A class to interact with the e621 web interface.
22
- #
23
- # @author Maxine Michalski
24
- # @api public
25
- # @since 2.0.0
26
- class Note
27
- # @author Maxine Michalski
28
- #
29
- # Fetch a list of notes
30
- #
31
- # @example Get a list of notes
32
- # E621::Post::Note.list(id: 1) #=> Array<E621::Post::Note>
33
- # @return [Array<E621::Note>]
34
- # @see https://e621.net/help/show/api#notes
35
- def self.list(post)
36
- unless post.is_a?(Hash) || post.is_a?(E621::Post)
37
- raise ArgumentError, 'A Hash or Post object is required'
38
- end
39
- post.store(:post_id, post.delete(:id)) if post.is_a?(Hash)
40
- post = { post_id: post.id } if post.is_a?(E621::Post)
41
- E621::API.fetch(:note, :index, post).map do |note|
42
- new(note)
43
- end
44
- end
45
-
46
- # @author Maxine Michalski
47
- #
48
- # Search for notes
49
- #
50
- # @example Get a list of notes
51
- # E621::Post::Note.search(query: 'moo') #=> Array<E621::Post::Note>
52
- # @return [Array<E621::Note>]
53
- # @see https://e621.net/help/show/api#notes
54
- def self.search(query)
55
- raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash)
56
- E621::API.fetch(:note, :search, query).map do |note|
57
- new(note)
58
- end
59
- end
60
-
61
- # @author Maxine Michalski
62
- #
63
- # Fetch a list of note versions
64
- #
65
- # @example Get a list of notes
66
- # E621::Post::Note.list(post_id: 1) #=> Array<E621::Post::Note>
67
- # @return [Array<E621::Note>]
68
- # @see https://e621.net/help/show/api#notes
69
- def self.history(query)
70
- raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash)
71
- E621::API.fetch(:note, :history, query).map do |note|
72
- new(note)
73
- end
74
- end
75
- end
76
- end
77
- end
@@ -1,71 +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
- # A class to interact with the e621 web interface.
21
- #
22
- # @author Maxine Michalski
23
- # @api public
24
- # @since 1.4.0
25
- class Tag
26
- # @author Maxine Michalski
27
- #
28
- # Fetch tag data
29
- #
30
- # @param tag [Hash|E621::Tag] a hash or tag object
31
- # @example Get tag information
32
- # E621::Tag.show(id: 1) #=> E621::Tag
33
- # @return [E621::Tag]
34
- # @see https://e621.net/help/show/api#tags
35
- def self.show(tag)
36
- unless (tag.is_a?(Hash) && tag[:id].is_a?(Integer)) ||
37
- tag.is_a?(E621::Tag)
38
- raise ArgumentError, 'A Hash or tag data object are required'
39
- end
40
- id = tag.is_a?(Hash) ? tag[:id] : tag.id
41
- new(E621::API.fetch(:tag, :show, id: id))
42
- end
43
-
44
- # @author Maxine Michalski
45
- #
46
- # Fetch a list of tags
47
- #
48
- # @param query [Hash] query data
49
- # @example Get list of tags
50
- # E621::Tag.list(name: 'feline') #=> Array<E621::Tag>
51
- # @return [Array<E621::Tag>]
52
- # @see https://e621.net/help/show/api#tags
53
- def self.list(query)
54
- raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash)
55
- E621::API.fetch(:tag, :index, query).map do |tag|
56
- new(tag)
57
- end
58
- end
59
-
60
- # @author Maxine Michalski
61
- #
62
- # Return a filled Tag object from a tag
63
- # @example Gwt tag information
64
- # tag.show #=> E621::Tag
65
- # @return [E621::Tag]
66
- def show
67
- E621::Tag.new(E621::API.fetch(:tag, :show,
68
- @id.nil? ? { name: @name } : { id: @id }))
69
- end
70
- end
71
- end
@@ -1,46 +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
- # A class to interact with the e621 web interface.
22
- #
23
- # @author Maxine Michalski
24
- # @api public
25
- # @since 2.0.0
26
- class Alias
27
- # @author Maxine Michalski
28
- #
29
- # Fetch tag aliases
30
- #
31
- # @param query [Hash] Parameter for query
32
- #
33
- # @example Get a list of posts
34
- # E621::Tag::Alias.list(implied_to: 'feline',
35
- # page: 1) #=> Array<E621::Tag::Alias>
36
- # @return [Array[E621::Tag::Alias]
37
- # @see https://e621.net/help/show/api#aliases
38
- def self.list(query)
39
- raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash)
40
- E621::API.fetch(:tag_alias, :index, query).map do |tag|
41
- new(tag)
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,46 +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
- # A class to interact with the e621 web interface.
22
- #
23
- # @author Maxine Michalski
24
- # @api public
25
- # @since 2.0.0
26
- class Implication
27
- # @author Maxine Michalski
28
- #
29
- # Fetch tag implications
30
- #
31
- # @param query [Hash] Parameter for query
32
- #
33
- # @example Get a list of posts
34
- # E621::Tag::Implication.list(implied_to: 'feline',
35
- # page: 1) #=> Array<E621::Tag::Implication>
36
- # @return [Array[E621::Tag::Implication]
37
- # @see https://e621.net/help/show/api#implications
38
- def self.list(query)
39
- raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash)
40
- E621::API.fetch(:tag_implication, :index, query).map do |tag|
41
- new(tag)
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,67 +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
- # A class to interact with the e621 web interface.
21
- #
22
- # @author Maxine Michalski
23
- # @api public
24
- # @since 1.4.0
25
- class User
26
- # @author Maxine Michalski
27
- #
28
- # Fetch data for user
29
- #
30
- # @param user [Hash|E621::User] User data to fetch from
31
- # @example Get user information
32
- # E621::User.show(id: 1) #=> E621::User
33
- # @return [E621::User]
34
- def self.show(user)
35
- unless (user.is_a?(Hash) && user[:id].is_a?(Integer)) ||
36
- user.is_a?(E621::User)
37
- raise ArgumentError, 'A Hash or user object are required'
38
- end
39
- user = user.is_a?(Hash) ? user : { id: user.id }
40
- new(E621::API.fetch(:user, :show, user))
41
- end
42
-
43
- # @author Maxine Michalski
44
- #
45
- # Fetch a list of users
46
- #
47
- # @example Get list of users
48
- # E621::User.list(name: 'purple') #=> Array<E621::User>
49
- # @return [E621::User]
50
- def self.list(query)
51
- raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash)
52
- E621::API.fetch(:user, :index, query).map do |user|
53
- new(user)
54
- end
55
- end
56
-
57
- # @author Maxine Michalski
58
- #
59
- # User information
60
- # @example Get User Information
61
- # user.show #=> E621::User
62
- # @return [E621::User]
63
- def show
64
- E621::User.new(E621::API.fetch(:user, :show, id: @id))
65
- end
66
- end
67
- end
@@ -1,166 +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 information about an artist on e621
21
- #
22
- # @author Maxine Michalski
23
- # @api public
24
- # @since 1.0.0
25
- class Artist
26
- # Artist ID
27
- # @example Get artist ID
28
- # artist.id #=> Integer
29
- # @return [Integer] id of artist
30
- attr_reader :id
31
-
32
- # Artist name
33
- # @example Get artist name
34
- # artist.name #=> String
35
- # @return [String] name of artist
36
- attr_reader :name
37
-
38
- # Alternative names for artist
39
- # @example Get alternative names for artist
40
- # artist.other_names #=> [] or Array<String>
41
- # @return [Array<String>] alternative names for artist
42
- attr_reader :other_names
43
-
44
- # Group name for artist
45
- # @example Get group name for artist
46
- # artist.group_name #=> String
47
- # @return [String] group name for artist
48
- attr_reader :group_name
49
-
50
- # URLs to find artist
51
- # @example Get parsed URIs for artist
52
- # artist.urls #=> Array<URI> or []
53
- # @return [Array<URI>] links to find artist
54
- attr_reader :urls
55
-
56
- # Version of artist information
57
- # @example Get version of this artist's information
58
- # artist.version #=> Integer
59
- # @return [Integer] version of artist information
60
- attr_reader :version
61
-
62
- # Updating user for this artist
63
- # @example Get the user, who last updated this artist
64
- # artist.updater #=> E621::User
65
- # @return [E621::User] updating user
66
- attr_reader :updater
67
-
68
- # @author Maxine Michalski
69
- #
70
- # Initializer for Artist
71
- #
72
- # @param artist [Hash] artist data
73
- # @example Get an artist instance
74
- # E621::Artist.new(id: 1) #=> E621::Artist instance
75
- # E621::Artist.new(name: 'artist') #=> E621::Artist instance
76
- # @return the object
77
- def initialize(artist)
78
- unless artist.is_a?(Hash)
79
- raise ArgumentError, "#{artist.class} is not a Hash"
80
- end
81
- if artist[:id].nil? && artist[:name].nil?
82
- raise ArgumentError, 'At least :id or :name must be given!'
83
- end
84
- artist.each do |k, v|
85
- if %i[id name group_name version is_active].include?(k)
86
- if k == :id && !(v.is_a?(Integer) && v.positive?)
87
- raise InvalidIDError, "ID out of range: #{v}"
88
- end
89
- instance_variable_set("@#{k}".to_sym, v)
90
- elsif %i[other_names urls updater_id].include?(k)
91
- __send__("setup_#{k}".to_sym, v)
92
- end
93
- end
94
- end
95
-
96
- # @author Maxine Michalski
97
- #
98
- # Comparison method for artists
99
- # @example Compare two tags, that are unequal
100
- # Tag.new(id: 1) == Tag.new(id: 2) #=> false
101
- # @return [TrueClass, FalseClass]
102
- def ==(other)
103
- return false unless other.is_a?(Artist)
104
- @id == other.id && @name == other.name && @version == other.version
105
- end
106
-
107
- # @author Maxine Michalski
108
- #
109
- # Check if this artist is active
110
- # @example Is artist active?
111
- # artist.active? #=> true or false
112
- # @return [TrueClass|FalseClass] depending on active status
113
- def active?
114
- @is_active
115
- end
116
-
117
- # @author Maxine Michalski
118
- #
119
- # Turn object into a hash representation of itself
120
- #
121
- # @example Turn a User into a Hash
122
- # Tag.new(id: 1).to_hash #=> { id: 1 }
123
- # @return [Hash]
124
- def to_hash
125
- hash = {}
126
- instance_variables.each do |i|
127
- hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i))
128
- end
129
- hash
130
- end
131
-
132
- private
133
-
134
- # @author Maxine Michalski
135
- #
136
- # Setup other names for artist
137
- #
138
- # @param names [String] comma separated list of names
139
- # @api private
140
- # @return [Array<String>]
141
- def setup_other_names(names)
142
- @other_names = names.split(',')
143
- end
144
-
145
- # @author Maxine Michalski
146
- #
147
- # Parsed URI to find artist
148
- #
149
- # @param urls [Array<String>] urls to parse
150
- # @api private
151
- # @return [Array<URI>]
152
- def setup_urls(urls)
153
- @urls = urls.map { |u| URI.parse(u) }
154
- end
155
-
156
- # @author Maxine Michalski
157
- #
158
- # Setup updating user
159
- # @param updater [Integer] ID of the user who last updated
160
- # @api private
161
- # @return [E621::User]
162
- def setup_updater_id(updater)
163
- @updater = E621::User.new(id: updater)
164
- end
165
- end
166
- end