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
@@ -1,122 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2014-2018 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 for post file data. This is mostly an abstraction to have data
21
- # structures in a more Ruby like nature.
22
- #
23
- # @api private
24
- # @author Maxine Michalski
25
- # @since 1.0.0
26
- class Image
27
- # @return [URI] url of file
28
- attr_reader :url
29
-
30
- # @return [String] extension of file
31
- attr_reader :ext
32
-
33
- # @return [Integer] image/video width
34
- attr_reader :width
35
-
36
- # @return [Integer] image/video height
37
- attr_reader :height
38
-
39
- # @return [String] MD5 hash sum
40
- attr_reader :md5
41
-
42
- # @return [Integer] file size in bytes
43
- attr_reader :size
44
-
45
- # @author Maxine Michalski
46
- #
47
- # Initializer for a File. This is not a Ruby file class, but an abstraction
48
- # of e621 file information.
49
- #
50
- # @param file [Hash] file information
51
- #
52
- # @return the object
53
- def initialize(file)
54
- @url = URI.parse(file[:url])
55
- @md5 = File.basename(file[:url]).sub(/\.\w{3,4}$/, '')
56
- @ext = file[:ext]
57
- @width = file[:width].to_i
58
- @height = file[:height].to_i
59
- @size = file[:size].to_i
60
- @user_agent = { 'User-Agent' =>
61
- "#{Rubyhexagon::NAME}/#{Rubyhexagon::VERSION} "\
62
- '(by maxine_red on e621' }
63
- end
64
-
65
- # @author Maxine Michalski
66
- #
67
- # Comparison method to comapre two Image objects (and sub class objects)
68
- #
69
- # @return [TrueClass, FalseClass]
70
- def ==(other)
71
- other.is_a?(Image) && @md5 == other.md5
72
- end
73
-
74
- # @author Maxine Michalski
75
- #
76
- # Retrieve data from e621 and save it to file.
77
- #
78
- # @param dirname [String] path where to save. This needs be an existing
79
- # directory. This overwrites existing files.
80
- # @param filename [String] name of file, without extension
81
- #
82
- # @raise [ArgumentError] Argument given is not an existing directory
83
- def save!(dirname = './', filename = nil)
84
- raise ArgumentError, 'Not a directory!' unless File.directory?(dirname)
85
- filename ||= @md5
86
- loop do
87
- stream = @url.open(@user_agent).read
88
- File.open("#{dirname}/#{filename}.#{@ext}", 'w') do |f|
89
- f.print stream
90
- end
91
- break if Digest::MD5.hexdigest(stream) == @md5
92
- end
93
- end
94
- end
95
- class Sample < Image; end
96
-
97
- # Class for post file data. This is mostly an abstraction to have data
98
- # structures in a more Ruby like nature.
99
- # This class just holds an adapted version of #save!, to handle the case of
100
- # preview images having a different MD5 hash sum attribute than they actually
101
- # should have.
102
- # That is an e621 issue though.
103
- #
104
- # @api private
105
- # @author Maxine Michalski
106
- # @since 1.0.0
107
- class Preview < Image
108
- # @author Maxine Michalski
109
- #
110
- # Retrieve data from e621 and save it to file.
111
- #
112
- # @param dirname [String] path where to save. This needs be an existing
113
- # directory. This overwrites existing files.
114
- # @raise [ArgumentError] Argument given is not an existing directory
115
- def save!(dirname = './')
116
- raise ArgumentError, 'Not a directory!' unless File.directory?(dirname)
117
- File.open("#{dirname}/#{File.basename(@url.path)}", 'w') do |f|
118
- f.print @url.open(@user_agent).read
119
- end
120
- end
121
- end
122
- end
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2014-2018 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 level information.
21
- #
22
- # @api private
23
- # @author Maxine Michalski
24
- # @since 1.0.0
25
- class Level
26
- # @return [Integer] id of level
27
- attr_reader :id
28
-
29
- # @return [String] name of level
30
- attr_reader :name
31
-
32
- # @author Maxine Michalski
33
- #
34
- # Initializer for Level a user can have. This is just to have a more Ruby
35
- # like interface to it.
36
- #
37
- # @param level [Hash] level a user can have.
38
- #
39
- # @return the object
40
- def initialize(level)
41
- @id = level
42
- @name = if @id.between?(31, 39)
43
- [nil, nil, :contributor, :'former staff', :janotor][@id - 30]
44
- else
45
- %i[unactivated blocked member privileged mod admin][@id / 10]
46
- end
47
- end
48
-
49
- # @author Maxine Michalski
50
- #
51
- # Comparison method for Level objects
52
- #
53
- # @return [TrueClass, FalseClass]
54
- def ==(other)
55
- other.is_a?(Level) && @id == other.id && @name == other.name
56
- end
57
- end
58
- end
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2014-2018 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 fetching a list of flagged posts.
26
- #
27
- # @author Maxine Michalski
28
- # @since 1.4.0
29
- class FlagHistory
30
- # @author Maxine Michalski
31
- #
32
- # Retrieve a list of flagged posts, with flag 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<DeletedPost>] an array of deleted posts
39
- def self.list(page = 1)
40
- d = fetch_list(page)
41
- while block_given? && d != []
42
- d.each { |del| yield del }
43
- page += 1
44
- d = fetch_list(page)
45
- end
46
- d
47
- end
48
-
49
- # @author Maxine Michalski
50
- #
51
- # Helper function for flagged posts
52
- #
53
- # @return [Array<DeletedPost>] array of deleted posts
54
- def self.fetch_list(page)
55
- API.new.fetch('post_flag_history', 'index', page: page).map do |post|
56
- DeletedPost.new(post[:id], post[:reason])
57
- end
58
- end
59
- private_class_method :fetch_list
60
- end
61
- end
62
- end
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2014-2018 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 Pool searches.
26
- #
27
- # @author Maxine Michalski
28
- # @since 1.4.0
29
- class Pools
30
- # @author Maxine Michalski
31
- #
32
- # Retrieve a list of pools.
33
- # This method accepts blocks and only returns one page without blocks
34
- #
35
- # @param page [Integer] page of deleted pools to return
36
- #
37
- # @return [Array<Pool>] an array of deleted pools
38
- def self.list(query, page = 1)
39
- parameters = { query: query, page: page }
40
- pools = fetch_pools(parameters)
41
- while block_given? && pools != []
42
- pools.each { |pool| yield pool }
43
- parameters[:page] += 1
44
- pools = fetch_pools(parameters)
45
- end
46
- pools
47
- end
48
-
49
- # @author Maxine Michalski
50
- #
51
- # Helper function for pools
52
- #
53
- # @return [Array<Pool>] array of pools
54
- def self.fetch_pools(parameters)
55
- API.new.fetch('pool', 'index', parameters).map do |data|
56
- Pool.new(data[:id]).show(data)
57
- end
58
- end
59
- private_class_method :fetch_pools
60
- end
61
- end
62
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2014-2018 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 fetching tag changes.
26
- #
27
- # @author Maxine Michalski
28
- # @since 1.4.0
29
- class TagHistory
30
- # @author Maxine Michalski
31
- #
32
- # Retrieve a list of posts with changed tags
33
- # This method accepts blocks and only returns one page without blocks
34
- #
35
- # @param page [Integer] page of deleted posts to return
36
- #
37
- # @return [Array<Post>] an array of deleted posts
38
- def self.list(page = 1)
39
- d = fetch_list(page)
40
- while block_given? && d != []
41
- d.each { |del| yield del }
42
- page += 1
43
- d = fetch_list(page)
44
- end
45
- d
46
- end
47
-
48
- # @author Maxine Michalski
49
- #
50
- # Helper function for flagged posts
51
- #
52
- # @return [Array<DeletedPost>] array of deleted posts
53
- def self.fetch_list(page)
54
- API.new.fetch('post_tag_history', 'index', page: page).map do |post|
55
- TagChange.new(post)
56
- end
57
- end
58
- private_class_method :fetch_list
59
- end
60
- end
61
- end
@@ -1,139 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2014-2018 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 Tag searches.
26
- #
27
- # @author Maxine Michalski
28
- # @since 1.0.0
29
- class Tags
30
- # @author Maxine Michalski
31
- #
32
- # Retrieve a list of post data, which is filtered by arguments.
33
- # This method accepts a block and returns only one page without one.
34
- #
35
- # @param name [String] name pattern to search tags with
36
- # @param limit [Integer] number of tags to return. This has a hard limit
37
- # of 500
38
- # @param page [Integer] page to retieve
39
- #
40
- # @return [Array<Tag>] array of tags
41
- def self.list(name, limit = 500, page = 1)
42
- params = { name_pattern: name, order: :date, limit: limit,
43
- page: page }
44
- t = fetch_tags(params)
45
- while block_given? && t != []
46
- t.each { |tag| yield tag }
47
- params[:page] += 1
48
- t = fetch_tags(params)
49
- end
50
- t
51
- end
52
-
53
- # @author Maxine Michalski
54
- #
55
- # Retrieve information about implicated tags.
56
- # @param name [String] name pattern to search tags with
57
- # @param page [Integer] page to retrieve
58
- #
59
- # @raise ObjectNotFilledError if no name is present
60
- #
61
- # @return [Array<Tag>] array of implicated tags for this tag
62
- def self.implications(name, page = 1)
63
- params = { implied_to: name, page: page }
64
- tags = fetch_implications(params)
65
- while block_given? && tags != []
66
- tags.each { |tag| yield tag unless tag.nil? }
67
- tags = fetch_implications(params)
68
- params[:page] += 1
69
- end
70
- tags.compact
71
- end
72
-
73
- # @author Maxine Michalski
74
- #
75
- # Retrieve information about aliased tags.
76
- # @param name [String] name pattern to search tags with
77
- # @param page [Integer] page to retrieve
78
- #
79
- # @raise ObjectNotFilledError if no name is present
80
- #
81
- # @return [Array<Tag>] array of implicated tags for this tag
82
- def self.aliases(name, page = 1)
83
- params = { aliased_to: name, approved: true, page: page }
84
- tags = fetch_aliases(params)
85
- while block_given? && tags != []
86
- tags.each { |tag| yield tag unless tag.nil? }
87
- tags = fetch_aliases(params)
88
- params[:page] += 1
89
- end
90
- tags.compact
91
- end
92
-
93
- # @author Maxine Michalski
94
- #
95
- # Helper function to get Tag data
96
- #
97
- # @return [Array<Tag>] array of tags
98
- def self.fetch_tags(params)
99
- API.new.fetch('tag', 'index', params).map do |data|
100
- Tag.new(data[:id]).show(data)
101
- end
102
- end
103
- private_class_method :fetch_tags
104
-
105
- # @author Maxine Michalski
106
- #
107
- # Helper function to fetch implicated tags
108
- #
109
- # @param params [Hash] parameter for API call
110
- #
111
- # @return [Array<Tag>] array of implicated tags
112
- def self.fetch_implications(params)
113
- tag_params = { name: params[:implied_to], order: :date, limit: 1,
114
- page: 1 }
115
- implied_tag = fetch_tags(tag_params).first
116
- API.new.fetch('tag_implication', 'index', params).map do |tag|
117
- if tag[:consequent_id] == implied_tag.id && !tag[:pending]
118
- Tag.new(tag[:predicate_id])
119
- end
120
- end
121
- end
122
- private_class_method :fetch_implications
123
-
124
- # @author Maxine Michalski
125
- #
126
- # Helper function to fetch aliased tags
127
- #
128
- # @param params [Hash] parameter for API call
129
- #
130
- # @return [Array<Tag>] array of implicated tags
131
- def self.fetch_aliases(params)
132
- API.new.fetch('tag_alias', 'index', params).map do |tag|
133
- Tag.new(tag[:alias_id])
134
- end
135
- end
136
- private_class_method :fetch_aliases
137
- end
138
- end
139
- end