Class: Cloudsight::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudsight/api.rb

Class Method Summary collapse

Class Method Details

.authorization_header(http_method, url, params = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cloudsight/api.rb', line 18

def authorization_header(http_method, url, params = {})
  if Cloudsight.api_key
    "CloudSight #{Cloudsight.api_key}"
  else
    # Exclude image file when generating OAuth header
    filtered_payload = params.dup
    filtered_payload.delete('image_request[image]')

    oauth = SimpleOAuth::Header.new(http_method, url, filtered_payload, Cloudsight.oauth_options || {})
    oauth.to_s
  end
end

.get(url, headers = {}) ⇒ Object



11
12
13
14
15
16
# File 'lib/cloudsight/api.rb', line 11

def get(url, headers = {})
  headers['Authorization'] = authorization_header(:get, url)
  RestClient.get(url, headers)
rescue RestClient::Exception => e
  e.response
end

.post(url, params, headers = {}) ⇒ Object



4
5
6
7
8
9
# File 'lib/cloudsight/api.rb', line 4

def post(url, params, headers = {})
  headers['Authorization'] = authorization_header(:post, url, params)
  RestClient.post(url, params, headers)
rescue RestClient::Exception => e
  e.response
end