Project

web_client

0.0
No commit activity in last 3 years
No release in over 3 years
Net::HTTP wrapper easy to use
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
 Project Readme

WebClient

Gem Version Build Status Coverage Status Code Climate Dependency Status

Net::HTTP wrapper easy to use

Installation

Add this line to your application's Gemfile:

gem 'web_client'

And then execute:

$ bundle

Or install it yourself as:

$ gem install web_client

Usage

Connection initialization

connection = WebClient::Connection.new 'localhost', 3000
#or
connection = WebClient::Connection.new host: 'localhost', port: 3000

Request types

connection.get '/users'
connection.get '/users/123', headers: {content_type: 'application/json'}
connection.post '/users', body: '...'
connection.put '/users/123', body: '...'
connection.delete '/users/123'

Raising request exceptions

connection.get url #=> nil
connection.get! url #=> raise WebClient::Error

Response info

response = connection.get url
response.code #=> 200
response.body #=> '....'
response.success? #=> true
response.type #=> Net::HTTPOK

Success block

json = connection.get url do |response|
  JSON.parse response.body
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request