Class: ClassicApi::Command::Images
- Inherits:
-
Base
- Object
- Thor
- Base
- ClassicApi::Command::Images
show all
- Defined in:
- lib/classic_api/command/images.rb
Instance Method Summary
collapse
Methods inherited from Base
api, handle_argument_error, start
Instance Method Details
#get(id) ⇒ Object
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/classic_api/command/images.rb', line 12
def get(id)
image = api.images.find(id)
system "open #{image.url}" if options.open
present(image)
if image.children
image.children.each do|child|
present(child, 1)
end
end
end
|
#list ⇒ Object
5
6
7
8
|
# File 'lib/classic_api/command/images.rb', line 5
def list
images = api.images.all
present(images)
end
|
25
26
27
28
29
|
# File 'lib/classic_api/command/images.rb', line 25
def transform(id, strategy, width=nil, height=nil)
transformation = api.images.find(id).transform(strategy: strategy, width: width, height: height)
system "open #{transformation.url}" if options.open
present transformation
end
|
#upload(file, path = nil) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/classic_api/command/images.rb', line 35
def upload(file, path=nil)
local_path = File.absolute_path(file)
raise "File #{file} does not exist!" unless File.exists?(local_path)
path = file if path.nil?
policy = api.policies.create!(path: path)
if policy.image.stored_at and !options.force
print_error("An image file already exists with path '#{path}'.")
print_info("USAGE", "Use --force to overwrite.")
exit(1)
end
result = policy.upload_file(local_path)
transformations = options.transformations.map do |transformation_string|
(strategy,width,height) = transformation_string.split("/")
{strategy: strategy, width: width&.to_i, height: height&.to_i}
end
policy.image.update_attributes(stored_at: DateTime.now, transformations: transformations)
system "open #{policy.image.url}" if options.open
print_success("Image successfully uploaded")
present policy.image
end
|