Class: Rubyhexagon::Post
- Inherits:
-
Object
show all
- Defined in:
- lib/rubyhexagon/post.rb,
lib/rubyhexagon/api/post.rb,
lib/rubyhexagon/post/file.rb,
lib/rubyhexagon/post/score.rb,
lib/rubyhexagon/post/sample.rb,
lib/rubyhexagon/post/preview.rb
Overview
A class to interact with the e621 web interface.
Defined Under Namespace
Classes: File, Preview, Sample, Score
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(post) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/rubyhexagon/post.rb', line 90
def initialize(post)
raise ArgumentError, "#{post.class} is not a Hash" unless post.is_a?(Hash)
raise ArgumentError, 'Not a proper post Hash' if post.key?(:post)
post[:id] = post[:id].to_i
id = post[:id]
raise InvalidIDError, "ID out of range: #{id}" unless id.positive?
post.each do |k, v|
if %i[created_at updated_at file sample preview score flags
rating relationships].include?(k)
__send__("setup_#{k}".to_sym, v)
elsif %i[id tags change_seq sources fav_count description
comment_count is_favorited].include?(k)
instance_variable_set("@#{k}", v)
end
end
end
|
Instance Attribute Details
#approver ⇒ Object
77
78
79
|
# File 'lib/rubyhexagon/post.rb', line 77
def approver
@approver
end
|
#change_seq ⇒ Object
71
72
73
|
# File 'lib/rubyhexagon/post.rb', line 71
def change_seq
@change_seq
end
|
#children ⇒ Object
76
77
78
|
# File 'lib/rubyhexagon/post.rb', line 76
def children
@children
end
|
80
81
82
|
# File 'lib/rubyhexagon/post.rb', line 80
def
@comment_count
end
|
#created_at ⇒ Time
37
38
39
|
# File 'lib/rubyhexagon/post.rb', line 37
def created_at
@created_at
end
|
#description ⇒ Object
79
80
81
|
# File 'lib/rubyhexagon/post.rb', line 79
def description
@description
end
|
#fav_count ⇒ Object
73
74
75
|
# File 'lib/rubyhexagon/post.rb', line 73
def fav_count
@fav_count
end
|
#file ⇒ E621::Post::File
49
50
51
|
# File 'lib/rubyhexagon/post.rb', line 49
def file
@file
end
|
#id ⇒ Integer
31
32
33
|
# File 'lib/rubyhexagon/post.rb', line 31
def id
@id
end
|
70
71
72
|
# File 'lib/rubyhexagon/post.rb', line 70
def locked_tags
@locked_tags
end
|
#parent ⇒ Object
75
76
77
|
# File 'lib/rubyhexagon/post.rb', line 75
def parent
@parent
end
|
#preview ⇒ E621::Post::Preview
55
56
57
|
# File 'lib/rubyhexagon/post.rb', line 55
def preview
@preview
end
|
#rating ⇒ Object
72
73
74
|
# File 'lib/rubyhexagon/post.rb', line 72
def rating
@rating
end
|
#sample ⇒ E621::Post::Sample
61
62
63
|
# File 'lib/rubyhexagon/post.rb', line 61
def sample
@sample
end
|
#score ⇒ E621::Post::Score
67
68
69
|
# File 'lib/rubyhexagon/post.rb', line 67
def score
@score
end
|
#sources ⇒ Object
74
75
76
|
# File 'lib/rubyhexagon/post.rb', line 74
def sources
@sources
end
|
69
70
71
|
# File 'lib/rubyhexagon/post.rb', line 69
def tags
@tags
end
|
#updated_at ⇒ Time
Time post was last updated
43
44
45
|
# File 'lib/rubyhexagon/post.rb', line 43
def updated_at
@updated_at
end
|
#uploader ⇒ Object
78
79
80
|
# File 'lib/rubyhexagon/post.rb', line 78
def uploader
@uploader
end
|
Class Method Details
.list(query) ⇒ Array<E621::Post>
52
53
54
55
56
57
|
# File 'lib/rubyhexagon/api/post.rb', line 52
def self.list(query)
raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash)
E621::API.fetch(:posts, query)[:posts].map do |post|
new(post)
end
end
|
35
36
37
38
39
40
41
42
|
# File 'lib/rubyhexagon/api/post.rb', line 35
def self.show(post)
unless (post.is_a?(Hash) && post[:id].is_a?(Integer)) ||
post.is_a?(E621::Post)
raise ArgumentError, 'A Hash or post data object are required'
end
id = post.is_a?(Hash) ? post[:id] : post.id
new(E621::API.fetch(:posts, id: id)[:post])
end
|
Instance Method Details
#==(other) ⇒ TrueClass, FalseClass
Comparison method for posts
113
114
115
|
# File 'lib/rubyhexagon/post.rb', line 113
def ==(other)
other.is_a?(Post) && @id == other.id
end
|
#active_children? ⇒ Boolean
159
160
161
|
# File 'lib/rubyhexagon/post.rb', line 159
def active_children?
@has_active_children
end
|
#children? ⇒ Boolean
155
156
157
|
# File 'lib/rubyhexagon/post.rb', line 155
def children?
@has_children
end
|
#download(which) ⇒ Tempfile
Download a file from a post
78
79
80
81
82
83
|
# File 'lib/rubyhexagon/api/post.rb', line 78
def download(which)
unless %i[file preview sample].include?(which)
raise ArgumentError, 'Unsupported doanload'
end
E621::API.download(__send__(which).url)
end
|
#explicit? ⇒ Boolean
151
152
153
|
# File 'lib/rubyhexagon/post.rb', line 151
def explicit?
@rating == :explicit
end
|
#favorited? ⇒ Boolean
163
164
165
|
# File 'lib/rubyhexagon/post.rb', line 163
def favorited?
@is_favorited
end
|
#questionable? ⇒ Boolean
147
148
149
|
# File 'lib/rubyhexagon/post.rb', line 147
def questionable?
@rating == :questionable
end
|
#safe? ⇒ Boolean
143
144
145
|
# File 'lib/rubyhexagon/post.rb', line 143
def safe?
@rating == :safe
end
|
67
68
69
|
# File 'lib/rubyhexagon/api/post.rb', line 67
def show
E621::Post.new(E621::API.fetch(:posts, id: @id)[:post])
end
|
#test ⇒ Object
Also known as:
pending?, flagged?, note_locked?, status_locked?, rating_locked?, deleted?
132
133
134
|
# File 'lib/rubyhexagon/post.rb', line 132
def test
instance_variable_get("@#{__callee__.to_s.sub('?', '')}")
end
|
#to_hash ⇒ Hash
Turn object into a hash representation of itself
124
125
126
127
128
129
130
|
# File 'lib/rubyhexagon/post.rb', line 124
def to_hash
hash = {}
instance_variables.each do |i|
hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i))
end
hash
end
|