httparty

How can I use HTTParty with UTF-8 encoding?

房东的猫 提交于 2019-12-24 04:32:08
问题 I have a URL like http://example.com/tag/София/new.json and I want to make a GET request with HTTParty. When I do: HTTPArty.get "http://example.com/tag/София/new.json I get: URI::InvalidURIError at / bad URI(is not URI?): link here Any ideas how to handle this ? 回答1: The standard says "encode the URL as UTF-8, then represent multi-byte sequences as percent-escaped octets." In your case, http://example.com/tag/%D0%A1%D0%BE%D1%84%D0%B8%D1%8F/new.json 来源: https://stackoverflow.com/questions

How can I finish CRUD from API? I have questions on PUT [closed]

最后都变了- 提交于 2019-12-20 07:47:31
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed yesterday . I need to generate a put but I don't know how to pass the parameters to update the name, salary or age from Gem Faker. How to upgrade from GEM faker or any even fixed value? I tried but could not. require 'HTTParty' require 'httparty/request' require 'httparty/response/headers' #require_relative '..

'Nesting too deep' error while retrieving JSON using HTTParty

旧街凉风 提交于 2019-12-19 09:15:16
问题 I am writing a very simple proxy wrapper for the reddit api so I can make cross domain JSONP requests (reddit does not allow JSONP calls to my knowledge). I am using the HTTParty gem to make the call out and retrieve the response, which I immediately render out as json. I am retrieving the subreddit json perfectly fine so far with this as my route: match "r/:name" => "api#subreddit" ... and this as my controller action: def subreddit render :json => HTTParty.get("http://www.reddit.com/r/" +

How can I handle errors with HTTParty?

霸气de小男生 提交于 2019-12-18 10:19:26
问题 I'm working on a Rails application using HTTParty to make HTTP requests. How can I handle HTTP errors with HTTParty? Specifically, I need to catch HTTP 502 & 503 and other errors like connection refused and timeout errors. 回答1: An instance of HTTParty::Response has a code attribute which contains the status code of the HTTP response. It's given as an integer. So, something like this: response = HTTParty.get('http://twitter.com/statuses/public_timeline.json') case response.code when 200 puts

POSTing large amounts of data with HTTParty

99封情书 提交于 2019-12-18 09:05:18
问题 I'm using HTTParty to post information to a server using the following code: this_component = {"name" => "something", "ip" => "localhost", "logs" => logs_to_push} payload = {"payload" => JSON.dump(this_component)} response = JSONClient.post("http://localhost:8080/log", :body => '', :query => payload) The problem is that I get a Connection reset by peer (Errno::ECONNRESET) message when the POST actually executes, which I'm pretty sure is caused by my payload being too large (as logs_to_push is

Passing headers and query params in HTTparty

主宰稳场 提交于 2019-12-17 22:38:30
问题 How to pass query params and headers in post method using HTTparty. I am doing as follows But it throws query = {:method => "neworder", :nonce => 1404996028, :order_type => "buy", :quantity=>1,:rate=>1} headers = {:key=> "87819747209090199871234", :sign=> "0a3888ac7f8e411ad73a0a503c55db70a291rsf34bfb9f9a47147d5200882674f717f6ede475669f3453"} HTTParty.post("https://www.acb.com/api/v2/market/LTC_BTC/", :query => query, :headers => headers ) But it throws the following error. How to handle query

POST JSON to API using Rails and HTTParty

假如想象 提交于 2019-12-17 08:06:17
问题 I would like for a user within my ruby on rails app to be able to submit a ticket to my external ticket management system, squishlist.com. They have an api and instructions as follows. You need to authenticate and get a token and then submit the ticket with the token. From squishlist. # get the token https://api.squishlist.com/auth/?cfg=testcorp&user_key=privatekey&api_key=TEST-KEY-12345 => {"token": "authtoken", "expires": "2010-06-16 13:31:56"} # and then the ticket with the token https:/

Getting/setting session with HTTParty

核能气质少年 提交于 2019-12-14 03:59:47
问题 Using HTTParty, I'm able to read some pages fine, other on the same site strangely give a 404 unless I set the proper session headers. So I'm trying to get and set them via HTTParty. This works: HTTParty.get 'https://www.instagram.com/explore/locations/24993086/pfriem-family-brewers/' This gives a 404: HTTParty.get 'https://www.instagram.com/explore/locations/295648950/trio-salon-spa/' Curl also gives a 404 for that: url -I https://www.instagram.com/explore/locations/295648950/trio-salon-spa/

Ruby no method error with HTTParty

风格不统一 提交于 2019-12-13 04:53:12
问题 I am trying to make a post request in Ruby and I am getting inconsistent behaviour. I am currently using ruby-2.0.0-p598 on OSX. When using PRY and I type the following post command: HTTParty.post(@base_uri + '/method/?argument1&api_key=' + @api_key) I get a successful respond from the API. However when I run it through my specs or inside the class I get: undefined method `+' for nil:NilClass I know it has to do with the plus sign, but I find it weird that I am getting a different behaviour.

in `require': cannot load such file — httparty (LoadError)

。_饼干妹妹 提交于 2019-12-12 22:16:36
问题 My default ruby is 2.0.0p384. A ruby script has: #!/usr/bin/env ruby require 'rubygems' require 'httparty' If the above header is changed to: #!/usr/bin/ruby1.9.1 the script runs fine. /var/lib/gems/2.0.0/gems/httparty-0.13.5 exists. I can't understand why running the script with the 2.0.0 ruby gives: /usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53:in require': cannot load such file -- httparty (LoadError) from usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53:in require'