rubyhexagon 1.6.4 → 2.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.
Files changed (38) hide show
  1. checksums.yaml +5 -5
  2. data/lib/rubyhexagon.rb +34 -18
  3. data/lib/rubyhexagon/api.rb +96 -0
  4. data/lib/rubyhexagon/{login.rb → api/artist.rb} +9 -19
  5. data/lib/rubyhexagon/api/note.rb +50 -0
  6. data/lib/rubyhexagon/api/pool.rb +51 -0
  7. data/lib/rubyhexagon/api/post.rb +92 -0
  8. data/lib/rubyhexagon/api/post/flag.rb +36 -0
  9. data/lib/rubyhexagon/api/post/tag_item.rb +36 -0
  10. data/lib/rubyhexagon/api/tag.rb +65 -0
  11. data/lib/rubyhexagon/api/tag/alias.rb +41 -0
  12. data/lib/rubyhexagon/api/tag/implication.rb +41 -0
  13. data/lib/rubyhexagon/api/user.rb +52 -0
  14. data/lib/rubyhexagon/artist.rb +44 -32
  15. data/lib/rubyhexagon/error.rb +4 -5
  16. data/lib/rubyhexagon/note.rb +112 -0
  17. data/lib/rubyhexagon/pool.rb +22 -50
  18. data/lib/rubyhexagon/post.rb +142 -161
  19. data/lib/rubyhexagon/post/flag.rb +78 -0
  20. data/lib/rubyhexagon/post/image.rb +114 -0
  21. data/lib/rubyhexagon/post/tag_item.rb +74 -0
  22. data/lib/rubyhexagon/search/posts.rb +3 -3
  23. data/lib/rubyhexagon/tag.rb +20 -47
  24. data/lib/rubyhexagon/tag/alias.rb +87 -0
  25. data/lib/rubyhexagon/tag/implication.rb +91 -0
  26. data/lib/rubyhexagon/tag/type.rb +79 -0
  27. data/lib/rubyhexagon/user.rb +24 -30
  28. data/lib/rubyhexagon/user/level.rb +92 -0
  29. metadata +22 -13
  30. data/lib/rubyhexagon/helper/api.rb +0 -99
  31. data/lib/rubyhexagon/image.rb +0 -122
  32. data/lib/rubyhexagon/level.rb +0 -58
  33. data/lib/rubyhexagon/search/flag_history.rb +0 -62
  34. data/lib/rubyhexagon/search/pools.rb +0 -62
  35. data/lib/rubyhexagon/search/tag_history.rb +0 -61
  36. data/lib/rubyhexagon/search/tags.rb +0 -139
  37. data/lib/rubyhexagon/tag_change.rb +0 -69
  38. data/lib/rubyhexagon/type.rb +0 -72
@@ -0,0 +1,36 @@
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
+ # @since 2.0.0
25
+ class TagItem
26
+ def self.list(query)
27
+ unless query.is_a?(Hash)
28
+ raise ArgumentError, 'A Hash or Post object is required'
29
+ end
30
+ E621::API.fetch(:post_tag_history, :index, query).map do |note|
31
+ new(note)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,65 @@
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
+ # @since 1.4.0
24
+ class Tag
25
+ # @author Maxine Michalski
26
+ #
27
+ # Fetch tag data
28
+ #
29
+ # @param tag [Hash|E621::Tag] a hash or tag object
30
+ #
31
+ # @return [E621::Tag]
32
+ def self.show(tag)
33
+ unless (tag.is_a?(Hash) && tag[:id].is_a?(Integer)) ||
34
+ tag.is_a?(E621::Tag)
35
+ raise ArgumentError, 'A Hash or tag data object are required'
36
+ end
37
+ id = tag.is_a?(Hash) ? tag[:id] : tag.id
38
+ new(E621::API.fetch(:tag, :show, id: id))
39
+ end
40
+
41
+ # @author Maxine Michalski
42
+ #
43
+ # Fetch a list of tags
44
+ #
45
+ # @param query [Hash] query data
46
+ #
47
+ # @return [Array<E621::Tag>]
48
+ def self.list(query)
49
+ raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash)
50
+ E621::API.fetch(:tag, :index, query).map do |tag|
51
+ new(tag)
52
+ end
53
+ end
54
+
55
+ # @author Maxine Michalski
56
+ #
57
+ # Return a filled Tag object from a tag.
58
+ #
59
+ # @return [E621::Tag]
60
+ def show
61
+ E621::Tag.new(E621::API.fetch(:tag, :show,
62
+ @id.nil? ? { name: @name } : { id: @id }))
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,41 @@
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
+ # @since 2.0.0
25
+ class Alias
26
+ # @author Maxine Michalski
27
+ #
28
+ # Fetch tag aliases
29
+ #
30
+ # @param query [Hash] Parameter for query
31
+ #
32
+ # @return [Array[E621::Tag::Alias]
33
+ def self.list(query)
34
+ raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash)
35
+ E621::API.fetch(:tag_alias, :index, query).map do |tag|
36
+ new(tag)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
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
+ # @since 2.0.0
25
+ class Implication
26
+ # @author Maxine Michalski
27
+ #
28
+ # Fetch tag implications
29
+ #
30
+ # @param query [Hash] Parameter for query
31
+ #
32
+ # @return [Array[E621::Tag::Implication]
33
+ def self.list(query)
34
+ raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash)
35
+ E621::API.fetch(:tag_implication, :index, query).map do |tag|
36
+ new(tag)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,52 @@
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
+ # @since 1.4.0
24
+ class User
25
+ # @author Maxine Michalski
26
+ #
27
+ # Fetch data for user
28
+ #
29
+ # @param user [Hash|E621::User] User data to fetch from
30
+ #
31
+ # @return [E621::User]
32
+ def self.show(user)
33
+ unless (user.is_a?(Hash) && user[:id].is_a?(Integer)) ||
34
+ user.is_a?(E621::User)
35
+ raise ArgumentError, 'A Hash or user object are required'
36
+ end
37
+ user = user.is_a?(Hash) ? user : { id: user.id }
38
+ new(E621::API.fetch(:user, :show, user))
39
+ end
40
+
41
+ def self.list(query)
42
+ raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash)
43
+ E621::API.fetch(:user, :index, query).map do |user|
44
+ new(user)
45
+ end
46
+ end
47
+
48
+ def show
49
+ E621::User.new(E621::API.fetch(:user, :show, id: @id))
50
+ end
51
+ end
52
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2014-2018 Maxine Michalski <maxine@furfind.net>
3
+ # Copyright 2014-2018, 2020 Maxine Michalski <maxine@furfind.net>
4
4
  #
5
5
  # This file is part of rubyhexagon.
6
6
  #
@@ -29,42 +29,44 @@ module Rubyhexagon
29
29
  attr_reader :name
30
30
 
31
31
  # @return [Array<String>] alternative names for artist
32
- attr_reader :alternative_names
32
+ attr_reader :other_names
33
+
34
+ # @return [String] group name for artist
35
+ attr_reader :group_name
33
36
 
34
37
  # @return [Array<URI>] links to find artist
35
38
  attr_reader :urls
36
39
 
40
+ # @return [Integer] version of artist information
41
+ attr_reader :version
42
+
43
+ # @return [E621::User] updating user
44
+ attr_reader :updater
45
+
37
46
  # @author Maxine Michalski
38
47
  #
39
48
  # Initializer for Artist.
40
49
  #
41
- # @param artist [Hash] artist data, fetched from e621
50
+ # @param artist [Hash] artist data
42
51
  #
43
52
  # @return the object
44
53
  def initialize(artist)
45
- @name = artist
46
- end
47
-
48
- # @author Maxine Michalski
49
- #
50
- # Fills this object with additional artist data
51
- def show!
52
- artist = API.new.fetch('artist', 'index', name: @name).first
53
- @id = artist[:id].to_i
54
- @alternative_names = artist[:other_names].split(/,\s+/)
55
- @urls = artist[:urls].map { |u| URI(u) }
56
- @active = artist[:is_active]
57
- end
58
-
59
- # @author Maxine Michalski
60
- #
61
- # Returns a filled Artist object
62
- #
63
- # @return [Artist] filled out artist object
64
- def show
65
- artist = Artist.new(@name)
66
- artist.show!
67
- artist
54
+ unless artist.is_a?(Hash)
55
+ raise ArgumentError, "#{artist.class} is not a Hash"
56
+ end
57
+ if artist[:id].nil? && artist[:name].nil?
58
+ raise ArgumentError, 'At least :id or :name must be given!'
59
+ end
60
+ artist.each do |k, v|
61
+ if %i[id name group_name version is_active].include?(k)
62
+ if k == :id && !(v.is_a?(Integer) && v.positive?)
63
+ raise InvalidIDError, "ID out of range: #{v}"
64
+ end
65
+ instance_variable_set("@#{k}".to_sym, v)
66
+ elsif %i[other_names urls updater_id].include?(k)
67
+ __send__("setup_#{k}".to_sym, v)
68
+ end
69
+ end
68
70
  end
69
71
 
70
72
  # @author Maxine Michalski
@@ -74,11 +76,7 @@ module Rubyhexagon
74
76
  # @return [TrueClass, FalseClass]
75
77
  def ==(other)
76
78
  return false unless other.is_a?(Artist)
77
- if @id && other.id
78
- @id == other.id && @name == other.name
79
- else
80
- @name == other.name
81
- end
79
+ @id == other.id && @name == other.name && @version == other.version
82
80
  end
83
81
 
84
82
  # @author Maxine Michalski
@@ -88,7 +86,21 @@ module Rubyhexagon
88
86
  # @return [TrueClass] artist is active
89
87
  # @return [FalseClass] artist is not active
90
88
  def active?
91
- @active
89
+ @is_active
90
+ end
91
+
92
+ private
93
+
94
+ def setup_other_names(names)
95
+ @other_names = names.split(',')
96
+ end
97
+
98
+ def setup_urls(urls)
99
+ @urls = urls.map { |u| URI.parse(u) }
100
+ end
101
+
102
+ def setup_updater_id(updater)
103
+ @updater = E621::User.new(id: updater)
92
104
  end
93
105
  end
94
106
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2014-2018 Maxine Michalski <maxine@furfind.net>
3
+ # Copyright 2014-2018, 2020 Maxine Michalski <maxine@furfind.net>
4
4
  #
5
5
  # This file is part of rubyhexagon.
6
6
  #
@@ -34,10 +34,9 @@ module Rubyhexagon
34
34
  # @author Maxine Michalski
35
35
  # @since 1.6.0
36
36
  class AccessDenied < StandardError; end
37
-
38
- # Error class to denote that a Post was already favorited.
37
+ # Error class that is raised by attempting write access.
39
38
  #
40
39
  # @author Maxine Michalski
41
- # @since 1.6.0
42
- class AlreadyFavorited < StandardError; end
40
+ # @since 2.0.0
41
+ class APIWriteError < StandardError; end
43
42
  end
@@ -0,0 +1,112 @@
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
+ # This class holds note information. Notes are additional information on
21
+ # posts.
22
+ #
23
+ # @author Maxine Michalski
24
+ # @since 2.0.0
25
+ class Note
26
+ # @return [Integer] id for this note
27
+ attr_reader :id
28
+
29
+ # @return [Time] time of creation
30
+ attr_reader :created_at
31
+
32
+ # @return [Time] time of last update
33
+ attr_reader :updated_at
34
+
35
+ # @return [E621::User] user object of creator
36
+ attr_reader :creator
37
+
38
+ # @return [Integer] position x value
39
+ attr_reader :x
40
+
41
+ # @return [Integer] position y value
42
+ attr_reader :y
43
+
44
+ # @return [Array<Integer>] combined position (x, y)
45
+ attr_reader :point
46
+
47
+ # @return [Integer] width of object
48
+ attr_reader :width
49
+
50
+ # @return [Integer] height of object
51
+ attr_reader :height
52
+
53
+ # @return [Array<Integer>] combined rectangular (x, y, width, height)
54
+ attr_reader :rect
55
+
56
+ # @return [E621::Post] post this note belongs to
57
+ attr_reader :post
58
+
59
+ # @return [String] text content of note
60
+ attr_reader :body
61
+
62
+ # @return [Integer] version of this note
63
+ attr_reader :version
64
+
65
+ # @author Maxine Michalski
66
+ #
67
+ # Initializer for Note.
68
+ #
69
+ # @param note [Hash] note information in hash form
70
+ #
71
+ # @return the object
72
+ def initialize(note)
73
+ raise ArgumentError, "#{note.class} is not a Hash" unless note.is_a?(Hash)
74
+ raise ArgumentError, 'An id is required' if note[:id].nil?
75
+ note.each do |k, v|
76
+ if %i[id x y width height is_active version body].include?(k)
77
+ if k == :id && !(v.is_a?(Integer) && v.positive?)
78
+ raise InvalidIDError, "Invalid id: #{v}"
79
+ end
80
+ instance_variable_set("@#{k}".to_sym, v)
81
+ elsif %i[created_at updated_at].include?(k)
82
+ instance_variable_set("@#{k}".to_sym, Time.at(v[:s]))
83
+ elsif k == :post_id
84
+ @post = E621::Post.new(id: v)
85
+ elsif k == :creator_id
86
+ @creator = E621::User.new(id: v)
87
+ end
88
+ end
89
+ @point = [@x, @y]
90
+ @rect = [@x, @y, @width, @height]
91
+ end
92
+
93
+ # @author Maxine Michalski
94
+ #
95
+ # Determine if note is active or not.
96
+ #
97
+ # @return [TrueClass|FalseClass] active state of note
98
+ def active?
99
+ return false if @is_active.nil?
100
+ @is_active
101
+ end
102
+
103
+ # @author Maxine Michalski
104
+ #
105
+ # Comparison method for Notes, to give a more meaningful comparison.
106
+ #
107
+ # @return [TrueClass, FalseClass]
108
+ def ==(other)
109
+ other.is_a?(Note) && @id == other.id && @version == other.version
110
+ end
111
+ end
112
+ end