Questions tagged [httparty]
HTTParty is a Ruby gem written by John Nunemaker focused on the consumption of web services and APIs.
610
questions
0
votes
0
answers
30
views
Rails: How to force all calls to any other api (most of them done via httparty) to use proxy
I am struggling to capture all api communication from my application to the 3rd party services via proxy (it is on 127.0.0.1:8888).
So far I tried adding to .env files
http_proxy="127.0.0.1:8888&...
0
votes
1
answer
49
views
Request returns 401 Unauthorized with headers using HTTParty
i can get response from API using curl like this:
curl -X GET https://myapi.com/... -H "client_id: my_id" -H "client_secret: my_secret"
but when i send requests with HTTParty:
...
0
votes
1
answer
37
views
How can I upload data via HTTParty in Ruby while generating it?
I have a function which generates some data. Right now, this data is written to a file. Once the file is complete, I upload it via HTTParty:
require 'httparty'
url = "..."
def ...
0
votes
1
answer
15
views
convert curl request in httparty
how to convert below curl request in httparty
curl --noproxy localhost -k -d '{"username":"admin", "password":"adminpass"}' -H "Content-Type: application/...
0
votes
0
answers
37
views
Scraping for Stathead - Missing table rows
I am trying to log into stathead and grab a table of data. When exploring the body of the html, it does not have the full table results. On a webpage, 100 rows are showing, but the html body only has ...
0
votes
1
answer
27
views
HTTParty post method doesn't return status code when adding follow_redirects = false along with other headers and cookies?
The HTTParty methods are like HTTParty.XXX(urlGoesHere, and Args Here)
I'm doing the following:
params = {:UserName => "uname", :Password => "pwd"}
cookie_hash = HTTParty::...
0
votes
0
answers
56
views
Ruby flexible client class with HTTParty
I usually use the Faraday gem to connect to the external API but I want to try HTTParty for my pure Ruby app. The idea is to build flexible client class, similar to this one from made with Faraday:
...
0
votes
0
answers
42
views
How to set image src from variable
i have following issue:
Calling and rendering an external image url from an api endpoint and setting this as an varibale.
The variable is then placed within in the view as <img src=<%= @image %&...
0
votes
2
answers
63
views
How to render content from nested json object in ruby on rails view
I'm trying to render data from a API response (JSON) into my view.
For some reason i only can access the toplevel objects withouth any issues. BUt my knowledge is limited when it commes to retrieve ...
0
votes
0
answers
17
views
HTTParty#lock seems to be overriding ActiveRecord’s #lock method
When trying to implement pessimistic locking on a Rails model, I'm not able to do so because HTTParty#lock gets called rather than the ActiveRecord method with the same name.
I'm using AR 6.1.4.1 and ...
0
votes
1
answer
100
views
Ruby on Rails APi call from Controller with too much logic. Where and how can I make it simpler?
I was asked to fetch the Pokemon API from Ruby on Rails. But I'm struggling because I have too much logic in the controller, which is not recommended. Where and how can I make the call so I have less ...
0
votes
1
answer
279
views
Rspec testing Httparty response
I have a definition like this
require 'httparty'
def distance_calculation
url = "https://api.distancematrix.ai/maps/api/distancematrix/json?origins=#
{@departure}&destinations=#{@...
1
vote
1
answer
40
views
Can I reduce duplication in the serialization of a ruby hash?
I have a hash of the format
{com: 1234, users: [{nid: 3, sets: [1,2,3,4]}, {nid: 4, sets: [5,6,7,8]}]}
which I am sending to a remote server. I am using the HTTParty gem to do this. The code looks ...
1
vote
1
answer
39
views
How to loop over HTTP response in Rails 6
I'm using HTTParty to get some information on the internet. I then loop over that response and print it.
Loop here:
<% @responses.each do |response| %>
<%= response %>
<% end %>
...
1
vote
2
answers
47
views
Passing different symbols as a parameter depending on the enviroment
I started learning ruby today and I'm having a hard time understanding symbols and how to use them properly.
Right now I'm working on a simple server and website, and when I'm testing on the remote ...
0
votes
0
answers
32
views
Nokogiri, HTTParty and Twitter
I'm trying to get the src image so that the bot posts on twitter, the title, description and the featured image rather than a link.
I searched everywhere in the Nokogiri doc and couldn't find an ...
0
votes
1
answer
34
views
How to get api data using api keys in httparty ruby
i have been trying to get the api data using httparty and been doing it like this
require 'httparty'
doc = HTTParty.get('http://ip-api.com/php/105.49.23.183')
puts doc['status']
The api response is
...
0
votes
1
answer
109
views
Find a url in a document using regex in ruby
I have been trying to find a url in a html document and this has to be done in regex since the url is not in any html tag so I can't use nokogiri for that. To get the html i used httparty and i did it ...
0
votes
0
answers
39
views
How to post a file from Rails app to a Python Flask API?
I would like to post a file from a rails app to flask API. I have httparty setup.
# Ruby
file = params[:signals]
response = HTTParty.post("http://127.0.0.1:5000/validate", body: { "data&...
0
votes
2
answers
167
views
Why is my Ruby function web scraping the first page only and not the paginated pages?
I am using nokogiri to web scrape all vehicles across about 14 pages in a dealership website, the bug I am encountering is my code is running the scraper 14 times on only the first page. What is wrong ...
0
votes
1
answer
242
views
Post request detected as bot with HTTPARTY but not with postman (same headers)
I am trying to fetch a public API. When I do it from the postman everything works fine however when I do it from my app I get and error message: <META NAME=\"robots\" CONTENT=\"...
0
votes
1
answer
65
views
Fastest Net::HTTP/Net::HTTPS wrapper for Ruby
What is the fastest way to download a webpage for parsing in Ruby? I've tried using open-uri and HTTParty both seem to take roughly about 25 seconds to download simple webpages (I've tried multiple ...
-1
votes
3
answers
52
views
Case conditional in ruby doesn't enter in when
My code when executed it's not entering in the when loop inside the case conditional.
What I wanted is to sen two different GET requests based on the *args of the function.
So I can validate the ...
0
votes
1
answer
207
views
Ruby Instagram API content-type Wrong
Trying to use Instagram's API and I'm getting a content-type of "text/html" returned instead of "application/json". Then, I'm having a problem coercing this into json.
require '...
1
vote
3
answers
1k
views
How to pass raw-data into post request using HTTParty (or any other way in ruby)
I have to make this request in rails 6:
curl --location --request POST 'https://www.example.com/auth' \
--header 'Content-Type: application/json' \
--data-raw '{
"Username": "...
2
votes
1
answer
48
views
Getting "undefined method `css' for nil:NilClass (NoMethodError)" with using HTTPparty & Nokogiri
I'm not sure what I'm doing wrong. I'm new to coding so it could be something very simple. I've looked around and can't find a solution. It's in the first line in self.scrape_mainpage function.
...
1
vote
0
answers
79
views
How can I scrape a Website with onClick event listener using Nokogiri
I am trying to scrape a website using Nokogiri and download documents thats are posted on the website. I can scrape other websites like this one: Matatiela Website and get the documents from it. But ...
2
votes
1
answer
353
views
Upload a file from ActiveStorage to an API
I'm trying to upload a file to an API with Httparty gem.
Here is the requested format, from the documentation of this API:
Method: POST
Content-Type: application/json
{
"name": "...
2
votes
2
answers
68
views
Limiting the number of threads to be executed
I am trying to limit the number of threads that must be executed simultaneously or to separate the elements of the array in a certain amount and send them separately (splice) but I have no idea where ...
1
vote
1
answer
413
views
Recreating postman post request in HTTParty with AWS signature
I have a custom API that needs to pass in an AWS access key, secret key, and region. I'm able to generate results from the post requests in Postman when I place these credentials in Authorization ...
0
votes
1
answer
143
views
Noob with HTTParty and parsing / accessing responses
So I am BRAND new to the world of hitting and parsing API's, Using postman, I have been able to hit the api and get the response back, containing the info I need.
this is what's returned as the ...
-1
votes
1
answer
147
views
A lot of warnings after require 'Time'
When i import Time and HTTParty i got these warnings:
C:/Ruby27-x64/lib/ruby/2.7.0/time.rb:34: warning: already initialized constant Class::ZoneOffset
C:/Ruby27-x64/lib/ruby/2.7.0/Time.rb:34: warning: ...
2
votes
2
answers
223
views
Reading Instagram JSON with Ruby Controller and passing to View, using HTTParty gem
I'm trying to learn processing JSON with Ruby. I went through quite a few tutorial but got confused even more, so I try to learn by doing it.
Here, I'm trying to get user's data from Instagram and ...
0
votes
0
answers
102
views
Nokogiri scraper not sourcing properly
I'm trying to build a scraper for a web page for data transfer, and hitting a sourcing issue.
require 'nokogiri'
require 'byebug'
require 'httparty'
require "open-uri"
def scraper
url = &...
0
votes
1
answer
211
views
Rails use of httparty to parse the JSON to external URL
In a Rails application, a user has to be redirected to an external site for external processing. The controller generates a valid JSON string and a set of headers:
@result = HTTParty.post(
"...
0
votes
4
answers
121
views
How would I parse JSON in Ruby to give me specific output
So I'm trying to make in Ruby so that it "Idk how to express myself" parse JSON from this API so the output is:
{"infected"=>19334, "deceased"=>429, "recovered&...
0
votes
1
answer
527
views
POST call to Intercom API using httparty does not work because the "Query body must contain a query hash"
I want to use httparty to make a POST call to the Intercom API in order to search for conversations following certain criteria.
I tested first in Postman and it works fine (see screenshot on the ...
0
votes
1
answer
69
views
HTTParty + JSON-LD Content-Type response
How do we deal with HTTP requests that accepts only 'application/ld+json'? I have simple GET request that accepts only application/ld+json Content-Type. Example code:
app.rb: (Sinatra server that ...
1
vote
0
answers
214
views
Replacement of HTTParty.send with Faraday
I am rails beginner working on a task to replace HTTParty with Faraday. So in codebase I call put/post/get based on the verb like so:
response = HTTParty.send(verb, url, http_options)
I am aware ...
0
votes
3
answers
180
views
How to extract data from dynamic collapsing table with hidden elements using Nokogiri and Ruby
I am trying to scrape through the following website :
https://www.cdc.gov/coronavirus/2019-ncov/cases-updates/cases-in-us.html
to get all of the state statistics on coronavirus.
My code below works:...
0
votes
2
answers
302
views
Inherit HTTParty module
How can I inherit HTTParty module to set some default values?
module SuperClient
include HTTParty
headers 'Auth' => 'Basic'
end
module ServiceApiClient
include SuperClient
headers 'X-...
2
votes
2
answers
1k
views
DEPRECATION: HTTParty will no longer override `response#nil?`. What does this Deprecation warning mean?
This question is probably poorly structured so please bear with me, I'm new at this.
I'm trying to build a simple web scraper but every time i run my code i get this warning in terminal. I have tried ...
0
votes
1
answer
324
views
Sending POST request with array in body with HTTParty
I'm trying to create new subscribers over the Buttondown API.
Docs here.
The api expects the following body:
{
"email": "string",
"notes": "string",
"referrer_url": "string",
"tags": [
"...
1
vote
2
answers
1k
views
Docker Ruby SSL_connect returned=1 errno=0 state=error: wrong signature type
I have ruby 2.7 in a Docker container running a rather simple HTTP client using Faraday:
conn = Faraday.new("https://jinio.com.ph")
conn.post("/tracker", {p: @code}.to_json, {"Content-Type" => "...
1
vote
1
answer
826
views
Request using HTTParty with API key
I am trying to make a GET request to this API, which works fine in POSTMAN. In my app I am using HTTParty to make the same request, and I am failing to structure the request correctly, resulting in a {...
0
votes
0
answers
125
views
HTTParty File Upload
I'm trying to upload a file to slack-channel using Ruby and when I do it through HTTParty, I get the error, while same options through rest-client gets it done. Is there any issue with HTTParty or am ...
0
votes
1
answer
394
views
Request with proxy getting blocked from web server but not on browser
I am trying to make a request to a website with a proxy using httparty like so:
def self.fetch_page_with_html_response(url, proxy_id)
proxy = Proxy.find(proxy_id)
request_options = {
...
1
vote
1
answer
2k
views
Rbenv wrong gem installation path - can't find gem
I'm having an issue with rbenv and what I believe is an issue is of require trying to read from my system gems rather than from shims.
I'm trying to create a single script file without the overhead ...
0
votes
1
answer
369
views
GET request with authorization header (with httparty or faraday)
I'm tring to use twitter api to fetch some data (Since https://github.com/sferik/twitter is not updaded anymore, some field that I need is left out)
I can get Postman working with fields that I ...