Class: Oceanarium::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/oceanarium/resources/image.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#distributionObject

Returns the value of attribute distribution.



3
4
5
# File 'lib/oceanarium/resources/image.rb', line 3

def distribution
  @distribution
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/oceanarium/resources/image.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/oceanarium/resources/image.rb', line 3

def name
  @name
end

#slugObject

Returns the value of attribute slug.



3
4
5
# File 'lib/oceanarium/resources/image.rb', line 3

def slug
  @slug
end

Class Method Details

.allObject

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

.globalObject



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

.localObject



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

#destroyObject

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