Class: Shinybooru::Booru
- Inherits:
-
Object
- Object
- Shinybooru::Booru
- Defined in:
- lib/shinybooru.rb
Instance Attribute Summary collapse
-
#online ⇒ Object
Returns the value of attribute online.
Instance Method Summary collapse
- #booru_get(page) ⇒ Object
- #checkConnection ⇒ Object
- #errors ⇒ Object
-
#initialize ⇒ Booru
constructor
A new instance of Booru.
- #posts(args = Hash.new) ⇒ Object
Constructor Details
#initialize ⇒ Booru
Returns a new instance of Booru.
9 10 11 12 |
# File 'lib/shinybooru.rb', line 9 def initialize @booru = HTTP::Requestor.new "gelbooru.com" checkConnection end |
Instance Attribute Details
#online ⇒ Object
Returns the value of attribute online.
7 8 9 |
# File 'lib/shinybooru.rb', line 7 def online @online end |
Instance Method Details
#booru_get(page) ⇒ Object
27 28 29 |
# File 'lib/shinybooru.rb', line 27 def booru_get (page) @booru.get '/index.php?page=dapi&s=post&q=index' + page end |
#checkConnection ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/shinybooru.rb', line 14 def checkConnection conn = @booru.get 'index.php' if conn @online = true end rescue TimeoutError @online = false end |
#errors ⇒ Object
23 24 25 |
# File 'lib/shinybooru.rb', line 23 def errors !@online end |
#posts(args = Hash.new) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/shinybooru.rb', line 31 def posts (args=Hash.new) limit = args[:limit] limit = 1 if limit.nil? nsfw = args[:nsfw] nsfw = true if nsfw.nil? = args[:tags] = [] if .nil? if @online req = '&limit=' + limit.to_s if unless .is_a? String = .join('%20') end req += '&tags=' + end unless nsfw = '-rating%3aquestionable%20-rating%3explicit' unless req += '&tags=' + else req += '%20' + end end data = Nokogiri::Slop((booru_get req).body) posts = [] data.posts.children.each do |post| if post.is_a? Nokogiri::XML::Element posts.push Shinybooru::Post.new(post) end end if posts.length > 1 posts else posts[0] end else raise Shinybooru::OfflineError end end |