UriSigner
The KISSmetrics API provides an authentication realm of a digital signature of the request. This gem helps to put the pieces together and construct the URL with the signature.
This is used within the core KISSmetrics Ruby API Wrapper to help abstract the building of the requests.
Using this without a wrapper will require you to manually provide your client_secret.
Installation
Add this line to your application's Gemfile:
gem 'uri_signer'
And then execute:
$ bundle
Or install it yourself as:
$ gem install uri_signer
Usage
At any point, you can use the reload_yard
command to view the
documentation of the provided code. The basic usage is:
http_method = 'get'
uri = "https://api.example.com/v1/endpoint.json?page=2&per_page=12&order=name:desc&select=id,name"
secret = "my_secret"
signer = UriSigner::Signer.new(http_method, uri, secret)
=> #<UriSigner::Signer:0x007fd84ebf5490 @http_method="get", @uri="https://api.example.com/v1/endpoint.json?page=2&per_page=12&order=name:desc&select=id,name", @secret="my_secret">
signer.http_method
=> "GET"
signer.uri
=> "https://api.example.com/v1/endpoint.json?page=2&per_page=12&order=name:desc&select=id,name"
signer.signature
=> "Itt0xvD1ZAHHXP2ItX6PeXMfjOovr8MVgbpoXpq3158%3D"
signer.uri_with_signature
=> "https://api.example.com/v1/endpoint.json?page=2&per_page=12&order=name:desc&select=id,name&_signature=Itt0xvD1ZAHHXP2ItX6PeXMfjOovr8MVgbpoXpq3158%3D"
signer.valid?('Itt0xvD1ZAHHXP2ItX6PeXMfjOovr8MVgbpoXpq3158%3D')
=> true
signer.valid?('invalid')
=> false
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request