cloudsight 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cloudsight.rb +25 -25
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2fe5db87751bdc8c72c250868e949cf1b045576
|
4
|
+
data.tar.gz: eeb791589e465b21e8cbeffa9a64d8eb3927134b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c8302acc57e8c5317b2163682c0c2ea9842031311ac775f4897cdd5e9a2b14040916e9e66b1786f1ff23a38520cc93286c7d0ae202b513d0606e731f3898d09
|
7
|
+
data.tar.gz: 89d7a1386a9e85a10876eb0ef880d0d888284073ae88fe992492a4c5698c8db0cf1f9895b356edeed7170b6be725e854d4cc5b19ed56cbb63573d723e57eb592
|
data/lib/cloudsight.rb
CHANGED
@@ -40,31 +40,31 @@ module Cloudsight
|
|
40
40
|
end
|
41
41
|
|
42
42
|
class Util
|
43
|
-
def self.
|
44
|
-
|
45
|
-
RestClient.
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
if Cloudsight.api_key
|
52
|
-
req.add_field 'Authorization', "CloudSight #{Cloudsight.api_key}"
|
53
|
-
else
|
54
|
-
oauth = SimpleOAuth::Header.new(params[:method], params[:url], filtered_payload, Cloudsight.oauth_options || {})
|
55
|
-
req.add_field 'Authorization', oauth.to_s
|
56
|
-
end
|
57
|
-
end
|
43
|
+
def self.post(url, params, headers = {})
|
44
|
+
headers['Authorization'] = authorization_header(:post, url, params)
|
45
|
+
RestClient.post(url, params, headers)
|
46
|
+
rescue RestClient::Exception => e
|
47
|
+
e.response
|
48
|
+
end
|
58
49
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
50
|
+
def self.get(url, headers = {})
|
51
|
+
headers['Authorization'] = authorization_header(:get, url)
|
52
|
+
RestClient.get(url, headers)
|
53
|
+
rescue RestClient::Exception => e
|
54
|
+
e.response
|
55
|
+
end
|
64
56
|
|
65
|
-
|
57
|
+
def self.authorization_header(http_method, url, params = {})
|
58
|
+
if Cloudsight.api_key
|
59
|
+
"CloudSight #{Cloudsight.api_key}"
|
60
|
+
else
|
61
|
+
# Exclude image file when generating OAuth header
|
62
|
+
filtered_payload = params.dup
|
63
|
+
filtered_payload.delete('image_request[image]')
|
66
64
|
|
67
|
-
|
65
|
+
oauth = SimpleOAuth::Header.new(http_method, url, filtered_payload, Cloudsight.oauth_options || {})
|
66
|
+
oauth.to_s
|
67
|
+
end
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -86,7 +86,7 @@ module Cloudsight
|
|
86
86
|
params['image_request[remote_image_url]'] = options[:url] if options.has_key?(:url)
|
87
87
|
params['image_request[image]'] = options[:file] if options.has_key?(:file)
|
88
88
|
|
89
|
-
response = Util.
|
89
|
+
response = Util.post(url, params)
|
90
90
|
data = JSON.parse(response.body)
|
91
91
|
raise ResponseException.new(data['error']) if data['error']
|
92
92
|
raise UnexpectedResponseException.new(response.body) unless data['token']
|
@@ -97,7 +97,7 @@ module Cloudsight
|
|
97
97
|
def self.repost(token, options = {})
|
98
98
|
url = "#{Cloudsight::base_url}/image_requests/#{token}/repost"
|
99
99
|
|
100
|
-
response = Util.
|
100
|
+
response = Util.post(url, options)
|
101
101
|
return true if response.code == 200 and response.body.to_s.strip.empty?
|
102
102
|
|
103
103
|
data = JSON.parse(response.body)
|
@@ -112,7 +112,7 @@ module Cloudsight
|
|
112
112
|
def self.get(token, options = {})
|
113
113
|
url = "#{Cloudsight::base_url}/image_responses/#{token}"
|
114
114
|
|
115
|
-
response = Util.
|
115
|
+
response = Util.get(url)
|
116
116
|
data = JSON.parse(response.body)
|
117
117
|
raise ResponseException.new(data['error']) if data['error']
|
118
118
|
raise UnexpectedResponseException.new(response.body) unless data['status']
|