Module: Simple::HTTP::Helpers

Included in:
Simple::HTTP
Defined in:
lib/simple/http/helpers.rb

Instance Method Summary collapse

Instance Method Details

#build_url(base, *args) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/simple/http/helpers.rb', line 2

def build_url(base, *args)
  option_args, string_args = args.partition { |arg| arg.is_a?(Hash) }
  options = option_args.inject({}) { |hsh, option| hsh.update option }

  url = File.join([base] + string_args)

  query = build_query(options)
  url += url.index("?") ? "&#{query}" : "?#{query}" if query

  url
end