rubyhexagon 1.3.0 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d31432089ab4b468c94966f76cd32f4db815d34a84640115f6fc07e27cf81095
4
- data.tar.gz: fc239bb33f258b73419a6c110c84480fcb59732e99109431d8591e392fadc486
3
+ metadata.gz: f648db04caba89f3461c14c60bf3054e0727c265bfa5ae5a45374135043fb284
4
+ data.tar.gz: 40c7af470e95c3d8ab97f469354ec494cf6fbe71bc191e2b33770c0ffb494bd7
5
5
  SHA512:
6
- metadata.gz: 118cc4709487a0d4a180fa9b9e50a4158bdaf2fe6950e4480d8e6b17de1090f4e89a3732d6a66da03ed87a733933b60673c276e1ddf26d95cb8f24a4ed3b16f0
7
- data.tar.gz: 4ecfe79a22af4fc728045a2218140ed3aa92f925142ae95be52f9de3cf722229f0e60a4a2a6d513f0b7a5ec76a4b82f9cc972c3d03a692ef5f6574320a561a01
6
+ metadata.gz: 45fd6046f22d1d6a539af0e08aa2a9a8676269b96fd32f00d0d298f3e28dadbcf37970b7b97be6bcae699ce3c4c3e168268408dc6d69cc4eb07ca119c00f6201
7
+ data.tar.gz: ccd2c946edfcb2c2ce1dbff518f40ca6c84ad5d0a4e1311c60a9586ebc02f950f6dbe49ce5d776f4a026685f87c607ae73604d97881e4d631fa1996615441018
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright 2014-2018 Maxine Michalski <maxine@furfind.net>
2
4
  #
3
5
  # This file is part of rubyhexagon.
@@ -14,7 +16,7 @@
14
16
  # You should have received a copy of the GNU General Public License
15
17
  # along with rubyhexagon. If not, see <http://www.gnu.org/licenses/>.
16
18
 
17
- module E621
19
+ module Rubyhexagon
18
20
  # Class to hold information about an artist on e621
19
21
  #
20
22
  # @author Maxine Michalski
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright 2014-2018 Maxine Michalski <maxine@furfind.net>
2
4
  #
3
5
  # This file is part of rubyhexagon.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright 2014-2018 Maxine Michalski <maxine@furfind.net>
2
4
  #
3
5
  # This file is part of rubyhexagon.
@@ -15,7 +17,7 @@
15
17
  # You should have received a copy of the GNU General Public License
16
18
  # along with rubyhexagon. If not, see <http://www.gnu.org/licenses/>.
17
19
 
18
- module E621
20
+ module Rubyhexagon
19
21
  # An interface class, to unify calls from other code to e621 [dot] net.
20
22
  # This class handles rate limiting, as well as provides a more uniform
21
23
  # approach in making requests.
@@ -36,13 +38,11 @@ module E621
36
38
  # Initializer for API. All methods are instance methods.
37
39
  #
38
40
  # @return the object
39
- def initialize(rspec = false)
41
+ def initialize
40
42
  @user_agent = { 'User-Agent' =>
41
- "#{E621::NAME}/#{E621::VERSION} (by maxine_red on e621" }
42
- @rspec = rspec
43
- @base = if @rspec || !defined? RSpec then 'https://e621.net'
44
- else 'spec/data'
45
- end
43
+ "#{Rubyhexagon::NAME}/#{Rubyhexagon::VERSION} "\
44
+ '(by maxine_red on e621' }
45
+ @base = 'https://e621.net'
46
46
  lock_path = '/tmp/rubyhexagon.lock'
47
47
  @lock_file = File.open(lock_path, 'a')
48
48
  end
@@ -62,23 +62,11 @@ module E621
62
62
  query = query.to_a.map { |q| "#{q.first}=#{q.last}" }.join('&')
63
63
  query = "?#{query}" unless query == ''
64
64
  uri = "#{@base}/#{noun}/#{action}.json#{query}"
65
- fetch_data(uri)
66
- end
67
-
68
- private
69
-
70
- # @author Maxine Michalski
71
- #
72
- def fetch_data(uri)
65
+ uri = URI.parse(uri)
73
66
  lock do
74
- data = if @rspec || !defined? RSpec then open(uri, @user_agent).read
75
- else File.open(uri).read
76
- end
67
+ data = uri.open(@user_agent).read
77
68
  JSON.parse(data, symbolize_names: true)
78
69
  end
79
- rescue SocketError
80
- sleep 5
81
- retry
82
70
  end
83
71
 
84
72
  # @author Maxine Michalski
@@ -93,7 +81,7 @@ module E621
93
81
  data = yield
94
82
  # There is a hard limit of 2 requests per second, but to be nice we wait
95
83
  # a whole second between requests.
96
- sleep 1 if @rspec || !defined? RSpec
84
+ sleep 1
97
85
  ensure
98
86
  @lock_file.flock(File::LOCK_UN)
99
87
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright 2014-2018 Maxine Michalski <maxine@furfind.net>
2
4
  #
3
5
  # This file is part of rubyhexagon.
@@ -14,7 +16,7 @@
14
16
  # You should have received a copy of the GNU General Public License
15
17
  # along with rubyhexagon. If not, see <http://www.gnu.org/licenses/>.
16
18
 
17
- module E621
19
+ module Rubyhexagon
18
20
  # Class for post file data. This is mostly an abstraction to have data
19
21
  # structures in a more Ruby like nature.
20
22
  #
@@ -49,14 +51,15 @@ module E621
49
51
  #
50
52
  # @return the object
51
53
  def initialize(file)
52
- @url = URI(file[:url])
54
+ @url = URI.parse(file[:url])
53
55
  @md5 = File.basename(file[:url]).sub(/\.\w{3,4}$/, '')
54
56
  @ext = file[:ext]
55
57
  @width = file[:width].to_i
56
58
  @height = file[:height].to_i
57
59
  @size = file[:size].to_i
58
60
  @user_agent = { 'User-Agent' =>
59
- "#{E621::NAME}/#{E621::VERSION} (by maxine_red on e621" }
61
+ "#{Rubyhexagon::NAME}/#{Rubyhexagon::VERSION} "\
62
+ '(by maxine_red on e621' }
60
63
  end
61
64
 
62
65
  # @author Maxine Michalski
@@ -81,7 +84,7 @@ module E621
81
84
  raise ArgumentError, 'Not a directory!' unless File.directory?(dirname)
82
85
  filename ||= @md5
83
86
  loop do
84
- stream = open(@url, @user_agent).read
87
+ stream = @url.open(@user_agent).read
85
88
  File.open("#{dirname}/#{filename}.#{@ext}", 'w') do |f|
86
89
  f.print stream
87
90
  end
@@ -112,7 +115,7 @@ module E621
112
115
  def save!(dirname = './')
113
116
  raise ArgumentError, 'Not a directory!' unless File.directory?(dirname)
114
117
  File.open("#{dirname}/#{File.basename(@url.path)}", 'w') do |f|
115
- f.print open(@url, @user_agent).read
118
+ f.print @url.open(@user_agent).read
116
119
  end
117
120
  end
118
121
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright 2014-2018 Maxine Michalski <maxine@furfind.net>
2
4
  #
3
5
  # This file is part of rubyhexagon.
@@ -14,7 +16,7 @@
14
16
  # You should have received a copy of the GNU General Public License
15
17
  # along with rubyhexagon. If not, see <http://www.gnu.org/licenses/>.
16
18
 
17
- module E621
19
+ module Rubyhexagon
18
20
  # Class to hold level information.
19
21
  #
20
22
  # @api private
@@ -0,0 +1,133 @@
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
+ # This class holds post information, fetched from e621, and gives access in a
21
+ # more Ruby like manner.
22
+ #
23
+ # @author Maxine Michalski
24
+ # @since 1.4.0
25
+ class Pool
26
+ # @return [Integer] returns this pool's ID
27
+ attr_reader :id
28
+
29
+ # @return [String] returns name of current pool
30
+ attr_reader :name
31
+
32
+ # @return [Time] returns creation time
33
+ attr_reader :created_at
34
+
35
+ # @return [Time] returns time of last update
36
+ attr_reader :updated_at
37
+
38
+ # @return [String] returns a description of the current pool
39
+ attr_reader :description
40
+
41
+ # @return [User] returns the user, who has created this pool
42
+ attr_reader :user
43
+
44
+ # @return [Array<Post>] returns an array of posts, that belong to this pool
45
+ attr_reader :posts
46
+
47
+ # @author Maxine Michalski
48
+ #
49
+ # Initializer for Pool objects
50
+ #
51
+ # @param id [Integer] ID of this pool
52
+ #
53
+ # @return the object
54
+ def initialize(id)
55
+ unless id.is_a?(Integer) && id.positive?
56
+ raise InvalidIDError, "ID out of range: #{id}"
57
+ end
58
+ @id = id
59
+ end
60
+
61
+ # @author Maxine Michalski
62
+ #
63
+ # @param pool [Hash] pool data, if present
64
+ #
65
+ # Fetch data from e621 to current post id
66
+ def show!(pool = nil)
67
+ @posts = []
68
+ if pool.nil?
69
+ page = 1
70
+ loop do
71
+ pool = API.new.fetch('pool', 'show', id: @id, page: page)
72
+ page += 1
73
+ @posts += pool[:posts].map do |post|
74
+ E621::Post.new(post[:id]).show(post)
75
+ end
76
+ break if pool[:posts] == []
77
+ end
78
+ end
79
+ @name = pool[:name]
80
+ @created_at = Time.at(pool[:created_at][:s].to_i)
81
+ @updated_at = Time.at(pool[:updated_at][:s].to_i)
82
+ @description = pool[:description]
83
+ @user = User.new(id: pool[:user_id])
84
+ @is_locked = pool[:is_locked]
85
+ @is_active = pool[:is_active]
86
+ end
87
+
88
+ # @author Maxine Michalski
89
+ #
90
+ # @param pool [Hash] pool data, if present
91
+ #
92
+ # Fetch data from e621 to current pool id
93
+ def show(pool = nil)
94
+ tmp = Pool.new(@id)
95
+ tmp.show!(pool)
96
+ tmp
97
+ end
98
+
99
+ # @author Maxine Michalski
100
+ #
101
+ # Returns locking status
102
+ #
103
+ # @return [TrueClass,FalseClass]
104
+ def locked?
105
+ @is_locked
106
+ end
107
+
108
+ # @author Maxine Michalski
109
+ #
110
+ # Returns active status
111
+ #
112
+ # @return [TrueClass,FalseClass]
113
+ def active?
114
+ @is_active
115
+ end
116
+
117
+ # @author Maxine Michalski
118
+ #
119
+ # Comparison method for Pool objects
120
+ #
121
+ # @param other [Object] other object to compare
122
+ #
123
+ # @return [TrueClass,FalseClass]
124
+ def ==(other)
125
+ if @name.nil?
126
+ other.is_a?(Pool) && @id == other.id
127
+ else
128
+ other.is_a?(Pool) && @name == other.name && @id == other.id &&
129
+ @updated_at == other.updated_at
130
+ end
131
+ end
132
+ end
133
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright 2014-2018 Maxine Michalski <maxine@furfind.net>
2
4
  #
3
5
  # This file is part of rubyhexagon.
@@ -14,7 +16,7 @@
14
16
  # You should have received a copy of the GNU General Public License
15
17
  # along with rubyhexagon. If not, see <http://www.gnu.org/licenses/>.
16
18
 
17
- module E621
19
+ module Rubyhexagon
18
20
  # This class holds post information, fetched from e621, and gives access in a
19
21
  # more Ruby like manner.
20
22
  #
@@ -65,13 +67,13 @@ module E621
65
67
  # @return [String] MD5 checksum associated with this post
66
68
  attr_reader :md5
67
69
 
68
- # @return [E621::Image] file content of this post
70
+ # @return [Rubyhexagon::Image] file content of this post
69
71
  attr_reader :image
70
72
 
71
- # @return [E621::Sample] sample data in E621::Sample format
73
+ # @return [Rubyhexagon::Sample] sample data in Rubyhexagon::Sample format
72
74
  attr_reader :sample
73
75
 
74
- # @return [E621::Preview] preview data in E621::Preview format
76
+ # @return [Rubyhexagon::Preview] preview data in Rubyhexagon::Preview format
75
77
  attr_reader :preview
76
78
 
77
79
  # @return [Array<String>] tag names only for convenience
@@ -86,7 +88,7 @@ module E621
86
88
  # @return the object
87
89
  def initialize(id)
88
90
  id = id.to_i
89
- unless id.is_a?(Integer) && id > 0
91
+ unless id.is_a?(Integer) && id.positive?
90
92
  raise InvalidIDError, "ID out of range: #{id}"
91
93
  end
92
94
  @id = id
@@ -113,8 +115,7 @@ module E621
113
115
  #
114
116
  # Fetch data from e621 to current post id
115
117
  def show(post = nil)
116
- post = API.new.fetch('post', 'show', id: @id) if post.nil?
117
- tmp = Post.new(post[:id].to_i)
118
+ tmp = Post.new(@id)
118
119
  tmp.show!(post)
119
120
  tmp
120
121
  end
@@ -169,9 +170,9 @@ module E621
169
170
  def setup_file_data(post)
170
171
  @tag_names = post[:tags].split(/\s+/)
171
172
  @md5 = post[:md5]
172
- @image = E621::Image.new(url: post[:file_url], ext: post[:file_ext],
173
- width: post[:width], height: post[:height],
174
- size: post[:file_size])
173
+ @image = Image.new(url: post[:file_url], ext: post[:file_ext],
174
+ width: post[:width], height: post[:height],
175
+ size: post[:file_size])
175
176
  setup_sample(post)
176
177
  setup_preview(post)
177
178
  end
@@ -180,18 +181,18 @@ module E621
180
181
  #
181
182
  # Helper function, to setup post sample data
182
183
  def setup_sample(post)
183
- @sample = E621::Sample.new(url: post[:sample_url], ext: post[:file_ext],
184
- width: post[:sample_width],
185
- height: post[:sample_height])
184
+ @sample = Sample.new(url: post[:sample_url], ext: post[:file_ext],
185
+ width: post[:sample_width],
186
+ height: post[:sample_height])
186
187
  end
187
188
 
188
189
  # @author Maxine Michalski
189
190
  #
190
191
  # Helper function, to setup post preview data
191
192
  def setup_preview(post)
192
- @preview = E621::Preview.new(url: post[:preview_url], ext: 'jpg',
193
- width: post[:preview_width],
194
- height: post[:preview_height])
193
+ @preview = Preview.new(url: post[:preview_url], ext: 'jpg',
194
+ width: post[:preview_width],
195
+ height: post[:preview_height])
195
196
  end
196
197
 
197
198
  # @author Maxine Michalski
@@ -0,0 +1,62 @@
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
@@ -0,0 +1,62 @@
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright 2014-2018 Maxine Michalski <maxine@furfind.net>
2
4
  #
3
5
  # This file is part of rubyhexagon.
@@ -14,7 +16,7 @@
14
16
  # You should have received a copy of the GNU General Public License
15
17
  # along with rubyhexagon. If not, see <http://www.gnu.org/licenses/>.
16
18
 
17
- module E621
19
+ module Rubyhexagon
18
20
  # Module to hold search classes
19
21
  #
20
22
  # @author Maxine Michalski
@@ -108,7 +110,7 @@ module E621
108
110
  Post.new(data[:id]).show(data)
109
111
  end
110
112
  end
111
- private_class_method :fetch_deleted
113
+ private_class_method :fetch_posts
112
114
  end
113
115
  end
114
116
  end
@@ -0,0 +1,61 @@
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright 2014-2018 Maxine Michalski <maxine@furfind.net>
2
4
  #
3
5
  # This file is part of rubyhexagon.
@@ -14,7 +16,7 @@
14
16
  # You should have received a copy of the GNU General Public License
15
17
  # along with rubyhexagon. If not, see <http://www.gnu.org/licenses/>.
16
18
 
17
- module E621
19
+ module Rubyhexagon
18
20
  # Module to hold search classes
19
21
  #
20
22
  # @author Maxine Michalski
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright 2014-2018 Maxine Michalski <maxine@furfind.net>
2
4
  #
3
5
  # This file is part of rubyhexagon.
@@ -14,7 +16,7 @@
14
16
  # You should have received a copy of the GNU General Public License
15
17
  # along with rubyhexagon. If not, see <http://www.gnu.org/licenses/>.
16
18
 
17
- module E621
19
+ module Rubyhexagon
18
20
  # Class to hold tag information.
19
21
  #
20
22
  # @author Maxine Michalski
@@ -42,7 +44,7 @@ module E621
42
44
  #
43
45
  # @return the object
44
46
  def initialize(id)
45
- unless id.is_a?(Integer) && id > 0
47
+ unless id.is_a?(Integer) && id.positive?
46
48
  raise InvalidIDError, "ID out of range: #{id}"
47
49
  end
48
50
  @id = id
@@ -0,0 +1,69 @@
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
+ # This class holds post information, fetched from e621, and gives access in a
21
+ # more Ruby like manner.
22
+ #
23
+ # @author Maxine Michalski
24
+ # @since 1.4.0
25
+ class TagChange
26
+ # @return [Integer] change ID
27
+ attr_reader :id
28
+
29
+ # @return [Integer] post ID that got updated
30
+ attr_reader :post_id
31
+
32
+ # @return [Time] time of change
33
+ attr_reader :created_at
34
+
35
+ # @return [Array<String>] new tags
36
+ attr_reader :tags
37
+
38
+ # @return [Array<String>] new sources
39
+ attr_reader :sources
40
+
41
+ # @author Maxine Michalski
42
+ #
43
+ # Initializer for TagChange
44
+ #
45
+ # @param post [Hash]
46
+ #
47
+ # @return the object
48
+ def initialize(post)
49
+ post.each do |k, v|
50
+ if k.to_s =~ /id$/
51
+ v = v.to_i
52
+ unless k.to_s.match(/id$/) && v.is_a?(Integer) && v.positive?
53
+ raise InvalidIDError, "ID out of range: #{v}"
54
+ end
55
+ end
56
+ instance_variable_set("@#{k}".to_sym, v)
57
+ end
58
+ end
59
+
60
+ # @author Maxine Michalski
61
+ #
62
+ # Comparison method for tag changes
63
+ #
64
+ # @return [TrueClass, FalseClass]
65
+ def ==(other)
66
+ other.is_a?(TagChange) && @id == other.id
67
+ end
68
+ end
69
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright 2014-2018 Maxine Michalski <maxine@furfind.net>
2
4
  #
3
5
  # This file is part of rubyhexagon.
@@ -14,7 +16,7 @@
14
16
  # You should have received a copy of the GNU General Public License
15
17
  # along with rubyhexagon. If not, see <http://www.gnu.org/licenses/>.
16
18
 
17
- module E621
19
+ module Rubyhexagon
18
20
  # Class to hold type information.
19
21
  #
20
22
  # @api private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright 2014-2018 Maxine Michalski <maxine@furfind.net>
2
4
  #
3
5
  # This file is part of rubyhexagon.
@@ -16,7 +18,7 @@
16
18
 
17
19
  require 'time'
18
20
 
19
- module E621
21
+ module Rubyhexagon
20
22
  # Class to hold user information for users on e621.
21
23
  #
22
24
  # @author Maxine Michalski
@@ -72,7 +74,11 @@ module E621
72
74
  #
73
75
  # @return [TrueClass, FalseClass]
74
76
  def ==(other)
75
- other.is_a?(User) && @id == other.id && @name == other.name
77
+ if @name.nil?
78
+ other.is_a?(User) && @id == other.id
79
+ else
80
+ other.is_a?(User) && @id == other.id && @name == other.name
81
+ end
76
82
  end
77
83
  end
78
84
  end
data/lib/rubyhexagon.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright 2014-2018 Maxine Michalski <maxine@furfind.net>
2
4
  #
3
5
  # This file is part of rubyhexagon.
@@ -29,16 +31,26 @@ require 'rubyhexagon/type'
29
31
  require 'rubyhexagon/image'
30
32
  require 'rubyhexagon/level'
31
33
  require 'rubyhexagon/post'
34
+ require 'rubyhexagon/pool'
35
+ require 'rubyhexagon/tag_change'
32
36
  require 'rubyhexagon/search/posts'
37
+ require 'rubyhexagon/search/pools'
33
38
  require 'rubyhexagon/search/tags'
39
+ require 'rubyhexagon/search/flag_history'
40
+ require 'rubyhexagon/search/tag_history'
34
41
 
35
42
  # Namespace for all classes in this gem.
36
43
  # @author Maxine Michalski
37
44
  # @since 0.4.3
38
- module E621
45
+ module Rubyhexagon
39
46
  MAJOR = 1
40
- MINOR = 3
47
+ MINOR = 4
41
48
  PATCH = 0
42
- NAME = 'rubyhexagon'.freeze
43
- VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}".freeze
49
+ NAME = 'rubyhexagon'
50
+ VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}"
44
51
  end
52
+
53
+ # Compatibility assignment, so that I can move module to a new name and don't
54
+ # break old code.
55
+ # Both module names can be used.
56
+ E621 = Rubyhexagon
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyhexagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxine Michalski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-07 00:00:00.000000000 Z
11
+ date: 2018-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -36,10 +36,15 @@ files:
36
36
  - lib/rubyhexagon/helper/api.rb
37
37
  - lib/rubyhexagon/image.rb
38
38
  - lib/rubyhexagon/level.rb
39
+ - lib/rubyhexagon/pool.rb
39
40
  - lib/rubyhexagon/post.rb
41
+ - lib/rubyhexagon/search/flag_history.rb
42
+ - lib/rubyhexagon/search/pools.rb
40
43
  - lib/rubyhexagon/search/posts.rb
44
+ - lib/rubyhexagon/search/tag_history.rb
41
45
  - lib/rubyhexagon/search/tags.rb
42
46
  - lib/rubyhexagon/tag.rb
47
+ - lib/rubyhexagon/tag_change.rb
43
48
  - lib/rubyhexagon/type.rb
44
49
  - lib/rubyhexagon/user.rb
45
50
  homepage: https://github.com/maxine-red/rubyhexagon
@@ -54,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
59
  requirements:
55
60
  - - "~>"
56
61
  - !ruby/object:Gem::Version
57
- version: '2.1'
62
+ version: '2.3'
58
63
  required_rubygems_version: !ruby/object:Gem::Requirement
59
64
  requirements:
60
65
  - - ">="