From 63b42804543000c2ca88a3b9e7b1ef3f4a66478d Mon Sep 17 00:00:00 2001 From: Jack McCallum Date: Wed, 22 Nov 2017 11:21:04 +1100 Subject: [PATCH 1/4] Add test running rake task --- Rakefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 579ed9e..d33dd63 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,13 @@ require "bundler/gem_tasks" -task :default do +begin + require 'rspec/core/rake_task' + + RSpec::Core::RakeTask.new(:spec) do |t| + t.fail_on_error = false + end + + task :default => :spec +rescue LoadError + # no rspec available end From 69d83ccc7fdd7bcf7282f7fcdd815aadbb7d846c Mon Sep 17 00:00:00 2001 From: Jack McCallum Date: Wed, 22 Nov 2017 11:34:51 +1100 Subject: [PATCH 2/4] Use new v1 api --- lib/cloudsight/request.rb | 16 +++++------ lib/cloudsight/response.rb | 2 +- spec/cloudsight/request_spec.rb | 48 ++++++++++++++++---------------- spec/cloudsight/response_spec.rb | 12 ++++---- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/lib/cloudsight/request.rb b/lib/cloudsight/request.rb index c9d93bd..24f82da 100644 --- a/lib/cloudsight/request.rb +++ b/lib/cloudsight/request.rb @@ -3,7 +3,7 @@ class Request class << self def send(options = {}) raise RuntimeError.new("Need to define either oauth_options or api_key") unless Cloudsight.api_key || Cloudsight.oauth_options - url = "#{Cloudsight::base_url}/image_requests" + url = "#{Cloudsight::base_url}/v1/images" params = construct_params(options) response = Api.post(url, params) @@ -15,7 +15,7 @@ def send(options = {}) end def repost(token, options = {}) - url = "#{Cloudsight::base_url}/image_requests/#{token}/repost" + url = "#{Cloudsight::base_url}/v1/images/#{token}/repost" response = Api.post(url, options) return true if response.code == 200 and response.body.to_s.strip.empty? @@ -29,17 +29,17 @@ def repost(token, options = {}) def construct_params(options) params = {} - [:locale, :language, :latitude, :longitude, :altitude, :device_id, :ttl].each do |attr| - params["image_request[#{attr}]"] = options[attr] if options.has_key?(attr) + [:locale, :language, :latitude, :longitude, :altitude, :device_id, :ttl, :focus_x, :focus_y].each do |attr| + params[attr.to_s] = options[attr] if options.has_key?(attr) end if options[:focus] - params['focus[x]'] = options[:focus][:x] - params['focus[y]'] = options[:focus][:y] + params['focus_x'] = options[:focus][:x] + params['focus_y'] = options[:focus][:y] end - params['image_request[remote_image_url]'] = options[:url] if options.has_key?(:url) - params['image_request[image]'] = options[:file] if options.has_key?(:file) + params['remote_image_url'] = options[:url] if options.has_key?(:url) + params['image'] = options[:file] if options.has_key?(:file) params end end diff --git a/lib/cloudsight/response.rb b/lib/cloudsight/response.rb index f652c7e..c43b950 100644 --- a/lib/cloudsight/response.rb +++ b/lib/cloudsight/response.rb @@ -2,7 +2,7 @@ module Cloudsight class Response class << self def get(token, options = {}) - url = "#{Cloudsight::base_url}/image_responses/#{token}" + url = "#{Cloudsight::base_url}/v1/images/#{token}" response = Api.get(url) data = JSON.parse(response.body) diff --git a/spec/cloudsight/request_spec.rb b/spec/cloudsight/request_spec.rb index ae0df19..038e22e 100644 --- a/spec/cloudsight/request_spec.rb +++ b/spec/cloudsight/request_spec.rb @@ -29,17 +29,17 @@ options = described_class.construct_params(params) expect(options).to eq( { - 'image_request[locale]' => 'en', - 'image_request[language]' => 'en', - 'image_request[latitude]' => '5', - 'image_request[longitude]' => '5', - 'image_request[altitude]' => '5', - 'image_request[device_id]' => '5', - 'image_request[ttl]' => '5', - 'image_request[remote_image_url]' => 'test_url', - 'image_request[image]' => 'test_file', - 'focus[x]' => '5', - 'focus[y]' => '5' + 'locale' => 'en', + 'language' => 'en', + 'latitude' => '5', + 'longitude' => '5', + 'altitude' => '5', + 'device_id' => '5', + 'ttl' => '5', + 'remote_image_url' => 'test_url', + 'image' => 'test_file', + 'focus_x' => '5', + 'focus_y' => '5' } ) end @@ -50,8 +50,8 @@ it 'returns the proper result' do stub_post( - path: '/image_requests', - body: { "image_request"=>{ "locale"=>"en", "remote_image_url"=>"test_url" } }, + path: '/v1/images', + body: { "locale" => "en", "remote_image_url" => "test_url" }, response: fixture_file('image_request.json') ) @@ -64,8 +64,8 @@ it 'responds correctly to a response exception error' do stub_post( - path: '/image_requests', - body: { "image_request"=>{ "locale"=>"en", "remote_image_url"=>"test_url" } }, + path: '/v1/images', + body: { "locale" => "en", "remote_image_url" => "test_url" }, response: fixture_file('error_response.json') ) @@ -74,8 +74,8 @@ it 'responds correctly to an unexpected response' do stub_post( - path: '/image_requests', - body: { "image_request"=>{ "locale"=>"en", "remote_image_url"=>"test_url" } }, + path: '/v1/images', + body: { "locale" => "en", "remote_image_url" => "test_url" }, response: fixture_file('unexpected_response.json') ) @@ -84,12 +84,12 @@ end describe '#repost' do - let(:params) { { image_request: { locale: 'en', remote_image_url: 'test_url' } } } + let(:params) { { locale: 'en', remote_image_url: 'test_url' } } it 'returns the proper result' do stub_post( - path: '/image_requests/sample_token/repost', - body: { "image_request"=>{ "locale"=>"en", "remote_image_url"=>"test_url" } }, + path: '/v1/images/sample_token/repost', + body: { "locale" => "en", "remote_image_url" => "test_url" }, response: fixture_file('image_request.json') ) @@ -102,8 +102,8 @@ it 'responds correctly to a response exception error' do stub_post( - path: '/image_requests/sample_token/repost', - body: { "image_request"=>{ "locale"=>"en", "remote_image_url"=>"test_url" } }, + path: '/v1/images/sample_token/repost', + body: { "locale" => "en", "remote_image_url" => "test_url" }, response: fixture_file('error_response.json') ) @@ -112,8 +112,8 @@ it 'responds correctly to an unexpected response' do stub_post( - path: '/image_requests/sample_token/repost', - body: { "image_request"=>{ "locale"=>"en", "remote_image_url"=>"test_url" } }, + path: '/v1/images/sample_token/repost', + body: { "locale" => "en", "remote_image_url" => "test_url" }, response: fixture_file('unexpected_response.json') ) diff --git a/spec/cloudsight/response_spec.rb b/spec/cloudsight/response_spec.rb index 5209b2e..dc12b1c 100644 --- a/spec/cloudsight/response_spec.rb +++ b/spec/cloudsight/response_spec.rb @@ -8,7 +8,7 @@ describe '#get' do it 'returns the proper result' do stub_get( - path: '/image_responses/sample_token', + path: '/v1/images/sample_token', response: fixture_file('completed_response.json') ) @@ -21,7 +21,7 @@ it 'responds correctly to a response exception error' do stub_get( - path: '/image_responses/sample_token', + path: '/v1/images/sample_token', response: fixture_file('error_response.json') ) @@ -30,7 +30,7 @@ it 'responds correctly to an unexpected response' do stub_get( - path: '/image_responses/sample_token', + path: '/v1/images/sample_token', response: fixture_file('unexpected_response.json') ) @@ -40,7 +40,7 @@ describe '#retrieve' do it 'returns the proper result' do - stub_polling(3, 'image_request.json', 'completed_response.json', '/image_responses/sample_token') + stub_polling(3, 'image_request.json', 'completed_response.json', '/v1/images/sample_token') response = described_class.retrieve('sample_token', poll_wait: 0.01) @@ -50,13 +50,13 @@ end it 'responds correctly to a response exception error' do - stub_polling(3, 'image_request.json', 'error_response.json', '/image_responses/sample_token') + stub_polling(3, 'image_request.json', 'error_response.json', '/v1/images/sample_token') expect { described_class.retrieve('sample_token', poll_wait: 0.01) }.to raise_error Cloudsight::ResponseException end it 'responds correctly to an unexpected response' do - stub_polling(3, 'image_request.json', 'unexpected_response.json', '/image_responses/sample_token') + stub_polling(3, 'image_request.json', 'unexpected_response.json', '/v1/images/sample_token') expect { described_class.retrieve('sample_token', poll_wait: 0.01) }.to raise_error Cloudsight::UnexpectedResponseException end From a582f208a3e69d19b4dacce1075f176f866026fd Mon Sep 17 00:00:00 2001 From: Jack McCallum Date: Wed, 22 Nov 2017 11:42:07 +1100 Subject: [PATCH 3/4] Use snake_case in ruby --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 929985b..67ca257 100644 --- a/README.md +++ b/README.md @@ -51,25 +51,25 @@ Usage Send the image request using a file: ```ruby -requestData = Cloudsight::Request.send(locale: 'en', file: File.open('image.jpg')) +request_data = Cloudsight::Request.send(locale: 'en', file: File.open('image.jpg')) ``` Or, you can send the image request using a URL: ```ruby -requestData = Cloudsight::Request.send(locale: 'en', url: 'http://www.google.com/images/srpr/logo11w.png') +request_data = Cloudsight::Request.send(locale: 'en', url: 'http://www.google.com/images/srpr/logo11w.png') ``` Then, use the token to retrieve the response: ```ruby -responseData = Cloudsight::Response.get(requestData['token']) +response_data = Cloudsight::Response.get(request_data['token']) ``` You can also use the `retrieve` method which will poll for the response for you: ```ruby -Cloudsight::Response.retrieve(requestData['token']) do |responseData| - p responseData +Cloudsight::Response.retrieve(request_data['token']) do |response_data| + p response_data end ``` From 5c9edde4f7636b4c44058c39a85dc2c96e5818c2 Mon Sep 17 00:00:00 2001 From: Jack McCallum Date: Wed, 22 Nov 2017 11:42:57 +1100 Subject: [PATCH 4/4] Version bump --- lib/cloudsight/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cloudsight/version.rb b/lib/cloudsight/version.rb index 79612c3..1b36290 100644 --- a/lib/cloudsight/version.rb +++ b/lib/cloudsight/version.rb @@ -1,3 +1,3 @@ module Cloudsight - VERSION = "0.0.9.1" + VERSION = "0.1.0" end