Class: Patreon::Utils::JSONAPI::URLUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/patreon/utils/jsonapi/url_util.rb

Class Method Summary collapse

Class Method Details

.build_url(url, includes = nil, fields = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/patreon/utils/jsonapi/url_util.rb', line 8

def self.build_url(url, includes=nil, fields=nil)
  parsed_url = URI.parse(url)
  params = parsed_url.query ? Rack::Utils.parse_query(parsed_url.query) : {}
  params['include'] = joined_or_null(includes) if includes
  fields.each do |name, val|
    params["fields[#{name}]"] = val
  end if fields
  query = params.empty? ? "" : "?#{Rack::Utils.build_query(params)}"

  "#{parsed_url.path}#{query}"
end