Class: Kayakoapi::URLGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/kayakoapi-ruby/urlgenerator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url_root) ⇒ URLGenerator

Returns a new instance of URLGenerator.



5
6
7
8
# File 'lib/kayakoapi-ruby/urlgenerator.rb', line 5

def initialize(url_root)
  @url_root = url_root
  @params = {}
end

Class Method Details

.urlncode(string) ⇒ Object



30
31
32
# File 'lib/kayakoapi-ruby/urlgenerator.rb', line 30

def self.urlncode(string)
  URI.escape(string, Regexp.new("[Generating an API Signature^#{URI::PATTERN::UNRESERVED}]"))
end

Instance Method Details

#append_to_url(key, value) ⇒ Object



10
11
12
# File 'lib/kayakoapi-ruby/urlgenerator.rb', line 10

def append_to_url(key, value)
  @params[key] = value
end

#first_param?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/kayakoapi-ruby/urlgenerator.rb', line 26

def first_param?
  @first_param
end

#full_urlObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/kayakoapi-ruby/urlgenerator.rb', line 14

def full_url
  current_url = @url_root
  if @params.empty?
    raise NoURLParametersException.new(msg: "Params hash is empty while attempting to build a URL.")
  else
    @params.each do |key, value|
      current_url += "&#{key}=#{value}"
    end
    return current_url
  end
end