Skip to content

Commit ed6940a

Browse files
authored
Merge pull request #8 from cloudsight/use-v1-api
Use v1 api
2 parents cdee965 + 5c9edde commit ed6940a

File tree

7 files changed

+55
-46
lines changed

7 files changed

+55
-46
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,25 @@ Usage
5151
Send the image request using a file:
5252

5353
```ruby
54-
requestData = Cloudsight::Request.send(locale: 'en', file: File.open('image.jpg'))
54+
request_data = Cloudsight::Request.send(locale: 'en', file: File.open('image.jpg'))
5555
```
5656

5757
Or, you can send the image request using a URL:
5858

5959
```ruby
60-
requestData = Cloudsight::Request.send(locale: 'en', url: 'http://www.google.com/images/srpr/logo11w.png')
60+
request_data = Cloudsight::Request.send(locale: 'en', url: 'http://www.google.com/images/srpr/logo11w.png')
6161
```
6262

6363
Then, use the token to retrieve the response:
6464

6565
```ruby
66-
responseData = Cloudsight::Response.get(requestData['token'])
66+
response_data = Cloudsight::Response.get(request_data['token'])
6767
```
6868

6969
You can also use the `retrieve` method which will poll for the response for you:
7070

7171
```ruby
72-
Cloudsight::Response.retrieve(requestData['token']) do |responseData|
73-
p responseData
72+
Cloudsight::Response.retrieve(request_data['token']) do |response_data|
73+
p response_data
7474
end
7575
```

Rakefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
require "bundler/gem_tasks"
22

3-
task :default do
3+
begin
4+
require 'rspec/core/rake_task'
5+
6+
RSpec::Core::RakeTask.new(:spec) do |t|
7+
t.fail_on_error = false
8+
end
9+
10+
task :default => :spec
11+
rescue LoadError
12+
# no rspec available
413
end

lib/cloudsight/request.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class Request
33
class << self
44
def send(options = {})
55
raise RuntimeError.new("Need to define either oauth_options or api_key") unless Cloudsight.api_key || Cloudsight.oauth_options
6-
url = "#{Cloudsight::base_url}/image_requests"
6+
url = "#{Cloudsight::base_url}/v1/images"
77

88
params = construct_params(options)
99
response = Api.post(url, params)
@@ -15,7 +15,7 @@ def send(options = {})
1515
end
1616

1717
def repost(token, options = {})
18-
url = "#{Cloudsight::base_url}/image_requests/#{token}/repost"
18+
url = "#{Cloudsight::base_url}/v1/images/#{token}/repost"
1919

2020
response = Api.post(url, options)
2121
return true if response.code == 200 and response.body.to_s.strip.empty?
@@ -29,17 +29,17 @@ def repost(token, options = {})
2929

3030
def construct_params(options)
3131
params = {}
32-
[:locale, :language, :latitude, :longitude, :altitude, :device_id, :ttl].each do |attr|
33-
params["image_request[#{attr}]"] = options[attr] if options.has_key?(attr)
32+
[:locale, :language, :latitude, :longitude, :altitude, :device_id, :ttl, :focus_x, :focus_y].each do |attr|
33+
params[attr.to_s] = options[attr] if options.has_key?(attr)
3434
end
3535

3636
if options[:focus]
37-
params['focus[x]'] = options[:focus][:x]
38-
params['focus[y]'] = options[:focus][:y]
37+
params['focus_x'] = options[:focus][:x]
38+
params['focus_y'] = options[:focus][:y]
3939
end
4040

41-
params['image_request[remote_image_url]'] = options[:url] if options.has_key?(:url)
42-
params['image_request[image]'] = options[:file] if options.has_key?(:file)
41+
params['remote_image_url'] = options[:url] if options.has_key?(:url)
42+
params['image'] = options[:file] if options.has_key?(:file)
4343
params
4444
end
4545
end

lib/cloudsight/response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Cloudsight
22
class Response
33
class << self
44
def get(token, options = {})
5-
url = "#{Cloudsight::base_url}/image_responses/#{token}"
5+
url = "#{Cloudsight::base_url}/v1/images/#{token}"
66

77
response = Api.get(url)
88
data = JSON.parse(response.body)

lib/cloudsight/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Cloudsight
2-
VERSION = "0.0.9.1"
2+
VERSION = "0.1.0"
33
end

spec/cloudsight/request_spec.rb

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@
2929
options = described_class.construct_params(params)
3030
expect(options).to eq(
3131
{
32-
'image_request[locale]' => 'en',
33-
'image_request[language]' => 'en',
34-
'image_request[latitude]' => '5',
35-
'image_request[longitude]' => '5',
36-
'image_request[altitude]' => '5',
37-
'image_request[device_id]' => '5',
38-
'image_request[ttl]' => '5',
39-
'image_request[remote_image_url]' => 'test_url',
40-
'image_request[image]' => 'test_file',
41-
'focus[x]' => '5',
42-
'focus[y]' => '5'
32+
'locale' => 'en',
33+
'language' => 'en',
34+
'latitude' => '5',
35+
'longitude' => '5',
36+
'altitude' => '5',
37+
'device_id' => '5',
38+
'ttl' => '5',
39+
'remote_image_url' => 'test_url',
40+
'image' => 'test_file',
41+
'focus_x' => '5',
42+
'focus_y' => '5'
4343
}
4444
)
4545
end
@@ -50,8 +50,8 @@
5050

5151
it 'returns the proper result' do
5252
stub_post(
53-
path: '/image_requests',
54-
body: { "image_request"=>{ "locale"=>"en", "remote_image_url"=>"test_url" } },
53+
path: '/v1/images',
54+
body: { "locale" => "en", "remote_image_url" => "test_url" },
5555
response: fixture_file('image_request.json')
5656
)
5757

@@ -64,8 +64,8 @@
6464

6565
it 'responds correctly to a response exception error' do
6666
stub_post(
67-
path: '/image_requests',
68-
body: { "image_request"=>{ "locale"=>"en", "remote_image_url"=>"test_url" } },
67+
path: '/v1/images',
68+
body: { "locale" => "en", "remote_image_url" => "test_url" },
6969
response: fixture_file('error_response.json')
7070
)
7171

@@ -74,8 +74,8 @@
7474

7575
it 'responds correctly to an unexpected response' do
7676
stub_post(
77-
path: '/image_requests',
78-
body: { "image_request"=>{ "locale"=>"en", "remote_image_url"=>"test_url" } },
77+
path: '/v1/images',
78+
body: { "locale" => "en", "remote_image_url" => "test_url" },
7979
response: fixture_file('unexpected_response.json')
8080
)
8181

@@ -84,12 +84,12 @@
8484
end
8585

8686
describe '#repost' do
87-
let(:params) { { image_request: { locale: 'en', remote_image_url: 'test_url' } } }
87+
let(:params) { { locale: 'en', remote_image_url: 'test_url' } }
8888

8989
it 'returns the proper result' do
9090
stub_post(
91-
path: '/image_requests/sample_token/repost',
92-
body: { "image_request"=>{ "locale"=>"en", "remote_image_url"=>"test_url" } },
91+
path: '/v1/images/sample_token/repost',
92+
body: { "locale" => "en", "remote_image_url" => "test_url" },
9393
response: fixture_file('image_request.json')
9494
)
9595

@@ -102,8 +102,8 @@
102102

103103
it 'responds correctly to a response exception error' do
104104
stub_post(
105-
path: '/image_requests/sample_token/repost',
106-
body: { "image_request"=>{ "locale"=>"en", "remote_image_url"=>"test_url" } },
105+
path: '/v1/images/sample_token/repost',
106+
body: { "locale" => "en", "remote_image_url" => "test_url" },
107107
response: fixture_file('error_response.json')
108108
)
109109

@@ -112,8 +112,8 @@
112112

113113
it 'responds correctly to an unexpected response' do
114114
stub_post(
115-
path: '/image_requests/sample_token/repost',
116-
body: { "image_request"=>{ "locale"=>"en", "remote_image_url"=>"test_url" } },
115+
path: '/v1/images/sample_token/repost',
116+
body: { "locale" => "en", "remote_image_url" => "test_url" },
117117
response: fixture_file('unexpected_response.json')
118118
)
119119

spec/cloudsight/response_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
describe '#get' do
99
it 'returns the proper result' do
1010
stub_get(
11-
path: '/image_responses/sample_token',
11+
path: '/v1/images/sample_token',
1212
response: fixture_file('completed_response.json')
1313
)
1414

@@ -21,7 +21,7 @@
2121

2222
it 'responds correctly to a response exception error' do
2323
stub_get(
24-
path: '/image_responses/sample_token',
24+
path: '/v1/images/sample_token',
2525
response: fixture_file('error_response.json')
2626
)
2727

@@ -30,7 +30,7 @@
3030

3131
it 'responds correctly to an unexpected response' do
3232
stub_get(
33-
path: '/image_responses/sample_token',
33+
path: '/v1/images/sample_token',
3434
response: fixture_file('unexpected_response.json')
3535
)
3636

@@ -40,7 +40,7 @@
4040

4141
describe '#retrieve' do
4242
it 'returns the proper result' do
43-
stub_polling(3, 'image_request.json', 'completed_response.json', '/image_responses/sample_token')
43+
stub_polling(3, 'image_request.json', 'completed_response.json', '/v1/images/sample_token')
4444

4545
response = described_class.retrieve('sample_token', poll_wait: 0.01)
4646

@@ -50,13 +50,13 @@
5050
end
5151

5252
it 'responds correctly to a response exception error' do
53-
stub_polling(3, 'image_request.json', 'error_response.json', '/image_responses/sample_token')
53+
stub_polling(3, 'image_request.json', 'error_response.json', '/v1/images/sample_token')
5454

5555
expect { described_class.retrieve('sample_token', poll_wait: 0.01) }.to raise_error Cloudsight::ResponseException
5656
end
5757

5858
it 'responds correctly to an unexpected response' do
59-
stub_polling(3, 'image_request.json', 'unexpected_response.json', '/image_responses/sample_token')
59+
stub_polling(3, 'image_request.json', 'unexpected_response.json', '/v1/images/sample_token')
6060

6161
expect { described_class.retrieve('sample_token', poll_wait: 0.01) }.to raise_error Cloudsight::UnexpectedResponseException
6262
end

0 commit comments

Comments
 (0)