Welcome to the Typeform request gem! This gem is wrapper for the rest-client gem found at rubygems.org . It provides the following set of functions that makes it easier to access certain properties of each request.
Add this line to your application's Gemfile:
gem 'request', git: 'https://github.com/Typeform/ruby-request-gem.git'
Create a class to extend from
Request and implement a
success? method in this class. This method should assert certain attributes that you expect to be in the response of a successful request. For example, if I want to send a POST request that would return a 201 code and a JSON response if successful, then I could have a class that looks something like the following
class ExamplePostRequest < Request::Request def initialize(payload_to_send) request( method: :post, url: 'http://example.com/post, payload: payload_to_send ) end def success? @response.code == 201 && json? end end
Here I've created the constructor to send the request I want, and implemeneted the success method. This allows me to use the
execute method which will send the request and assert it was succesful. Of course you can make use of the
json function in the
success? method to check the contents of the response itself for a more thorough check.
After checking out the repo, run
bin/setup to install dependencies. You can also run
bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run
bundle exec rake install. To release a new version, update the version number in
version.rb, and then run
bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the
.gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/Typeform/ruby-request-gem .