Class: Oceanarium::Region

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(option, api_key, client_id) ⇒ Region

Returns a new instance of Region.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/oceanarium/resources/region.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
    end
    if @object.nil?
      self.id = nil
    else
      self.id = @object['id']
      self.name = @object['name']
      self.slug = @object['slug']
    end
  end
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#slugObject

Returns the value of attribute slug.



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

def slug
  @slug
end

Class Method Details

.allObject



22
23
24
25
26
27
28
29
# File 'lib/oceanarium/resources/region.rb', line 22

def self.all
  # Returns all avaliable regions in Array
  @request = Oceanarium::Request.new
  @get = @request.get('/regions/')
  if @get.parsed_response['status'] == 'OK'
    @get.parsed_response['regions']
  end
end