cloudsight 0.0.9.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/Rakefile +10 -1
- data/lib/cloudsight/request.rb +8 -8
- data/lib/cloudsight/response.rb +1 -1
- data/lib/cloudsight/version.rb +1 -1
- data/spec/cloudsight/request_spec.rb +24 -24
- data/spec/cloudsight/response_spec.rb +6 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 478811edc71cf94a43fbbb5c6f90523abcff2566
|
4
|
+
data.tar.gz: 4ec2871c44911b853f97412d83d69cc4e97668b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c638e70d37ba3ebafd51ec85e3f7d524cad69edf42513351fe22ec41124106ef99a6e2eebfd500224a68c6fb27df60030e046afeecf6de291b44a210e51489a
|
7
|
+
data.tar.gz: 17608322f8b79f1e7ba8ba229a3d05dd96fc1615f07a350414e58992e0bf22819a2f2408b0111be7898f487b89a67b763265fd1adbb2a09f84c4d2d54ffcd60e
|
data/README.md
CHANGED
@@ -51,25 +51,25 @@ Usage
|
|
51
51
|
Send the image request using a file:
|
52
52
|
|
53
53
|
```ruby
|
54
|
-
|
54
|
+
request_data = Cloudsight::Request.send(locale: 'en', file: File.open('image.jpg'))
|
55
55
|
```
|
56
56
|
|
57
57
|
Or, you can send the image request using a URL:
|
58
58
|
|
59
59
|
```ruby
|
60
|
-
|
60
|
+
request_data = Cloudsight::Request.send(locale: 'en', url: 'http://www.google.com/images/srpr/logo11w.png')
|
61
61
|
```
|
62
62
|
|
63
63
|
Then, use the token to retrieve the response:
|
64
64
|
|
65
65
|
```ruby
|
66
|
-
|
66
|
+
response_data = Cloudsight::Response.get(request_data['token'])
|
67
67
|
```
|
68
68
|
|
69
69
|
You can also use the `retrieve` method which will poll for the response for you:
|
70
70
|
|
71
71
|
```ruby
|
72
|
-
Cloudsight::Response.retrieve(
|
73
|
-
p
|
72
|
+
Cloudsight::Response.retrieve(request_data['token']) do |response_data|
|
73
|
+
p response_data
|
74
74
|
end
|
75
75
|
```
|
data/Rakefile
CHANGED
data/lib/cloudsight/request.rb
CHANGED
@@ -3,7 +3,7 @@ module Cloudsight
|
|
3
3
|
class << self
|
4
4
|
def send(options = {})
|
5
5
|
raise RuntimeError.new("Need to define either oauth_options or api_key") unless Cloudsight.api_key || Cloudsight.oauth_options
|
6
|
-
url = "#{Cloudsight::base_url}/
|
6
|
+
url = "#{Cloudsight::base_url}/v1/images"
|
7
7
|
|
8
8
|
params = construct_params(options)
|
9
9
|
response = Api.post(url, params)
|
@@ -15,7 +15,7 @@ module Cloudsight
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def repost(token, options = {})
|
18
|
-
url = "#{Cloudsight::base_url}/
|
18
|
+
url = "#{Cloudsight::base_url}/v1/images/#{token}/repost"
|
19
19
|
|
20
20
|
response = Api.post(url, options)
|
21
21
|
return true if response.code == 200 and response.body.to_s.strip.empty?
|
@@ -29,17 +29,17 @@ module Cloudsight
|
|
29
29
|
|
30
30
|
def construct_params(options)
|
31
31
|
params = {}
|
32
|
-
[:locale, :language, :latitude, :longitude, :altitude, :device_id, :ttl].each do |attr|
|
33
|
-
params[
|
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)
|
34
34
|
end
|
35
35
|
|
36
36
|
if options[:focus]
|
37
|
-
params['
|
38
|
-
params['
|
37
|
+
params['focus_x'] = options[:focus][:x]
|
38
|
+
params['focus_y'] = options[:focus][:y]
|
39
39
|
end
|
40
40
|
|
41
|
-
params['
|
42
|
-
params['
|
41
|
+
params['remote_image_url'] = options[:url] if options.has_key?(:url)
|
42
|
+
params['image'] = options[:file] if options.has_key?(:file)
|
43
43
|
params
|
44
44
|
end
|
45
45
|
end
|
data/lib/cloudsight/response.rb
CHANGED
data/lib/cloudsight/version.rb
CHANGED
@@ -29,17 +29,17 @@ RSpec.describe Cloudsight::Request do
|
|
29
29
|
options = described_class.construct_params(params)
|
30
30
|
expect(options).to eq(
|
31
31
|
{
|
32
|
-
'
|
33
|
-
'
|
34
|
-
'
|
35
|
-
'
|
36
|
-
'
|
37
|
-
'
|
38
|
-
'
|
39
|
-
'
|
40
|
-
'
|
41
|
-
'
|
42
|
-
'
|
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'
|
43
43
|
}
|
44
44
|
)
|
45
45
|
end
|
@@ -50,8 +50,8 @@ RSpec.describe Cloudsight::Request do
|
|
50
50
|
|
51
51
|
it 'returns the proper result' do
|
52
52
|
stub_post(
|
53
|
-
path: '/
|
54
|
-
body: { "
|
53
|
+
path: '/v1/images',
|
54
|
+
body: { "locale" => "en", "remote_image_url" => "test_url" },
|
55
55
|
response: fixture_file('image_request.json')
|
56
56
|
)
|
57
57
|
|
@@ -64,8 +64,8 @@ RSpec.describe Cloudsight::Request do
|
|
64
64
|
|
65
65
|
it 'responds correctly to a response exception error' do
|
66
66
|
stub_post(
|
67
|
-
path: '/
|
68
|
-
body: { "
|
67
|
+
path: '/v1/images',
|
68
|
+
body: { "locale" => "en", "remote_image_url" => "test_url" },
|
69
69
|
response: fixture_file('error_response.json')
|
70
70
|
)
|
71
71
|
|
@@ -74,8 +74,8 @@ RSpec.describe Cloudsight::Request do
|
|
74
74
|
|
75
75
|
it 'responds correctly to an unexpected response' do
|
76
76
|
stub_post(
|
77
|
-
path: '/
|
78
|
-
body: { "
|
77
|
+
path: '/v1/images',
|
78
|
+
body: { "locale" => "en", "remote_image_url" => "test_url" },
|
79
79
|
response: fixture_file('unexpected_response.json')
|
80
80
|
)
|
81
81
|
|
@@ -84,12 +84,12 @@ RSpec.describe Cloudsight::Request do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
describe '#repost' do
|
87
|
-
let(:params) { {
|
87
|
+
let(:params) { { locale: 'en', remote_image_url: 'test_url' } }
|
88
88
|
|
89
89
|
it 'returns the proper result' do
|
90
90
|
stub_post(
|
91
|
-
path: '/
|
92
|
-
body: { "
|
91
|
+
path: '/v1/images/sample_token/repost',
|
92
|
+
body: { "locale" => "en", "remote_image_url" => "test_url" },
|
93
93
|
response: fixture_file('image_request.json')
|
94
94
|
)
|
95
95
|
|
@@ -102,8 +102,8 @@ RSpec.describe Cloudsight::Request do
|
|
102
102
|
|
103
103
|
it 'responds correctly to a response exception error' do
|
104
104
|
stub_post(
|
105
|
-
path: '/
|
106
|
-
body: { "
|
105
|
+
path: '/v1/images/sample_token/repost',
|
106
|
+
body: { "locale" => "en", "remote_image_url" => "test_url" },
|
107
107
|
response: fixture_file('error_response.json')
|
108
108
|
)
|
109
109
|
|
@@ -112,8 +112,8 @@ RSpec.describe Cloudsight::Request do
|
|
112
112
|
|
113
113
|
it 'responds correctly to an unexpected response' do
|
114
114
|
stub_post(
|
115
|
-
path: '/
|
116
|
-
body: { "
|
115
|
+
path: '/v1/images/sample_token/repost',
|
116
|
+
body: { "locale" => "en", "remote_image_url" => "test_url" },
|
117
117
|
response: fixture_file('unexpected_response.json')
|
118
118
|
)
|
119
119
|
|
@@ -8,7 +8,7 @@ RSpec.describe Cloudsight::Response do
|
|
8
8
|
describe '#get' do
|
9
9
|
it 'returns the proper result' do
|
10
10
|
stub_get(
|
11
|
-
path: '/
|
11
|
+
path: '/v1/images/sample_token',
|
12
12
|
response: fixture_file('completed_response.json')
|
13
13
|
)
|
14
14
|
|
@@ -21,7 +21,7 @@ RSpec.describe Cloudsight::Response do
|
|
21
21
|
|
22
22
|
it 'responds correctly to a response exception error' do
|
23
23
|
stub_get(
|
24
|
-
path: '/
|
24
|
+
path: '/v1/images/sample_token',
|
25
25
|
response: fixture_file('error_response.json')
|
26
26
|
)
|
27
27
|
|
@@ -30,7 +30,7 @@ RSpec.describe Cloudsight::Response do
|
|
30
30
|
|
31
31
|
it 'responds correctly to an unexpected response' do
|
32
32
|
stub_get(
|
33
|
-
path: '/
|
33
|
+
path: '/v1/images/sample_token',
|
34
34
|
response: fixture_file('unexpected_response.json')
|
35
35
|
)
|
36
36
|
|
@@ -40,7 +40,7 @@ RSpec.describe Cloudsight::Response do
|
|
40
40
|
|
41
41
|
describe '#retrieve' do
|
42
42
|
it 'returns the proper result' do
|
43
|
-
stub_polling(3, 'image_request.json', 'completed_response.json', '/
|
43
|
+
stub_polling(3, 'image_request.json', 'completed_response.json', '/v1/images/sample_token')
|
44
44
|
|
45
45
|
response = described_class.retrieve('sample_token', poll_wait: 0.01)
|
46
46
|
|
@@ -50,13 +50,13 @@ RSpec.describe Cloudsight::Response do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'responds correctly to a response exception error' do
|
53
|
-
stub_polling(3, 'image_request.json', 'error_response.json', '/
|
53
|
+
stub_polling(3, 'image_request.json', 'error_response.json', '/v1/images/sample_token')
|
54
54
|
|
55
55
|
expect { described_class.retrieve('sample_token', poll_wait: 0.01) }.to raise_error Cloudsight::ResponseException
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'responds correctly to an unexpected response' do
|
59
|
-
stub_polling(3, 'image_request.json', 'unexpected_response.json', '/
|
59
|
+
stub_polling(3, 'image_request.json', 'unexpected_response.json', '/v1/images/sample_token')
|
60
60
|
|
61
61
|
expect { described_class.retrieve('sample_token', poll_wait: 0.01) }.to raise_error Cloudsight::UnexpectedResponseException
|
62
62
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudsight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Folkens
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-12-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
@@ -176,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
176
|
version: '0'
|
177
177
|
requirements: []
|
178
178
|
rubyforge_project:
|
179
|
-
rubygems_version: 2.6.
|
179
|
+
rubygems_version: 2.6.13
|
180
180
|
signing_key:
|
181
181
|
specification_version: 4
|
182
182
|
summary: CloudSight API Client
|