Class: Hover::Client::Midas
Instance Attribute Summary
Attributes inherited from HMAC
#client_id, #client_secret
Attributes inherited from HTTP
#prefix, #site
Instance Method Summary
collapse
Methods inherited from Hover
#json_delete, #json_get, #json_patch, #json_post, #json_put
Methods inherited from HMAC
#authenticate, #initialize
Methods inherited from HTTP
#authenticate, #delete, #get, #get_redirect_location, #initialize, #make_form_request, #make_request, #make_uri, #parse_response, #patch, #post, #put, #raise_errors, #raise_errors_for_cloudfront_response
Instance Method Details
#complete_order_upload(order_id) ⇒ Object
43
44
45
|
# File 'lib/hover/client/midas.rb', line 43
def complete_order_upload(order_id)
patch("orders/#{order_id}/archive_uploading_complete.json")
end
|
#create_order(params = {}) ⇒ Object
def update_order(id, order_attributes)
put("orders/#{id}.json", order_parameters(order_attributes))
end
39
40
41
|
# File 'lib/hover/client/midas.rb', line 39
def create_order(params = {})
json_post('orders.json', params)
end
|
#download_image(image, parameters = {}, &block) ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/hover/client/midas.rb', line 59
def download_image(image, parameters = {}, &block)
return unless url = get_redirect_location("images/#{image["id"]}.jpg", parameters)
Tempfile.open(["image-download", ".jpg"]) do |output|
output.write(Kernel.open(url).read)
output.rewind
yield output
end
end
|
#image(id) ⇒ Object
55
56
57
|
# File 'lib/hover/client/midas.rb', line 55
def image(id)
json_get("images/#{id}.json")
end
|
#image_upload_urls(order_id) ⇒ Object
87
88
89
|
# File 'lib/hover/client/midas.rb', line 87
def image_upload_urls(order_id)
json_get("images/upload_urls.json", order_id: order_id)
end
|
#images(parameters = {}) ⇒ Object
51
52
53
|
# File 'lib/hover/client/midas.rb', line 51
def images(parameters = {})
json_get("images.json", parameters)
end
|
#me ⇒ Object
15
16
17
|
# File 'lib/hover/client/midas.rb', line 15
def me
json_get('me.json')
end
|
#order(id, parameters = {}) ⇒ Object
27
28
29
|
# File 'lib/hover/client/midas.rb', line 27
def order(id, parameters = {})
json_get("orders/#{id}.json", parameters)
end
|
#order_complete_work(order_id) ⇒ Object
31
32
33
|
# File 'lib/hover/client/midas.rb', line 31
def order_complete_work(order_id)
put("orders/#{order_id}/work_complete.json")
end
|
#orders(parameters = {}) ⇒ Object
23
24
25
|
# File 'lib/hover/client/midas.rb', line 23
def orders(parameters = {})
json_get('orders.json', parameters)
end
|
#upload_image(image, io) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/hover/client/midas.rb', line 70
def upload_image(image, io)
raise "Already Uploaded" unless upload_url = image["image"].try(:[], "upload_url")
file = (io.is_a?(String) ? File.open(io) : io)
uri = URI.parse(upload_url)
request = Net::HTTP::Put.new(uri.request_uri)
request.body_stream = file
request.content_length = file.size
request['Content-Type'] = ''
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
response = http.request(request)
end
|
#upload_images_for_order(order_id, input_path) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/hover/client/midas.rb', line 91
def upload_images_for_order(order_id, input_path)
image_array = image_upload_urls(order_id).map { |upload_url| {"image" => {"upload_url" => upload_url}} }
file_paths = Dir.glob(File.join(input_path, "*.jp*"))
if file_paths.size > image_array.size
raise("Trying to upload #{file_paths.size} files. #{image_array.size} is the maximum.")
end
file_paths.each do |file_path|
image = image_array.pop
upload_image(image, file_path)
end
end
|
#upload_images_from_prometheus_export(order_id, export_zip_path) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/hover/client/midas.rb', line 105
def upload_images_from_prometheus_export(order_id, export_zip_path)
Zip::File.open(export_zip_path) do |zip|
Dir.mktmpdir do |directory_path|
zip.entries.select { |entry| entry.name =~ /original_image\.jp(g|eg)$/ }.each do |entry|
basename = File.basename(entry.name)
next if basename =~ /^\./
entry.(File.join(directory_path, basename)) { true }
end
upload_images_for_order(order_id, directory_path)
end
end
end
|