wolox / wor-requests Goto Github PK
View Code? Open in Web Editor NEWMake external requests in you service objects, with easy logging and error handling!
Home Page: https://wolox.github.io/wor-requests/
License: MIT License
Make external requests in you service objects, with easy logging and error handling!
Home Page: https://wolox.github.io/wor-requests/
License: MIT License
Whenever you receive an empty body as a response, the json parser fails to decode the response.
Will be useful to be able to select different parsers for different services. For example json parser, xml parser, raw_parser (doesn't parse at all)
It isn't clear how to use headers, body and query params right now
We should be aware that if you want to make a post request with HTTParty with a body like the following:
{
values: [{some_attr: some_value1, another_attr: another_value1},
{some_attr: some_value2, another_attr: another_value2},
{some_attr: some_value3, another_attr: another_value3}]
}
HTTParty transforms it in the following:
{
values: [{some_attr: [some_value1, some_value1, some_value1]},
{another_attr: [another_value1, another_value2, another_value3]}]
}
There is a possible fix here:
https://stackoverflow.com/questions/21856373/sending-array-variables-using-httparty
When the base_url method is defined, but the string is not defined (it has an empty string) it returns this error:
undefined method
[]' for nil:NilClass`
It should return a more descriptive error message.
if we send an array in the body, the resulting body is translated to
{ dody: array_param[]=value1, array_param[]=value2, .... etc }
It shoud be converted to_json manualy before it gets to httparty
On lines 15 and 17, it says requets instead of requests.
File: https://github.com/Wolox/wor-requests/blob/master/spec/wor/generators/install_generator_spec.rb
There is a problem when we combine the base url with the path, when URI joins them it deletes the path included in the base url.
Example:
base_url = http://someurl.com/v1/
path = users/some_method
URI.join base_url, path returns -----> http://someurl.com/users/some_method (deletes the v1)
According to the RFC, GET and DELETE methods do not receive a body. The gem simply ignores if the user sends a body in the request, I think it should raise an error when this happens, because it will save the user time debugging
The request logs appear during the rspec run.
The requests are stubbed to return specific response with webmock
▶ rspec .
Randomized with seed 46047
[rspec-sidekiq] WARNING! Sidekiq will *NOT* process jobs in this environment. See https://github.com/philostler/rspec-sidekiq/wiki/FAQ-&-Troubleshooting
...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................I, [2017-12-29T11:58:17.632939 #5087] INFO -- : ATTEMPTING TO: get admin token
E, [2017-12-29T11:58:17.635055 #5087] ERROR -- : ERROR when trying to get admin token. Got status code: 500.
.I, [2017-12-29T11:58:17.670625 #5087] INFO -- : ATTEMPTING TO: get admin token
I, [2017-12-29T11:58:17.672560 #5087] INFO -- : SUCCESS: get admin token
I, [2017-12-29T11:58:17.673180 #5087] INFO -- : ATTEMPTING TO: register vehicle 556
E, [2017-12-29T11:58:17.674881 #5087] ERROR -- : ERROR when trying to register vehicle 556. Got status code: 500.
.I, [2017-12-29T11:58:17.704330 #5087] INFO -- : ATTEMPTING TO: get admin token
I, [2017-12-29T11:58:17.706026 #5087] INFO -- : SUCCESS: get admin token
I, [2017-12-29T11:58:17.706157 #5087] INFO -- : ATTEMPTING TO: register vehicle 557
I, [2017-12-29T11:58:17.707024 #5087] INFO -- : SUCCESS: register vehicle 557
.I, [2017-12-29T11:58:17.744163 #5087] INFO -- : ATTEMPTING TO: get admin token
I, [2017-12-29T11:58:17.745895 #5087] INFO -- : SUCCESS: get admin token
I, [2017-12-29T11:58:17.746018 #5087] INFO -- : ATTEMPTING TO: register vehicle 558
I, [2017-12-29T11:58:17.746900 #5087] INFO -- : SUCCESS: register vehicle 558
.I, [2017-12-29T11:58:17.781548 #5087] INFO -- : ATTEMPTING TO: get admin token
I, [2017-12-29T11:58:17.783540 #5087] INFO -- : SUCCESS: get admin token
I, [2017-12-29T11:58:17.783714 #5087] INFO -- : ATTEMPTING TO: register vehicle 559
I, [2017-12-29T11:58:17.784725 #5087] INFO -- : SUCCESS: register vehicle 559
.I, [2017-12-29T11:58:17.822138 #5087] INFO -- : ATTEMPTING TO: get admin token
I, [2017-12-29T11:58:17.823979 #5087] INFO -- : SUCCESS: get admin token
I, [2017-12-29T11:58:17.824119 #5087] INFO -- : ATTEMPTING TO: register vehicle 560
I, [2017-12-29T11:58:17.825087 #5087] INFO -- : SUCCESS: register vehicle 560
.........................................................................................................................................................................................................................................................................................................................................................................................................................................
Currently we need to do something like this to access the headers instead of the eample in the readme
require 'wor-requests'
require 'pry'
class GithubService < Wor::Requests::Base
def repositories(username, &block)
get(
attempting_to: "get repositories of #{username}",
path: "/users/#{username}/repos", &block)
rescue Wor::Requests::RequestError => e
puts e.message
end
private
def base_url
'https://api.github.com'
end
end
GithubService.new.repositories('alebian') do |r|
puts response.headers
end
Would be great to have this in some place in the readme or in a wiki :P
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.