0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Abstract away the details of composing a URL with query parameters.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

 Project Readme

compose_url

compose_url is a Ruby class that abstracts away the details composing a URL with query paramters.

Usage

Instantiate compose_url by passing a base_url.

url = ComposeURL.new('http://api.com/1/a')

Include some initial query parameters either in the initial base_url or as a Hash. Or both at the same time.

url = ComposeURL.new('http://api.com/1/a', { 'foo' => 'bar', 'baz' => 'grault' })
url = ComposeURL.new('http://api.com/1/a?foo=bar&baz=grault')
url = ComposeURL.new('http://api.com/1/a?foo=bar', { 'baz' => 'grault' })

Add additional params to the resulting ComposeURL object.

url.add_param('a', 'b')

The @params Hash is accessible using Ruby’s attr_accessor, so it can be treated directly as a Hash.

url.params['c'] = 'd'
url.params.merge!({ 'e' => 'f' })

Remove a key value pair by calling remove_param on the key.

url.remove_param('a')

Retrieve your composed URL string by calling url or to_s.

url.to_s

Installation

Install as a gem.

gem install compose_url

Or add to your Gemfile and bundle install.

# Gemfile
gem "compose_url"
bundle install

Todo

History

  • v0.1.3 2014-12-20

    • Define dependencies in Gemspec
  • v0.1.2 2014-12-02

    • Fix bug where params could be escaped twice
    • Rely more on existing Ruby libraries
  • v0.1.1 2014-12-01

    • Parse out params in the initial base_url and add them to the @params hash
  • v0.1.0 2014-12-01

    • Initial release

Contributing

Open an Issue or bring a Rull Request!

License

Apache2