Class: Morguefile
- Inherits:
-
Object
- Object
- Morguefile
- Defined in:
- lib/morguefile.rb,
lib/morguefile/version.rb
Constant Summary collapse
- VERSION =
"0.1.1"
Class Attribute Summary collapse
-
.key ⇒ Object
Returns the value of attribute key.
-
.secret ⇒ Object
Returns the value of attribute secret.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(key, secret) ⇒ Morguefile
constructor
A new instance of Morguefile.
- #search(term) ⇒ Object
Constructor Details
#initialize(key, secret) ⇒ Morguefile
Returns a new instance of Morguefile.
17 18 19 20 |
# File 'lib/morguefile.rb', line 17 def initialize(key, secret) @key = key @secret = secret end |
Class Attribute Details
.key ⇒ Object
Returns the value of attribute key.
8 9 10 |
# File 'lib/morguefile.rb', line 8 def key @key end |
.secret ⇒ Object
Returns the value of attribute secret.
8 9 10 |
# File 'lib/morguefile.rb', line 8 def secret @secret end |
Class Method Details
.find_image(term) ⇒ Object
11 12 13 14 15 |
# File 'lib/morguefile.rb', line 11 def self.find_image(term) client = new(key || ENV.fetch('MORGUEFILE_KEY'), secret || ENV.fetch('MORGUEFILE_SECRET')) return unless result = client.search(term)['doc'].first result.fetch('file_path_large') end |
Instance Method Details
#search(term) ⇒ Object
22 23 24 25 |
# File 'lib/morguefile.rb', line 22 def search(term) response = get("/image/json?terms=#{CGI.escape(term)}&sort=pop&af=morgueFile") JSON.parse(response) end |