Class: RandomYiff::E621
- Inherits:
-
Object
show all
- Defined in:
- lib/random_yiff/e621.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize {|_self| ... } ⇒ E621
Returns a new instance of E621.
13
14
15
16
17
|
# File 'lib/random_yiff/e621.rb', line 13
def initialize
@post_uri = self.class.post_uri
@post = JSON.load(Net::HTTP.get(post_uri))
yield self if block_given?
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
35
36
37
|
# File 'lib/random_yiff/e621.rb', line 35
def method_missing(m, *args, &block)
post["#{m}"] || super(m, *args, &block)
end
|
Instance Attribute Details
#post ⇒ Object
Returns the value of attribute post.
11
12
13
|
# File 'lib/random_yiff/e621.rb', line 11
def post
@post
end
|
#post_uri ⇒ Object
Returns the value of attribute post_uri.
11
12
13
|
# File 'lib/random_yiff/e621.rb', line 11
def post_uri
@post_uri
end
|
Class Method Details
.post_uri ⇒ Object
6
7
8
9
|
# File 'lib/random_yiff/e621.rb', line 6
def self.post_uri
res = Net::HTTP.get_response(URI('https://e621.net/post/random'))
URI(res['location'] + '?format=json')
end
|
Instance Method Details
#file ⇒ Object
27
28
29
|
# File 'lib/random_yiff/e621.rb', line 27
def file
Net::HTTP.get(file_uri)
end
|
#file_name ⇒ Object
23
24
25
|
# File 'lib/random_yiff/e621.rb', line 23
def file_name
"#{md5}.#{file_ext}"
end
|
#file_uri ⇒ Object
19
20
21
|
# File 'lib/random_yiff/e621.rb', line 19
def file_uri
URI(file_url)
end
|
#source ⇒ Object
31
32
33
|
# File 'lib/random_yiff/e621.rb', line 31
def source
post['source'] || 'Unknown'
end
|