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
@@ -23,53 +23,57 @@ module Rubyhexagon
|
|
23
23
|
#
|
24
24
|
# @api private
|
25
25
|
# @author Maxine Michalski
|
26
|
-
# @since
|
27
|
-
class
|
28
|
-
#
|
29
|
-
# @return [URI] url of file
|
26
|
+
# @since 3.0.0
|
27
|
+
class File
|
28
|
+
# File url
|
29
|
+
# @return [URI] url of file or nil
|
30
30
|
attr_reader :url
|
31
31
|
|
32
|
-
#
|
32
|
+
# File file extension
|
33
33
|
# @return [String] extension of file
|
34
34
|
attr_reader :ext
|
35
35
|
|
36
|
-
#
|
36
|
+
# File width
|
37
37
|
# @return [Integer] image/video width
|
38
38
|
attr_reader :width
|
39
39
|
|
40
|
-
#
|
40
|
+
# File height
|
41
41
|
# @return [Integer] image/video height
|
42
42
|
attr_reader :height
|
43
43
|
|
44
|
-
#
|
44
|
+
# File size
|
45
45
|
# @return [Integer] file size in bytes
|
46
46
|
attr_reader :size
|
47
47
|
|
48
|
+
# File MD5 hash string
|
49
|
+
# @return [String] MD5 hash
|
50
|
+
attr_reader :md5
|
51
|
+
|
48
52
|
# @author Maxine Michalski
|
49
53
|
#
|
50
|
-
# Initializer for an
|
54
|
+
# Initializer for an File
|
51
55
|
#
|
52
|
-
# @param image [Hash]
|
56
|
+
# @param image [Hash] file information
|
53
57
|
# @option image [String] :url URI location
|
54
58
|
# @option image [String] :ext extension string
|
55
|
-
# @option image [Integer] :width of
|
56
|
-
# @option image [Integer] :height of
|
57
|
-
# @option image [Integer] :size of
|
59
|
+
# @option image [Integer] :width of file
|
60
|
+
# @option image [Integer] :height of file
|
61
|
+
# @option image [Integer] :size of file
|
62
|
+
# @option image [String] :md5 of file
|
58
63
|
#
|
59
64
|
# @return the object
|
60
|
-
def initialize(
|
61
|
-
unless
|
62
|
-
raise ArgumentError, "#{
|
65
|
+
def initialize(file)
|
66
|
+
unless file.is_a?(Hash)
|
67
|
+
raise ArgumentError, "#{file.class} is not a Hash"
|
63
68
|
end
|
64
|
-
|
65
|
-
|
66
|
-
raise ArgumentError, "Missing key#{mis.count > 1 ? 's' : ''}: #{mis}"
|
69
|
+
unless file.keys.sort == %i[ext height md5 size url width]
|
70
|
+
raise ArgumentError, 'Missing keys in file Hash.'
|
67
71
|
end
|
68
|
-
|
69
|
-
if %i[
|
72
|
+
file.each do |k, v|
|
73
|
+
if %i[width height ext size md5].include?(k)
|
70
74
|
instance_variable_set("@#{k}".to_sym, v)
|
71
75
|
elsif k == :url
|
72
|
-
@url = URI.parse(v)
|
76
|
+
@url = v.nil? ? nil : URI.parse(v)
|
73
77
|
end
|
74
78
|
end
|
75
79
|
end
|
@@ -94,20 +98,21 @@ module Rubyhexagon
|
|
94
98
|
|
95
99
|
# @author Maxine Michalski
|
96
100
|
#
|
97
|
-
# Comparison method to comapre two
|
101
|
+
# Comparison method to comapre two File objects (and sub class objects)
|
98
102
|
#
|
99
103
|
# @example Compare two notes, that are unequal
|
100
104
|
# Note.new(id: 1) == Note.new(id: 2) #=> false
|
101
105
|
# @return [TrueClass, FalseClass]
|
102
106
|
def ==(other)
|
103
|
-
other.is_a?(
|
107
|
+
other.is_a?(File) && @md5 == other.md5 && @url == other.url &&
|
108
|
+
@size == other.size
|
104
109
|
end
|
105
110
|
|
106
111
|
# @author Maxine Michalski
|
107
112
|
#
|
108
113
|
# Turn object into a hash representation of itself
|
109
114
|
#
|
110
|
-
# @example Turn an
|
115
|
+
# @example Turn an File into a Hash
|
111
116
|
# Note.new(id: 1).to_hash #=> { id: 1 }
|
112
117
|
# @return [Hash]
|
113
118
|
def to_hash
|
@@ -118,19 +123,5 @@ module Rubyhexagon
|
|
118
123
|
hash
|
119
124
|
end
|
120
125
|
end
|
121
|
-
|
122
|
-
# class for samples, that is just a copy of Image
|
123
|
-
#
|
124
|
-
# @api private
|
125
|
-
# @author Maxine Michalski
|
126
|
-
# @since 1.0,0
|
127
|
-
class Sample < Image; end
|
128
|
-
|
129
|
-
# class for previews, that is just a copy of Image
|
130
|
-
#
|
131
|
-
# @api private
|
132
|
-
# @author Maxine Michalski
|
133
|
-
# @since 1.0,0
|
134
|
-
class Preview < Image; end
|
135
126
|
end
|
136
127
|
end
|
@@ -18,26 +18,36 @@
|
|
18
18
|
|
19
19
|
module Rubyhexagon
|
20
20
|
class Post
|
21
|
-
#
|
21
|
+
# Class for post preview data. This is mostly an abstraction to have data
|
22
|
+
# structures in a more Ruby like nature.
|
22
23
|
#
|
24
|
+
# @api private
|
23
25
|
# @author Maxine Michalski
|
24
|
-
# @
|
25
|
-
|
26
|
-
class Flag
|
26
|
+
# @since 3.0.0
|
27
|
+
class Preview < File
|
27
28
|
# @author Maxine Michalski
|
28
29
|
#
|
29
|
-
#
|
30
|
+
# Initializer for an Preview
|
30
31
|
#
|
31
|
-
# @
|
32
|
-
#
|
33
|
-
# @
|
34
|
-
# @
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
# @param image [Hash] preview information
|
33
|
+
# @option image [String] :url URI location
|
34
|
+
# @option image [Integer] :width of preview
|
35
|
+
# @option image [Integer] :height of preview
|
36
|
+
#
|
37
|
+
# @return the object
|
38
|
+
def initialize(preview)
|
39
|
+
unless preview.is_a?(Hash)
|
40
|
+
raise ArgumentError, "#{preview.class} is not a Hash"
|
41
|
+
end
|
42
|
+
unless preview.keys.sort == %i[height url width]
|
43
|
+
raise ArgumentError, 'Missing keys in preview Hash.'
|
38
44
|
end
|
39
|
-
|
40
|
-
|
45
|
+
preview.each do |k, v|
|
46
|
+
if %i[width height].include?(k)
|
47
|
+
instance_variable_set("@#{k}".to_sym, v)
|
48
|
+
elsif k == :url
|
49
|
+
@url = v.nil? ? nil : URI.parse(v)
|
50
|
+
end
|
41
51
|
end
|
42
52
|
end
|
43
53
|
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
|
+
class Post
|
21
|
+
# Class for post preview data. This is mostly an abstraction to have data
|
22
|
+
# structures in a more Ruby like nature.
|
23
|
+
#
|
24
|
+
# @api private
|
25
|
+
# @author Maxine Michalski
|
26
|
+
# @since 3.0.0
|
27
|
+
class Sample < File
|
28
|
+
# @author Maxine Michalski
|
29
|
+
#
|
30
|
+
# Initializer for an Sample
|
31
|
+
#
|
32
|
+
# @param image [Hash] preview information
|
33
|
+
# @option image [String] :url URI location
|
34
|
+
# @option image [Integer] :width of sample
|
35
|
+
# @option image [Integer] :height of sample
|
36
|
+
# @option image [TrueClass|FalseClass] :has
|
37
|
+
#
|
38
|
+
# @return the object
|
39
|
+
def initialize(sample)
|
40
|
+
unless sample.is_a?(Hash)
|
41
|
+
raise ArgumentError, "#{sample.class} is not a Hash"
|
42
|
+
end
|
43
|
+
unless sample.keys.sort == %i[has height url width]
|
44
|
+
raise ArgumentError, 'Missing keys in sample Hash.'
|
45
|
+
end
|
46
|
+
sample.each do |k, v|
|
47
|
+
if %i[width height has].include?(k)
|
48
|
+
instance_variable_set("@#{k}".to_sym, v)
|
49
|
+
elsif k == :url
|
50
|
+
@url = v.nil? ? nil : URI.parse(v)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# @author Maxine Michalski
|
56
|
+
#
|
57
|
+
# Show if post has a sample or not.
|
58
|
+
#
|
59
|
+
# @return [TrueClass|FalseClass]
|
60
|
+
def exist?
|
61
|
+
@has
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -18,28 +18,43 @@
|
|
18
18
|
|
19
19
|
module Rubyhexagon
|
20
20
|
class Post
|
21
|
-
#
|
21
|
+
# Class for post file data. This is mostly an abstraction to have data
|
22
|
+
# structures in a more Ruby like nature.
|
22
23
|
#
|
24
|
+
# @api private
|
23
25
|
# @author Maxine Michalski
|
24
|
-
# @
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
def self.list(query)
|
36
|
-
unless query.is_a?(Hash)
|
37
|
-
raise ArgumentError, 'A Hash or Post object is required'
|
26
|
+
# @since 3.0.0
|
27
|
+
class Score
|
28
|
+
|
29
|
+
attr_reader :up
|
30
|
+
attr_reader :down
|
31
|
+
attr_reader :total
|
32
|
+
|
33
|
+
def initialize(score)
|
34
|
+
raise ArgumentError, 'Hash required' unless score.is_a?(Hash)
|
35
|
+
unless score.keys.sort == %i[down total up]
|
36
|
+
raise ArgumentError, 'Missing Hash keys.'
|
38
37
|
end
|
39
|
-
|
40
|
-
|
38
|
+
score.each do |k, v|
|
39
|
+
instance_variable_set("@#{k}".to_sym, v)
|
41
40
|
end
|
42
41
|
end
|
42
|
+
|
43
|
+
def to_i
|
44
|
+
@total
|
45
|
+
end
|
46
|
+
|
47
|
+
def positive?
|
48
|
+
@total.positive?
|
49
|
+
end
|
50
|
+
|
51
|
+
def negative?
|
52
|
+
@total.negative?
|
53
|
+
end
|
54
|
+
|
55
|
+
def zero?
|
56
|
+
@total.zero?
|
57
|
+
end
|
43
58
|
end
|
44
59
|
end
|
45
60
|
end
|
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:
|
4
|
+
version: 3.0.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: 2020-
|
11
|
+
date: 2020-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -32,31 +32,13 @@ extra_rdoc_files: []
|
|
32
32
|
files:
|
33
33
|
- lib/rubyhexagon.rb
|
34
34
|
- lib/rubyhexagon/api.rb
|
35
|
-
- lib/rubyhexagon/api/artist.rb
|
36
|
-
- lib/rubyhexagon/api/pool.rb
|
37
35
|
- lib/rubyhexagon/api/post.rb
|
38
|
-
- lib/rubyhexagon/api/post/flag.rb
|
39
|
-
- lib/rubyhexagon/api/post/note.rb
|
40
|
-
- lib/rubyhexagon/api/post/tag_item.rb
|
41
|
-
- lib/rubyhexagon/api/tag.rb
|
42
|
-
- lib/rubyhexagon/api/tag/alias.rb
|
43
|
-
- lib/rubyhexagon/api/tag/implication.rb
|
44
|
-
- lib/rubyhexagon/api/user.rb
|
45
|
-
- lib/rubyhexagon/artist.rb
|
46
36
|
- lib/rubyhexagon/error.rb
|
47
|
-
- lib/rubyhexagon/pool.rb
|
48
37
|
- lib/rubyhexagon/post.rb
|
49
|
-
- lib/rubyhexagon/post/
|
50
|
-
- lib/rubyhexagon/post/
|
51
|
-
- lib/rubyhexagon/post/
|
52
|
-
- lib/rubyhexagon/post/
|
53
|
-
- lib/rubyhexagon/search/posts.rb
|
54
|
-
- lib/rubyhexagon/tag.rb
|
55
|
-
- lib/rubyhexagon/tag/alias.rb
|
56
|
-
- lib/rubyhexagon/tag/implication.rb
|
57
|
-
- lib/rubyhexagon/tag/type.rb
|
58
|
-
- lib/rubyhexagon/user.rb
|
59
|
-
- lib/rubyhexagon/user/level.rb
|
38
|
+
- lib/rubyhexagon/post/file.rb
|
39
|
+
- lib/rubyhexagon/post/preview.rb
|
40
|
+
- lib/rubyhexagon/post/sample.rb
|
41
|
+
- lib/rubyhexagon/post/score.rb
|
60
42
|
homepage: https://github.com/maxine-red/rubyhexagon
|
61
43
|
licenses:
|
62
44
|
- GPL-3.0
|
@@ -76,8 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
58
|
- !ruby/object:Gem::Version
|
77
59
|
version: '0'
|
78
60
|
requirements: []
|
79
|
-
|
80
|
-
rubygems_version: 2.5.2.1
|
61
|
+
rubygems_version: 3.1.2
|
81
62
|
signing_key:
|
82
63
|
specification_version: 4
|
83
64
|
summary: Rubyhexagon, Ruby bindings for e621.
|
@@ -1,42 +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 2.0.0
|
25
|
-
class Artist
|
26
|
-
# @author Maxine Michalski
|
27
|
-
#
|
28
|
-
# Fetch a list of artists
|
29
|
-
#
|
30
|
-
# @param query [Hsah] Query for fetching artist data
|
31
|
-
# @example Get list of artists
|
32
|
-
# E621::Artist.list(name: 'artist') #=> Array<E621::Artist>
|
33
|
-
# @return [Array<E621::Artist>]
|
34
|
-
# @see https://e621.net/help/show/api#artists
|
35
|
-
def self.list(query)
|
36
|
-
raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash)
|
37
|
-
E621::API.fetch(:artist, :index, query).map do |artist|
|
38
|
-
new(artist)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
data/lib/rubyhexagon/api/pool.rb
DELETED
@@ -1,80 +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 Pool
|
26
|
-
# @author Maxine Michalski
|
27
|
-
#
|
28
|
-
# Fetch pool information
|
29
|
-
#
|
30
|
-
# @param pool [E621::Pool|Hash] A pool or hash to fetch data for
|
31
|
-
# @param page [Hash]
|
32
|
-
# @example Get pool information
|
33
|
-
# E621::Pool.show(id: 1, page: 1) #=> E621::Pool
|
34
|
-
# @return [E621::Pool]
|
35
|
-
# @see https://e621.net/help/show/api#pools
|
36
|
-
def self.show(pool, page = nil)
|
37
|
-
unless (pool.is_a?(Hash) && pool[:id].is_a?(Integer)) ||
|
38
|
-
pool.is_a?(E621::Pool)
|
39
|
-
raise ArgumentError, 'A Hash or pool object are required'
|
40
|
-
end
|
41
|
-
id = pool.is_a?(Hash) ? pool[:id] : pool.id
|
42
|
-
page = page.nil? ? pool[:page] : page[:page]
|
43
|
-
E621::API.fetch(:pool, :show, id: id, page: page)[:posts].map do |post|
|
44
|
-
E621::Post.new(post)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# @author Maxine Michalski
|
49
|
-
#
|
50
|
-
# Fetch a list of pools
|
51
|
-
#
|
52
|
-
# @param query [Hsah] Query for fetching pool data
|
53
|
-
# @example Get list of pools
|
54
|
-
# E621::Pool.list(name: 'moo', page: 1) #=> Array<E621::Pool>
|
55
|
-
# @return [Array<E621::Pool>]
|
56
|
-
# @see https://e621.net/help/show/api#pools
|
57
|
-
def self.list(query)
|
58
|
-
raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash)
|
59
|
-
E621::API.fetch(:pool, :index, query).map do |pool|
|
60
|
-
new(pool)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
# @author Maxine Michalski
|
65
|
-
#
|
66
|
-
# Fetch pool information
|
67
|
-
#
|
68
|
-
# @param page [Hash]
|
69
|
-
# @example Get pool information
|
70
|
-
# poolshow(page: 1) #=> E621::Pool
|
71
|
-
# @return [E621::Pool]
|
72
|
-
# @see https://e621.net/help/show/api#pools
|
73
|
-
def show(page)
|
74
|
-
page = page[:page]
|
75
|
-
E621::API.fetch(:pool, :show, id: @id, page: page)[:posts].map do |post|
|
76
|
-
E621::Post.new(post)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|