Class: Cloudsight::Response

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

Class Method Summary collapse

Class Method Details

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

Raises:



112
113
114
115
116
117
118
119
120
121
# File 'lib/cloudsight.rb', line 112

def self.get(token, options = {})
  url = "#{Cloudsight::base_url}/image_responses/#{token}"

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

  data
end

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



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/cloudsight.rb', line 123

def self.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