Class: TinyClient::UrlBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/tiny_client/url_builder.rb

Overview

Convenient class used to build a request URL.

Constant Summary

SEPARATOR =
'/'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#query(params = {}) ⇒ Object



18
19
20
21
# File 'lib/tiny_client/url_builder.rb', line 18

def query(params = {})
  @query.merge!(params) unless params.empty?
  self
end

Class Method Details

.url(url) ⇒ Object



9
10
11
# File 'lib/tiny_client/url_builder.rb', line 9

def self.url(url)
  new(url)
end

Instance Method Details

#build!Object



23
24
25
26
# 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) ⇒ Object



13
14
15
16
# File 'lib/tiny_client/url_builder.rb', line 13

def path(path)
  @path << path unless path.blank?
  self
end