Class: Heremaps::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/heremaps/resources/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#method_nameObject

Returns the value of attribute method_name.



3
4
5
# File 'lib/heremaps/resources/base.rb', line 3

def method_name
  @method_name
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/heremaps/resources/base.rb', line 3

def path
  @path
end

#serviceObject

Returns the value of attribute service.



3
4
5
# File 'lib/heremaps/resources/base.rb', line 3

def service
  @service
end

Class Method Details

.get(options = {}) ⇒ Object



21
22
23
# File 'lib/heremaps/resources/base.rb', line 21

def self.get(options = {})
  new.get(options)
end

Instance Method Details

#get(options = {}) ⇒ Object



11
12
13
14
# File 'lib/heremaps/resources/base.rb', line 11

def get(options = {})
  res = RestClient.get(request_url(:format => options[:format]), :params => prepare_the_request(options))
  res
end

#prepare_the_request(options = {}) ⇒ Object



16
17
18
19
# File 'lib/heremaps/resources/base.rb', line 16

def prepare_the_request(options = {})
  options = options.merge(:apiKey => Heremaps::API_KEY)
  options
end

#request_url(format: "json") ⇒ Object



5
6
7
8
9
# File 'lib/heremaps/resources/base.rb', line 5

def request_url(format: "json")
  format ||= "json"
  url = File.join("https://", service + "." + Heremaps::DOMAIN, path, "#{method_name}.#{format}")
  url
end

#response_to_missing?(method_sym, *arg, &block) ⇒ Boolean

direct call to instance methods as class methods.

Returns:

  • (Boolean)


26
27
28
29
30
31
32
# File 'lib/heremaps/resources/base.rb', line 26

def response_to_missing?(method_sym, *arg, &block)
  if instance_methods.include?(method_sym)
    new.send(method_sym, *arg, &block)
  else
    super
  end
end