72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/cloudsight.rb', line 72
def self.send(options = {})
raise RuntimeError.new("Need to define either oauth_options or api_key") unless Cloudsight.api_key || Cloudsight.oauth_options
url = "#{Cloudsight::base_url}/image_requests"
params = {}
[:locale, :language, :latitude, :longitude, :altitude, :device_id, :ttl].each do |attr|
params["image_request[#{attr}]"] = options[attr] if options.has_key?(attr)
end
if options[:focus]
params['focus[x]'] = options[:focus][:x]
params['focus[y]'] = options[:focus][:y]
end
params['image_request[remote_image_url]'] = options[:url] if options.has_key?(:url)
params['image_request[image]'] = options[:file] if options.has_key?(:file)
response = Util.post(url, params)
data = JSON.parse(response.body)
raise ResponseException.new(data['error']) if data['error']
raise UnexpectedResponseException.new(response.body) unless data['token']
data
end
|