Class: Uploadcare::Api::Group
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Uploadcare::Api::Group
- Defined in:
- lib/uploadcare/resources/group.rb
Instance Method Summary collapse
- #cdn_url ⇒ Object
- #file_cdn_url(index = 0) ⇒ Object
-
#initialize(api, uuid_or_cdn_url, data = nil) ⇒ Group
constructor
A new instance of Group.
-
#is_loaded? ⇒ Boolean
(also: #loaded?)
Loading logic.
- #is_stored? ⇒ Boolean (also: #stored?)
- #load_data ⇒ Object (also: #load)
- #load_data! ⇒ Object (also: #load!)
-
#store ⇒ Object
Store group (and all files in group).
- #store! ⇒ Object
Constructor Details
#initialize(api, uuid_or_cdn_url, data = nil) ⇒ Group
Returns a new instance of Group.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/uploadcare/resources/group.rb', line 6 def initialize api, uuid_or_cdn_url, data=nil result = Uploadcare::Parser.parse_group_string(uuid_or_cdn_url) @api = api group = {uuid: result["uuid"], files_count: result["count"]} super group # if data is suplide - just pass it to builder. set_data(data) if data end |
Instance Method Details
#cdn_url ⇒ Object
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def cdn_url @api.[:static_url_base] + "/#{uuid}/" end |
#file_cdn_url(index = 0) ⇒ Object
21 22 23 24 |
# File 'lib/uploadcare/resources/group.rb', line 21 def file_cdn_url index=0 raise ArgumentError.new "The index was given is greater than files count in group." if index + 1 > files_count cdn_url + "nth/#{index}/" end |
#is_loaded? ⇒ Boolean Also known as: loaded?
Loading logic
27 28 29 |
# File 'lib/uploadcare/resources/group.rb', line 27 def is_loaded? !send(:files).nil? end |
#is_stored? ⇒ Boolean Also known as: stored?
62 63 64 65 |
# File 'lib/uploadcare/resources/group.rb', line 62 def is_stored? return nil unless is_loaded? !send(:datetime_stored).nil? end |
#load_data ⇒ Object Also known as: load
32 33 34 35 36 37 |
# File 'lib/uploadcare/resources/group.rb', line 32 def load_data unless is_loaded? load_data! end self end |
#load_data! ⇒ Object Also known as: load!
40 41 42 43 44 45 |
# File 'lib/uploadcare/resources/group.rb', line 40 def load_data! data = @api.get "/groups/#{uuid}/" set_data data self end |
#store ⇒ Object
Store group (and all files in group)
49 50 51 52 53 54 |
# File 'lib/uploadcare/resources/group.rb', line 49 def store unless is_stored? store! end self end |
#store! ⇒ Object
56 57 58 59 60 |
# File 'lib/uploadcare/resources/group.rb', line 56 def store! data = @api.put "/groups/#{uuid}/storage/" set_data(data) self end |