cloudsight 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eb35b6bfc1b3ad85f8b22fbada36405a301de3a2
4
+ data.tar.gz: 07ad0f0d8a70fd1e07538d75de7f200b2e523ca6
5
+ SHA512:
6
+ metadata.gz: 8ae5d760ea12f5bddaa50a7fc75f79e34d31fb5fcd87ae3146c5ebce675b31e4e32ac58cb8d528137dc0b77f988a7f7d45eca4b4ac0c92a57fba599fde0645f3
7
+ data.tar.gz: d00be6755a458a5ac22a47c3b6dd33770e644a1dfdbe4d75760f9da239980a3ce959818416c7de9d5313f36d29cb74afd8a27c2cd051f45b6db5bf9a86bb1306
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'json'
4
+ gem 'rest-client'
5
+ gem 'simple_oauth'
6
+
@@ -0,0 +1,16 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ json (1.8.1)
5
+ mime-types (2.2)
6
+ rest-client (1.6.7)
7
+ mime-types (>= 1.16)
8
+ simple_oauth (0.2.0)
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ json
15
+ rest-client
16
+ simple_oauth
@@ -0,0 +1,21 @@
1
+ # Copyright (c) 2008 Peter Boling
2
+ # Copyright (c) 2005 Jamis Buck
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ cloudsight-ruby
2
+ ===============
3
+
4
+ A simple CloudSight API Client
5
+
6
+ Installation
7
+ ============
8
+
9
+ ```
10
+ $ gem install cloudsight
11
+ ```
12
+
13
+ Configuration
14
+ =============
15
+
16
+ ```ruby
17
+ require 'rubygems'
18
+ require 'cloudsight'
19
+
20
+ Cloudsight.oauth_options = {
21
+ consumer_key: 'REPLACE WITH YOUR KEY',
22
+ consumer_secret: 'REPLACE WITH YOUR SECRET'
23
+ }
24
+ ```
25
+
26
+ Usage
27
+ =====
28
+
29
+ Send the image request using a file:
30
+
31
+ ```ruby
32
+ requestData = Cloudsight::Request.send(locale: 'en', file: File.open('image.jpg'))
33
+ ```
34
+
35
+ Or, you can send the image request using a URL:
36
+
37
+ ```ruby
38
+ requestData = Cloudsight::Request.send(locale: 'en', url: 'http://www.google.com/images/srpr/logo11w.png')
39
+ ```
40
+
41
+ Then, use the token to retrieve the response:
42
+
43
+ ```ruby
44
+ responseData = Cloudsight::Response.get(requestData['token'])
45
+ ```
46
+
47
+ You can also use the `retrieve` method which will poll for the response for you:
48
+
49
+ ```ruby
50
+ Cloudsight::Response.retrieve(requestData['token']) do |responseData|
51
+ p responseData
52
+ end
53
+ ```
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ $:.unshift File.expand_path('../lib', __FILE__)
4
+ require 'cloudsight/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'cloudsight'
8
+ s.version = Cloudsight::VERSION
9
+ s.date = '2014-11-14'
10
+ s.summary = "CloudSight API Client"
11
+ s.description = "A simple CloudSight API Client for Image Recognition"
12
+ s.authors = ['Brad Folkens']
13
+ s.email = 'brad@cloudsightapi.com'
14
+ s.homepage = 'http://github.com/cloudsight/cloudsight-ruby'
15
+ s.license = 'MIT'
16
+ s.platform = Gem::Platform::RUBY
17
+
18
+ s.files = [
19
+ 'lib/cloudsight.rb',
20
+ 'Gemfile',
21
+ 'Gemfile.lock',
22
+ 'MIT-LICENSE',
23
+ 'README.md',
24
+ 'cloudsight.gemspec'
25
+ ]
26
+ s.require_paths = [%q{lib}]
27
+
28
+ s.required_ruby_version = Gem::Requirement.new('>= 1.9.1')
29
+ s.add_development_dependency 'bundler', '~> 1.6'
30
+ s.add_development_dependency 'rake'
31
+ end
@@ -0,0 +1,92 @@
1
+ require 'rubygems'
2
+ require 'rest-client'
3
+ require 'simple_oauth'
4
+ require 'json'
5
+
6
+ module Cloudsight
7
+ BASE_URL = 'https://api.cloudsightapi.com'
8
+
9
+ class << self
10
+ def oauth_options=(val)
11
+ @@oauth_options = val
12
+
13
+ RestClient.add_before_execution_proc do |req, params|
14
+ if params[:payload]
15
+ filtered_payload = params[:payload].dup
16
+ filtered_payload.delete('image_request[image]')
17
+ end
18
+
19
+ oauth = SimpleOAuth::Header.new(params[:method], params[:url], filtered_payload, oauth_options)
20
+ req.add_field 'Authorization', oauth.to_s
21
+ end
22
+ end
23
+
24
+ def oauth_options
25
+ @@oauth_options
26
+ end
27
+
28
+ def base_url=(val)
29
+ @@base_url = val
30
+ end
31
+
32
+ def base_url
33
+ @@base_url ||= BASE_URL
34
+ end
35
+ end
36
+
37
+ class Request
38
+ def self.send(options = {})
39
+ url = "#{Cloudsight::base_url}/image_requests"
40
+
41
+ params = {}
42
+ [:locale, :language, :latitude, :longitude, :altitude, :device_id, :ttl].each do |attr|
43
+ params["image_request[#{attr}]"] = options[attr] if options.has_key?(attr)
44
+ end
45
+
46
+ if options[:focus]
47
+ params['focus[x]'] = options[:focus][:x]
48
+ params['focus[y]'] = options[:focus][:y]
49
+ end
50
+
51
+ params['image_request[remote_image_url]'] = options[:url] if options.has_key?(:url)
52
+ params['image_request[image]'] = options[:file] if options.has_key?(:file)
53
+
54
+ response = RestClient.post(url, params)
55
+ data = JSON.parse(response.body)
56
+ raise ResponseException.new(data['error']) if data['error']
57
+ raise UnexpectedResponseException.new(response.body) unless data['token']
58
+
59
+ data
60
+ end
61
+ end
62
+
63
+ class Response
64
+ def self.get(token, options = {})
65
+ url = "#{Cloudsight::base_url}/image_responses/#{token}"
66
+
67
+ response = RestClient.get(url)
68
+ data = JSON.parse(response.body)
69
+ raise ResponseException.new(data['error']) if data['error']
70
+ raise UnexpectedResponseException.new(response.body) unless data['status']
71
+
72
+ data
73
+ end
74
+
75
+ def self.retrieve(token, options = {})
76
+ options = { poll_wait: 1 }.merge(options)
77
+
78
+ data = nil
79
+ loop do
80
+ sleep options[:poll_wait]
81
+ data = Cloudsight::Response.get(token, options)
82
+ yield data if block_given?
83
+ break if data['status'] != 'not completed' and data['status'] != 'in progress'
84
+ end
85
+
86
+ data
87
+ end
88
+ end
89
+
90
+ class ResponseException < Exception; end
91
+ class UnexpectedResponseException < Exception; end
92
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloudsight
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Brad Folkens
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-14 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A simple CloudSight API Client for Image Recognition
42
+ email: brad@cloudsightapi.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - Gemfile
48
+ - Gemfile.lock
49
+ - MIT-LICENSE
50
+ - README.md
51
+ - cloudsight.gemspec
52
+ - lib/cloudsight.rb
53
+ homepage: http://github.com/cloudsight/cloudsight-ruby
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - '>='
64
+ - !ruby/object:Gem::Version
65
+ version: 1.9.1
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.2.2
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: CloudSight API Client
77
+ test_files: []