Class: Oceanarium::Image
- Inherits:
-
Object
- Object
- Oceanarium::Image
- Defined in:
- lib/oceanarium/resources/image.rb
Instance Attribute Summary collapse
-
#distribution ⇒ Object
Returns the value of attribute distribution.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#slug ⇒ Object
Returns the value of attribute slug.
Class Method Summary collapse
-
.all ⇒ Object
Core API.
- .destroy(id) ⇒ Object
- .find(id) ⇒ Object
- .find_by_name(string) ⇒ Object
- .global ⇒ Object
- .local ⇒ Object
- .transfer(id, region_id) ⇒ Object
Instance Method Summary collapse
-
#destroy ⇒ Object
User API.
-
#initialize(option, api_key, client_id) ⇒ Image
constructor
A new instance of Image.
- #transfer(region_id) ⇒ Object
Constructor Details
#initialize(option, api_key, client_id) ⇒ Image
Returns a new instance of Image.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/oceanarium/resources/image.rb', line 5 def initialize(option, api_key, client_id) if api_key.nil? || client_id.nil? raise 'No API key/client ID!' else if option.is_a?(Hash) @object = option else @object = Oceanarium::Image.find(option) end if @object.nil? self.id = nil else self.id = @object['id'] self.name = @object['name'] self.slug = @object['slug'] self.distribution = @object['distribution'] end end end |
Instance Attribute Details
#distribution ⇒ Object
Returns the value of attribute distribution.
3 4 5 |
# File 'lib/oceanarium/resources/image.rb', line 3 def distribution @distribution end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/oceanarium/resources/image.rb', line 3 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/oceanarium/resources/image.rb', line 3 def name @name end |
#slug ⇒ Object
Returns the value of attribute slug.
3 4 5 |
# File 'lib/oceanarium/resources/image.rb', line 3 def slug @slug end |
Class Method Details
.all ⇒ Object
Core API
37 38 39 40 41 42 43 44 |
# File 'lib/oceanarium/resources/image.rb', line 37 def self.all # Returns all avaliable images in Array @request = Oceanarium::Request.new @get = @request.get('/images/') if @get.parsed_response['status'] == 'OK' @get.parsed_response['images'] end end |
.destroy(id) ⇒ Object
77 78 79 80 81 |
# File 'lib/oceanarium/resources/image.rb', line 77 def self.destroy(id) @request = Oceanarium::Request.new @get = @request.get("/images/#{id}/destroy/") @get.parsed_response['status'] end |
.find(id) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/oceanarium/resources/image.rb', line 64 def self.find(id) @request = Oceanarium::Request.new @get = @request.get("/images/#{id}/") if @get.parsed_response['status'] == 'OK' @get.parsed_response['image'] end end |
.find_by_name(string) ⇒ Object
72 73 74 75 |
# File 'lib/oceanarium/resources/image.rb', line 72 def self.find_by_name(string) # Returns Array of images which name matching string. self.all.select { |i| i['name'].include? string } end |
.global ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/oceanarium/resources/image.rb', line 46 def self.global # Returns all global images in Array @request = Oceanarium::Request.new @get = @request.get('/images/?filter=global') if @get.parsed_response['status'] == 'OK' @get.parsed_response['images'] end end |
.local ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/oceanarium/resources/image.rb', line 55 def self.local # Returns all user's images in Array @request = Oceanarium::Request.new @get = @request.get('/images/?filter=my_images') if @get.parsed_response['status'] == 'OK' @get.parsed_response['images'] end end |
.transfer(id, region_id) ⇒ Object
83 84 85 86 87 |
# File 'lib/oceanarium/resources/image.rb', line 83 def self.transfer(id, region_id) @request = Oceanarium::Request.new @get = @request.get("/images/#{id}/transfer/?region_id=#{region_id}") @get.parsed_response['status'] end |
Instance Method Details
#destroy ⇒ Object
User API
27 28 29 |
# File 'lib/oceanarium/resources/image.rb', line 27 def destroy Oceanarium::Image.destroy(self.id) end |
#transfer(region_id) ⇒ Object
31 32 33 |
# File 'lib/oceanarium/resources/image.rb', line 31 def transfer(region_id) Oceanarium::Image.transfer(self.id, region_id) end |