Skip to content

Commit

Permalink
Use new v1 api
Browse files Browse the repository at this point in the history
  • Loading branch information
mccallumjack committed Nov 22, 2017
1 parent 63b4280 commit 69d83cc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
16 changes: 8 additions & 8 deletions lib/cloudsight/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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?
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/cloudsight/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
48 changes: 24 additions & 24 deletions spec/cloudsight/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
)

Expand All @@ -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')
)

Expand All @@ -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')
)

Expand All @@ -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')
)

Expand All @@ -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')
)

Expand All @@ -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')
)

Expand Down
12 changes: 6 additions & 6 deletions spec/cloudsight/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
)

Expand All @@ -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')
)

Expand All @@ -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')
)

Expand All @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit 69d83cc

Please sign in to comment.