Module: Tiqav
- Defined in:
- lib/tiqav.rb,
lib/tiqav/error.rb,
lib/tiqav/image.rb,
lib/tiqav/search.rb,
lib/tiqav/version.rb,
lib/tiqav/alpha_num.rb
Defined Under Namespace
Classes: AlphaNum, Error, Image
Constant Summary
collapse
- VERSION =
'0.0.6'
Class Method Summary
collapse
Class Method Details
.feeling_lucky(word) ⇒ Object
20
21
22
|
# File 'lib/tiqav/search.rb', line 20
def self.feeling_lucky(word)
Addressable::URI.parse "http://#{word}.tiqav.com/"
end
|
.random ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/tiqav/search.rb', line 12
def self.random
loop do
res = Image.new AlphaNum.encode rand 10000
return res if res.exists?
sleep 1
end
end
|
.search(word) ⇒ Object
3
4
5
6
7
8
9
10
|
# File 'lib/tiqav/search.rb', line 3
def self.search(word)
uri = Addressable::URI.parse "http://api.tiqav.com/search.json?q=#{Addressable::URI.encode word}"
res = Net::HTTP.start(uri.host, uri.port).request(Net::HTTP::Get.new uri.request_uri)
raise Error, "HTTP Status #{res.code} at #{uri}" unless res.code.to_i == 200
JSON.parse(res.body).map{|img|
Tiqav::Image.new img['id'], img['ext']
}
end
|