Class: Rubyidescat::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyidescat/client.rb

Constant Summary collapse

BASE_URL =
'http://api.idescat.cat/'

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
# File 'lib/rubyidescat/client.rb', line 9

def initialize(attributes = {})
  attributes.each do |attr, value|
    self.send("#{attr}=", value)
  end
end

Instance Method Details

#poblacio(version, format, operation, params = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/rubyidescat/client.rb', line 15

def poblacio(version, format, operation, params = {})
  @format = format
  @version = version
  @operation = operation
  @params = params
  @request_url = BASE_URL + 'pob/' + @version + '/' + @operation + '.' + @format
  @request_url += '?p=' + @params.map{|k,v|"#{k}/#{[v].flatten.join(",")}"}.join(";") unless @params.empty?
  make_call
end

#request_urlObject



5
6
7
# File 'lib/rubyidescat/client.rb', line 5

def request_url
  URI.escape(@request_url)
end