Skip to content

Make external requests in you service objects, with easy logging and error handling!

License

Notifications You must be signed in to change notification settings

mtejedorwolox/wor-requests

 
 

Repository files navigation

Wolox on Rails - Requests

Gem Version Dependency Status Build Status Code Climate Test Coverage

Make external requests in you service objects, with easy logging and error handling!

Installation

Add this line to your application's Gemfile:

gem 'wor-requests'

And then execute:

$ bundle

Or install it yourself as:

$ gem install wor-requests

Then you can run rails generate wor:requests:install to create the initializer:

# config/initializers/wor_requests.rb

Wor::Requests.configure do |config|
  config.logger = Rails.logger
end

Usage

To write your first Service using Wor-requests you can write something like this:

require 'wor/requests'

class GithubService < Wor::Requests::Base
  def repositories(username)
    get(
      attempting_to: "get repositories of #{username}",
      path: "/users/#{username}/repos"
    )
  rescue Wor::Requests::RequestError => e
    puts e.message
  end

  protected

  def base_url
    'https://api.github.com'
  end
end

puts GithubService.new.repositories('alebian')

Or, even easier, run rails generate wor:requests:service NAME in your Rails root

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Run rubocop lint (rubocop -R --format simple)
  5. Run rspec tests (bundle exec rspec)
  6. Push your branch (git push origin my-new-feature)
  7. Create a new Pull Request

About

This project is maintained by Diego Raffo along with Michel Agopian and it was written by Wolox. Wolox

License

wor-requests is available under the MIT license.

Copyright (c) 2017 Wolox

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

About

Make external requests in you service objects, with easy logging and error handling!

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 98.5%
  • HTML 1.5%