class TinyClient::UrlBuilder
Convenient class used to build a request URL.
Constants
- SEPARATOR
Attributes
query[W]
Public Class Methods
new(url)
click to toggle source
# File lib/tiny_client/url_builder.rb, line 30 def initialize(url) @path = [url] @query = {} end
url(url)
click to toggle source
# File lib/tiny_client/url_builder.rb, line 9 def self.url(url) new(url) end
Public Instance Methods
build!()
click to toggle source
# File lib/tiny_client/url_builder.rb, line 23 def build! query_s = "?#{@query.to_query}" unless @query.empty? "#{@path.join(SEPARATOR)}.json#{query_s}" end
path(path)
click to toggle source
# File lib/tiny_client/url_builder.rb, line 13 def path(path) @path << fix_path(path) unless path.blank? self end
query(params = {})
click to toggle source
# File lib/tiny_client/url_builder.rb, line 18 def query(params = {}) @query.merge!(params) unless params.empty? self end
Private Instance Methods
fix_path(path)
click to toggle source
# File lib/tiny_client/url_builder.rb, line 35 def fix_path(path) if path.respond_to?(:gsub) path.gsub(/\.json$/, '') else path end end