Class: Kayakoapi::URLGenerator
- Inherits:
-
Object
- Object
- Kayakoapi::URLGenerator
- Defined in:
- lib/kayakoapi-ruby/urlgenerator.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
-
#url_root ⇒ Object
Returns the value of attribute url_root.
Class Method Summary collapse
Instance Method Summary collapse
- #append_to_url(key, value) ⇒ Object
- #first_param? ⇒ Boolean
- #full_url ⇒ Object
-
#initialize(url_root) ⇒ URLGenerator
constructor
A new instance of URLGenerator.
Constructor Details
#initialize(url_root) ⇒ URLGenerator
Returns a new instance of URLGenerator.
7 8 9 10 11 |
# File 'lib/kayakoapi-ruby/urlgenerator.rb', line 7 def initialize(url_root) @url_root = url_root @params = {} @first_param = true end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/kayakoapi-ruby/urlgenerator.rb', line 5 def params @params end |
#url_root ⇒ Object
Returns the value of attribute url_root.
5 6 7 |
# File 'lib/kayakoapi-ruby/urlgenerator.rb', line 5 def url_root @url_root end |
Class Method Details
.urlncode(string) ⇒ Object
38 39 40 |
# File 'lib/kayakoapi-ruby/urlgenerator.rb', line 38 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
13 14 15 |
# File 'lib/kayakoapi-ruby/urlgenerator.rb', line 13 def append_to_url(key, value) @params[key] = value end |
#first_param? ⇒ Boolean
34 35 36 |
# File 'lib/kayakoapi-ruby/urlgenerator.rb', line 34 def first_param? @first_param end |
#full_url ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/kayakoapi-ruby/urlgenerator.rb', line 17 def full_url current_url = @url_root if @params.empty? raise NoURLParameters.new(msg: "Params hash is empty while attempting to build a URL.") else @params.each do |key, value| if @first_param current_url += "?#{key}=#{value}" @first_param = false else current_url += "&#{key}=#{value}" end end return current_url end end |