httparty

How would I parse JSON in Ruby to give me specific output

冷暖自知 提交于 2021-01-29 05:28:37
问题 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"=>14047, "tested"=>515395, "tested24hours"=>8393, "infected24hours"=>351, "deceased24hours"=>11, "sourceUrl"=>"https://covid19.rs/homepage-english/", "lastUpdatedAtApify"=>"2020-07-15T14:00:00.000Z", "readMe"=>"https://apify.com/krakorj/covid-serbia"} and I would like it to only show for example "infected"=>19334, as number 19334 I'm

How to test HTTParty API call with Ruby and RSpec

走远了吗. 提交于 2020-05-23 14:10:29
问题 I am using the HTTParty gem to make a call to the GitHub API to access a list of user's repos. It is a very simple application using Sinatra that displays a user's favourite programming language based on the most common language that appears in their repos. I am a bit stuck on how I can write an RSpec expectation that mocks out the actual API call and instead just checks that json data is being returned. I have a mock .json file but not sure how to use it in my test. Any ideas? github_api.rb

upload file to box api v2

五迷三道 提交于 2020-02-07 08:24:07
问题 i am trying to upload a file to box.com with their v2 api. i am able to successfully upload a file with curl, but cannot upload a file from my rails application. i am passing my upload function the correct folder id and file is a tempfile object created by a form upload in my app. here is the successful curl command curl https://upload.box.com/api/2.0/files/data -H "Authorization: BoxAuth api_key=API_KEY&auth_token=TOKEN" -F contract=@test.png -F folder_id=387656851 -ssl3 and here is my ruby

How to add headers to a httparty call

烂漫一生 提交于 2020-01-06 21:05:53
问题 Im trying to add headers to my api call Heres what i have tried at the moment api1 = HTTParty.get(URI.encode('apiurllink' + tmname + '&date=' + fromdate + ' TO ' + todate + '', :headers => {"Authorization" => "Bearer apikey"})).parsed_response This is returning this error TypeError: no implicit conversion of Hash into String How do I fix this? 回答1: Your attempt is raising a TypeError since you are passing the :headers => {"Authorization" => "Bearer apikey"} hash to URI.encode and not HTTParty

HTTParty to batch update users on MailChimp 3.0 API

半城伤御伤魂 提交于 2020-01-06 06:05:37
问题 I'm trying to use the batch API to add a new field to my list members. I'm able to post a batch request to the API and I receive a batch ID back. The batch request is accepted successfully but when I check the status of that job, I can see that is has failed: [{"status_code":404,"operation_id":null, "response":"{\"type\":\"http:\/\/developer.mailchimp.com\/documentation\/ mailchimp\/guides\/error-glossary\/\", \"title\":\"Resource Not Found\", \"status\":404, \"detail\":\"The requested

Login to a RESTful Rails app with HTTParty

萝らか妹 提交于 2020-01-05 12:09:17
问题 I have a web app with a clean RESTful JSON API, based on Rails 3.2 , Ruby 1.9 and Devise 2 . I would like to write a small script based on HTTParty web client in order to perform some actions frequently (with a crontab). But how can we sign in and keep the session open (with the session id passed by HTTP HEADER, and maybe stored in a cookie). I really have no experience about this aspect. 回答1: According to this mailing list comment as of January, may not be possible: https://groups.google.com

Using Postmates API in a rails app with HTTParty

隐身守侯 提交于 2020-01-04 14:20:59
问题 I've been working on integrating Postmates with my ecommerce rails application for on demand deliveries. I've built a controller and view for testing purposes and configured it in my routes file (built in my dev environment). For reference, here is the documentation from Postmates: docs and here is a technical blogpost: blog Routes file: resources :postmates do member do post 'get_delivery' end end The controller: require 'httparty' require 'json' class PostmatesController <

JSON Parsing Google API Custom Search Error

折月煮酒 提交于 2019-12-24 08:28:08
问题 I have the following code: require 'rubygems' require 'httparty' require 'pp' require 'json' class Search include HTTParty format :json end x = Search.get('https://www.googleapis.com/customsearch/v1key=AI...&cx=013...=flowers&alt=json') x = x.to_s result = JSON.parse(x) And every time I run it on the google search results that come back I get the following: FlowerPlaces.com Delivers Fresh <b>Flowers</b> To Your Place! <br> Order <b>Flowers</b> Online or Call 800-411-9049 for Same Day <b

How can I use HTTParty with UTF-8 encoding?

余生长醉 提交于 2019-12-24 04:32:28
问题 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 use HTTParty with UTF-8 encoding?

邮差的信 提交于 2019-12-24 04:32:09
问题 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