Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wolox/wor-requests
Make external requests in you service objects, with easy logging and error handling!
https://github.com/wolox/wor-requests
api rails requests ruby ruby-gem services wolox wor
Last synced: 5 days ago
JSON representation
Make external requests in you service objects, with easy logging and error handling!
- Host: GitHub
- URL: https://github.com/wolox/wor-requests
- Owner: Wolox
- License: mit
- Created: 2017-03-03T18:03:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-02-12T20:01:19.000Z (almost 5 years ago)
- Last Synced: 2024-11-09T02:22:01.197Z (5 days ago)
- Topics: api, rails, requests, ruby, ruby-gem, services, wolox, wor
- Language: Ruby
- Homepage: https://wolox.github.io/wor-requests/
- Size: 102 KB
- Stars: 12
- Watchers: 28
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Wolox on Rails - Requests
[![Gem Version](https://badge.fury.io/rb/wor-requests.svg)](https://badge.fury.io/rb/wor-requests)
[![Build Status](https://travis-ci.org/Wolox/wor-requests.svg)](https://travis-ci.org/Wolox/wor-requests)
[![Code Climate](https://codeclimate.com/github/Wolox/wor-requests/badges/gpa.svg)](https://codeclimate.com/github/Wolox/wor-requests)Make external requests in you service objects, with easy logging and error handling!
## Installation
Add this line to your application's Gemfile:
```ruby
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:
```ruby
# config/initializers/wor_requests.rbWor::Requests.configure do |config|
config.logger = Rails.logger
end
```## Generators
```ruby
rails generate wor:requests:service NAME
```### Generator options
#### module
Specifying the module name as:```ruby
rails generate wor:requests:service NAME --module MODULE_NAME
```
We can create a service with an inner class called NAME, and external module called MODULE_NAME```ruby
module ModuleName
class NameService < Wor::Requests::Base
# Your code here
end
end
```## Service example
To write your first Service using Wor-requests you can write something like this:```ruby
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
endprotected
def base_url
'https://api.github.com'
end
endputs GithubService.new.repositories('wolox')
```If you need to get the response headers, add a block in the call with the headers output
```ruby
GithubService.new.repositories('wolox') do |response|
puts response.headers
end
```If you need to send body parameters in a post request you can write something like this:
```ruby
require 'wor/requests'class ExternalService < Wor::Requests::Base
def post_request_example(authorization)
post(
attempting_to: 'Make a POST request to an external service.',
path: '/some_endpoint',
headers: {
Authorization: authorization,
'Content-type' => 'application/json'
},
body: {
# Some Json
}
)
endprotected
def base_url
'https://external.service.com'
end
endExternalService.new.post_request_example(token)
```## 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 was developed by [Diego Raffo](https://github.com/enanodr) along with [Michel Agopian](https://github.com/mishuagopian) and it was written by [Wolox](http://www.wolox.com.ar).Maintainers: [Samir Tapiero](https://github.com/blacksam07)
Contributors: [Diego Raffo](https://github.com/enanodr) [Michel Agopian](https://github.com/mishuagopian)
![Wolox](https://raw.githubusercontent.com/Wolox/press-kit/master/logos/logo_banner.png)
## License
**wor-requests** is available under the MIT [license](https://raw.githubusercontent.com/Wolox/wor-requests/master/LICENSE.md).
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.