Class: Cloudsight::Response

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

Class Method Summary collapse

Class Method Details

.get(token, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/cloudsight/response.rb', line 4

def get(token, options = {})
  url = "#{Cloudsight::base_url}/v1/images/#{token}"

  response = Api.get(url)
  data = JSON.parse(response.body)
  raise ResponseException.new(data['error']) if data['error']
  raise UnexpectedResponseException.new(response.body) unless data['status']

  data

rescue JSON::ParserError
  raise UnexpectedResponseException.new(response.body)
end

.retrieve(token, options = {}) ⇒ Object



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

def retrieve(token, options = {})
  options = { poll_wait: 1 }.merge(options)

  data = nil
  loop do
    sleep options[:poll_wait]
    data = Cloudsight::Response.get(token, options)
    yield data if block_given?
    break if data['status'] != 'not completed' and data['status'] != 'in progress'
  end

  data
end