Class: TinyClient::UrlBuilder
- Inherits:
-
Object
- Object
- TinyClient::UrlBuilder
- Defined in:
- lib/tiny_client/url_builder.rb
Overview
Convenient class used to build a request URL.
Constant Summary collapse
- SEPARATOR =
'/'.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#build ⇒ String
Url with all paths and query params.
-
#build! ⇒ Object
deprecated
Deprecated.
Please use #build instead
- #path(*paths) ⇒ Object
- #query(params = {}) ⇒ Object
Class Method Details
.url(url) ⇒ Object
8 9 10 |
# File 'lib/tiny_client/url_builder.rb', line 8 def self.url(url) new(url) end |
Instance Method Details
#build ⇒ String
Returns url with all paths and query params.
26 27 28 29 30 |
# File 'lib/tiny_client/url_builder.rb', line 26 def build url = "#{[@url, @path].join(SEPARATOR)}.json" url = "#{url}?#{@query.to_query}" unless @query.empty? url end |
#build! ⇒ Object
Deprecated.
Please use #build instead
33 34 35 36 |
# File 'lib/tiny_client/url_builder.rb', line 33 def build! ActiveSupport::Deprecation.warn('`build!` is deprecated. Please use `build` instead') build end |
#path(*paths) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/tiny_client/url_builder.rb', line 12 def path(*paths) paths.each do |path| new_path = fix_path(path) @path << new_path if new_path.present? end self end |
#query(params = {}) ⇒ Object
20 21 22 23 |
# File 'lib/tiny_client/url_builder.rb', line 20 def query(params = {}) @query.merge!(params) unless params.empty? self end |