Class: Bag::Gemeente

Inherits:
Base
  • Object
show all
Defined in:
lib/bag/gemeente.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gemeentecode, gemeentenaam) ⇒ Gemeente

Returns a new instance of Gemeente.



5
6
7
8
# File 'lib/bag/gemeente.rb', line 5

def initialize(gemeentecode, gemeentenaam)
  self.gemeentecode = gemeentecode
  self.gemeentenaam = gemeentenaam
end

Instance Attribute Details

#gemeentecodeObject

Returns the value of attribute gemeentecode.



3
4
5
# File 'lib/bag/gemeente.rb', line 3

def gemeentecode
  @gemeentecode
end

#gemeentenaamObject

Returns the value of attribute gemeentenaam.



3
4
5
# File 'lib/bag/gemeente.rb', line 3

def gemeentenaam
  @gemeentenaam
end

Class Method Details

.allObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bag/gemeente.rb', line 10

def self.all
  response = get('/gemeentes')
  result = []
  if response.success?
    response.each do |obj|
      result << self.new(obj['gemeentecode'], obj['gemeentenaam'])
    end
  elsif response.code == 404
    return nil
  else
    raise response.parsed_response['error']
  end
  result
end

.find_by_id(id) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/bag/gemeente.rb', line 36

def self.find_by_id(id)
  response = get("/gemeentes/#{URI::encode(id.to_s)}")
  if response.success?
    self.new(response['gemeentecode'], response['gemeentenaam'])
  elsif response.code == 404
    return nil
  else
    raise response.parsed_response['error']
  end
end

.reverse_geocode(latitude, longitude) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/bag/gemeente.rb', line 25

def self.reverse_geocode(latitude, longitude)
  response = get("/gemeentes/reverse_geocode", query: {longitude: longitude, latitude: latitude})
  if response.success?
    self.new(response['gemeentecode'], response['gemeentenaam'])
  elsif response.code == 404
    return nil
  else
    raise response.parsed_response['error']
  end
end