morguefile 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c6facd27051aad558ba3a3fed4d1c85e0e7ab226
4
+ data.tar.gz: c0f9fb1d66e5f215dad69e47fc220de766a202f7
5
+ SHA512:
6
+ metadata.gz: 920a96ee2732cc55a0185529b64bfe075395f08627ff6035af5a2788a46a0bdad845c1591a2668f66566edd423affa688cb4fc6866a64558fad24c3ce07aad7f
7
+ data.tar.gz: 511c4614eee5b4eb37e7caa5223e353d4d16ad8617c29b952801bb1fa4fb2274fe07458ddd5db0846e28293be454c65d9d551ee8e4b4d71d64afa71f07ef9ea9
@@ -0,0 +1,20 @@
1
+ Copyright (C) 2013 Michael Grosser <michael@grosser.it>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ require 'digest/sha2'
2
+ require 'json'
3
+ require 'openssl'
4
+ require 'open-uri'
5
+
6
+ class Morguefile
7
+ class << self
8
+ attr_accessor :key, :secret
9
+ end
10
+
11
+ def self.find_image(term)
12
+ client = new(key || ENV.fetch('MORGUEFILE_KEY'), secret || ENV.fetch('MORGUEFILE_SECRET'))
13
+ result = client.search(term)
14
+ return unless result = result['doc'] # 404 -> nothing
15
+ result.first.fetch('Archive').fetch('file_path_large')
16
+ end
17
+
18
+ def initialize(key, secret)
19
+ @key = key
20
+ @secret = secret
21
+ end
22
+
23
+ def search(term)
24
+ response = get("/archive/search/1/?q=#{CGI.escape(term)}&sort=pop&photo_lib=morgueFile")
25
+ JSON.parse(response)
26
+ end
27
+
28
+ private
29
+
30
+ def get(path)
31
+ signed = path.split('?').first.split("/").join("")
32
+ signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @key, signed)
33
+ url = "http://www.morguefile.com#{path}&key=#{@key}&sig=#{signature}"
34
+ open(url).read
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ class Morguefile
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: morguefile
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Grosser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email: michael@grosser.it
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - MIT-LICENSE
34
+ - lib/morguefile.rb
35
+ - lib/morguefile/version.rb
36
+ homepage: https://github.com/grosser/morguefile
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.2.2
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Morguefile.com api wrapper
60
+ test_files: []