cloudsight 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cloudsight.rb +25 -25
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2fd9cb63d16322fabb673abe3da859ef57382cb4
4
- data.tar.gz: c83cf57f6ebc7a618b858b602abc234a56f166a9
3
+ metadata.gz: a2fe5db87751bdc8c72c250868e949cf1b045576
4
+ data.tar.gz: eeb791589e465b21e8cbeffa9a64d8eb3927134b
5
5
  SHA512:
6
- metadata.gz: eb0623535da6c8e2657172f2a57f96d54c572dfec4e877d7256b906f8a94fdb0d17aa271231826b7f6c2184ea829b715a2eacae47f0027cc662d7df887fb295c
7
- data.tar.gz: 12c945044957ef0c4e8fa2dc7833e6c0050be84537549b12deaa0548cc9f979aee2510f028c9a8b4fcfbd7db5d0305f70cd0c179376e717b31dc1213e7731ae3
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.wrap_request &block
44
- RestClient.reset_before_execution_procs
45
- RestClient.add_before_execution_proc do |req, params|
46
- if params[:payload]
47
- filtered_payload = params[:payload].dup
48
- filtered_payload.delete('image_request[image]')
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
- begin
60
- retval = yield
61
- rescue RestClient::Exception => e
62
- retval = e.response
63
- end
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
- RestClient.reset_before_execution_procs
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
- return retval
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.wrap_request { RestClient.post(url, params) }
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.wrap_request { RestClient.post(url, options) }
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.wrap_request { RestClient.get(url) }
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']
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
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Folkens