incandescent 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: adf6d6d71b4ab98f3e9caa1b1205fde96046af82
4
+ data.tar.gz: 49ffd1432e97c06ebe0c3ad7f7bbfe63e0b2db96
5
+ SHA512:
6
+ metadata.gz: 4f964e97e97609c3e140d3601d684fff8b67e74a3cb5824bb4190522fb71875c9af2a4a02ab4be3f20a082e4c710a8e56e04e0c454544268c3309c3ca47e261e
7
+ data.tar.gz: b02d79b0388ae3dbb8b6bf4b4d82ad19103b0f046d95716228dfe2a87053a2a532cca16a2425ca86e33079f9d79fe9d533274a679f97310b19bdcf3060ed060d
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in incandescent.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ incandescent (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ faraday (0.13.1)
11
+ multipart-post (>= 1.2, < 3)
12
+ json (2.1.0)
13
+ multipart-post (2.0.0)
14
+ rake (10.5.0)
15
+ rspec (3.7.0)
16
+ rspec-core (~> 3.7.0)
17
+ rspec-expectations (~> 3.7.0)
18
+ rspec-mocks (~> 3.7.0)
19
+ rspec-core (3.7.0)
20
+ rspec-support (~> 3.7.0)
21
+ rspec-expectations (3.7.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.7.0)
24
+ rspec-mocks (3.7.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.7.0)
27
+ rspec-support (3.7.0)
28
+ vcr (4.0.0)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 1.16)
35
+ faraday (~> 0.13)
36
+ incandescent!
37
+ json (~> 2.1)
38
+ rake (~> 10.0)
39
+ rspec (~> 3.7)
40
+ vcr (~> 4)
41
+
42
+ BUNDLED WITH
43
+ 1.16.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Todd Gehman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Incandescent
2
+
3
+ Ruby wrapper for reverse image search via the [Incadescent API](http://incandescent.xyz/)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'incandescent'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install incandescent
20
+
21
+ ## Usage
22
+
23
+ client = Client.new(uid, api_key)
24
+ client.add_image_url('http://example.com/image.jpg')
25
+ client.initiate_search
26
+
27
+ hosts = client.get_results
28
+ hosts.each do |host|
29
+ host.name # pinterest.com
30
+ host.pags.each do |page|
31
+ page.page
32
+ page.source
33
+ page.date
34
+ page.usage_image
35
+ page.usage_height
36
+ page.usage_width
37
+ page.image
38
+ page.iid
39
+ end
40
+ end
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pugetive/incandescent.
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "incandescent"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,40 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "incandescent/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "incandescent"
8
+ spec.version = Incandescent::VERSION
9
+ spec.authors = ["Todd Gehman"]
10
+ spec.email = ["toddgehman@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby wrapper for the IncandescentAPI}
13
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = "https://github.com/pugetive/incandescent"
15
+ spec.license = "MIT"
16
+
17
+ # # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "faraday", "~> 0.13"
36
+ spec.add_development_dependency "json", "~> 2.1"
37
+ spec.add_development_dependency "rspec", "~> 3.7"
38
+ spec.add_development_dependency "vcr", "~> 4"
39
+
40
+ end
@@ -0,0 +1,48 @@
1
+ module Incandescent
2
+
3
+ class Client
4
+ attr_reader :uid, :api_key, :image_urls, :project_id
5
+
6
+ def initialize(uid, api_key)
7
+ @uid = uid
8
+ @api_key = api_key
9
+ @image_urls = []
10
+ @project_id = nil
11
+ end
12
+
13
+ def add_image_url(url)
14
+ image_urls << url
15
+ end
16
+
17
+ def initiate_search
18
+ if image_urls.empty?
19
+ raise Incandescent::Error, "Cannot initiate search before adding images to the queue."
20
+ end
21
+ handle_add_response(Incandescent::ServiceCall.new(:add, images: image_urls, multiple: 3).results)
22
+ end
23
+
24
+ def get_results
25
+ handle_get_response(Incandescent::ServiceCall.new(:get, project_id: project_id).results)
26
+ end
27
+
28
+ private
29
+
30
+ def handle_add_response(results)
31
+ if JSON.parse(results.body)["project_id"]
32
+ @project_id = JSON.parse(results.body)["project_id"]
33
+ else
34
+ raise Incandescent::Error, "Failed to capture project_id from Incandescent API"
35
+ end
36
+ end
37
+
38
+ def handle_get_response(results)
39
+ hosts = []
40
+ JSON.parse(results.body).each do |host_json|
41
+ hosts << Incandescent::Host.new(host_json)
42
+ end
43
+ hosts
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,4 @@
1
+ module Incandescent
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ module Incandescent
2
+ class Host
3
+ attr_reader :pages
4
+ def initialize(json_info)
5
+ @name = json_info.shift
6
+ @pages = []
7
+ json_info.first["pages"].each do |page_info|
8
+ @pages << Incandescent::Page.new(page_info)
9
+ end
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,18 @@
1
+ module Incandescent
2
+ class Page
3
+ attr_reader :page, :source, :date, :usage_image, :usage_height, :usage_width, :image, :iid
4
+
5
+ def initialize(json_info)
6
+ index, page_info = json_info
7
+
8
+ @page = page_info["page"]
9
+ @source = page_info["source"]
10
+ @date = page_info["date"]
11
+ @usage_image = page_info["usage-image"]
12
+ @usage_height = page_info["usage-height"]
13
+ @usage_width = page_info["usage-width"]
14
+ @image = page_info["image"]
15
+ @iid = page_info["id"]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,42 @@
1
+ require 'digest'
2
+
3
+ module Incandescent
4
+ class ServiceCall
5
+ ENDPOINT = 'https://incandescent.xyz/'
6
+
7
+ attr_reader :payload, :method_path, :connection
8
+
9
+ def initialize(method_path, params)
10
+ @connection = Faraday.new(url: ENDPOINT)
11
+ @method_path = method_path
12
+
13
+ expire_time = Time.now.to_i + 60*15
14
+
15
+ @payload = {uid: ENV['INCANDESCENT_UID'],
16
+ auth: auth_token(expire_time),
17
+ expires: expire_time}
18
+ @payload.merge!(params)
19
+ end
20
+
21
+ def results
22
+ make_post_request(method_path, payload)
23
+ end
24
+
25
+ private
26
+
27
+ def make_post_request(method, params)
28
+ connection.post do |req|
29
+ req.url "/api/#{method_path}/"
30
+ req.headers['Content-Type'] = 'application/json'
31
+ req.body = payload.to_json
32
+ end
33
+ end
34
+
35
+
36
+ # MD5 hash of your uid, the expires parameter, and your API Key
37
+ # $uid."-".$expires."-".$apikey;
38
+ def auth_token(expire_time)
39
+ Digest::MD5.hexdigest("#{ENV['INCANDESCENT_UID']}-#{expire_time}-#{ENV['INCANDESCENT_API_KEY']}")
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,4 @@
1
+ module Incandescent
2
+ VERSION = "0.1.1"
3
+
4
+ end
@@ -0,0 +1,11 @@
1
+ require "incandescent/version"
2
+
3
+ require "incandescent/client"
4
+ require "incandescent/error"
5
+ require "incandescent/host"
6
+ require "incandescent/page"
7
+ require "incandescent/service_call"
8
+
9
+ module Incandescent
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: incandescent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Todd Gehman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4'
97
+ description:
98
+ email:
99
+ - toddgehman@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - incandescent.gemspec
114
+ - lib/incandescent.rb
115
+ - lib/incandescent/client.rb
116
+ - lib/incandescent/error.rb
117
+ - lib/incandescent/host.rb
118
+ - lib/incandescent/page.rb
119
+ - lib/incandescent/service_call.rb
120
+ - lib/incandescent/version.rb
121
+ homepage: https://github.com/pugetive/incandescent
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.5.1
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Ruby wrapper for the IncandescentAPI
145
+ test_files: []