Tag: httparty

如何使用httparty for rails 3解析og元标记

我试图使用此代码使用HTTParty gem解析og元标记: link = http://www.usatoday.com/story/gameon/2013/01/08/nfl-jets-tony-sparano-fired/1817037/ # link = http://news.yahoo.com/chicago-lottery-winners-death-ruled-homicide-181627271.html resp = HTTParty.get(link) ret_body = resp.body # title og_title = ret_body.match(/\/) og_title = og_title[1].to_s 问题是它在一些网站上工作(雅虎!)而不是其他网站(今天的美国)

有人可以提供一个如何使用HTTParty和Ruby on Rails发布XML的示例吗?

我需要将一些xml发布到web服务,我正在尝试使用HTTParty。 有人可以提供一个关于我如何这样做的例子吗? 以下是我需要发布的XML格式: 到目前为止,这是我的class级: require ‘httparty’ class Webservice include HTTParty format :xml base_uri ‘mysite.com’ default_params :authorization => ‘xxxxxxx’ def self.add_candidate(first_name,last_name,email,gender) post(‘/test.xml’, :body => “”) end end 我不太确定如何充实add_candidate。 任何帮助,将不胜感激。 谢谢。

HTTParty解析Rails中的JSON

我有一个URL,显示400个YMCA位置的JSON保留信息。 我的目标是能够为每个位置提取纬度和经度,以便在地图上显示点。 我正在玩HTTParty,只是想在视图中只显示纬度和经度。 这是我的控制器: require ‘rubygems’ require ‘httparty’ class HomesController < ApplicationController include HTTParty def index uri = HTTParty.get"http://www.livestrong.org/we-can-help/ymca.json" @place = JSON.parse(uri.body) end end 以下是观点: 到目前为止,这将显示屏幕上的所有JSON。 如何挑选各个零件?

使用HTTParty登录RESTful Rails应用程序

我有一个基于Rails 3.2 , Ruby 1.9和Devise 2的干净RESTful JSON API的Web应用程序。 我想编写一个基于HTTParty Web客户端的小脚本,以便经常执行某些操作(使用crontab)。 但是我们如何登录并保持会话打开(会话ID由HTTP HEADER传递,并且可能存储在cookie中)。 我真的没有这方面的经验。

Strange Timeout :: Controller Action中的render_to_string和HTTParty出错

在我的控制器操作中,我使用带有jbuilder模板的render_to_string来向API呈现http post操作的对象,此API-Call的结果应该由控制器呈现。 但是我得到一个奇怪的超时然后我通过render_to_string渲染模型后调用HTTParty。 日志: [23:43:52.262] [18033] [info] Rendered admin/companies/companies.json.jbuilder (42.8ms) … nothing happens here (60s timeout) [23:44:52.314] [18033] [info] Completed 500 Internal Server Error in 60338ms [23:44:52.342] [18033] [fatal] Timeout::Error (Timeout::Error): app/controllers/admin/companies_controller.rb:135:in `copy_to_environment’ lib/middleware/x_domain_request_polyfill.rb:46:in `_call’ lib/middleware/x_domain_request_polyfill.rb:16:in `call’ [23:44:52.422] [18033] [info] Started POST “/api/v1/internal/company/create_company_copy.json” for 127.0.0.1 at 2013-05-26 23:44:52 +0200 [23:44:52.465] [18033] [info] Processing by Api::V1::Internal::CompaniesController#create_company_copy […]

Rails HTTParty获取超时::错误

我有一个以API为中心的应用程序(/ api / v1 / users),它只是简单地以JSON格式返回所有用户。 我的问题是,如果我在控制器上调用该路由,它返回“Timeout :: Error”有什么问题? class BaseController < ApplicationController def index return HTTParty.get('http://localhost:3000/api/v1/users').body end end 更新 users_controller.rb(/ api / v1 / users) application_controller.rb https://gist.github.com/4359591 日志 http://pastie.org/5565618

使用HTTParty将Content-Type更改为JSON

我正在尝试使用Ruby on Rails与Salesforce API进行通信。 我可以轻松地获取数据,但我在将数据发布到服务器时遇到问题。 我按照Quinton Wall的post使用HTTParty: https://github.com/quintonwall/omniauth-rails3-forcedotcom/wiki/Build-Mobile-Apps-in-the-Cloud-with-Omniauth,-Httparty-and-Force.com 但我似乎能够从salesforce服务器获得的是我以html身份提交正文的错误 {“message”=>“此资源不支持’application / x-www-form-urlencoded’的MediaType”,“errorCode”=>“UNSUPPORTED_MEDIA_TYPE”} 负责的代码如下: require ‘rubygems’ require ‘httparty’ class Accounts include HTTParty format :json …[set headers and root_url etc] def self.save Accounts.set_headers response = (post(Accounts.root_url+”/sobjects/Account/”, :body => {:name => “graham”}.to_json)) end end 任何人都知道为什么身体应该被发布为html以及如何更改它以便它肯定像json一样,以便salesforce不拒绝它? 任何帮助,将不胜感激。 干杯

使用HTTParty捕获特定请求

我想在不使用代理的情况下捕获给定操作的完整请求(raw_request – 线路上的内容)。 我知道Class上的debug_output方法,这可能是解决方案的一部分。 但不清楚如何根据每个请求设置它。 考虑以下 … @response = HTTParty.post(@job.callback_url, body: @job.to_json) notification = Notification.new notification.response_body = @response.body notification.response_code = @response.code notification.request_body = ???? 谢谢! 乔纳森

将文件上传到box api v2

我正在尝试使用他们的v2 api将文件上传到box.com。 我能够成功上传curl文件,但无法从我的rails应用程序上传文件。 我正在传递我的上传function正确的文件夹ID和文件是由我的应用程序中的表单上传创建的临时文件对象。 这是成功的curl命令 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 这是我的ruby代码 class BoxApi require ‘httmultiparty’ include HTTMultiParty ssl_version :SSLv3 def initialize @key = API_KEY @token = TOKEN end def upload_file(folder_id,file,filename,content_type) File.open(file) do |open_file| response = self.class.post(‘https://upload.box.com/2.0/files/data’, :query => { :file => open_file, :folder_id => folder_id }, :headers => {‘Authorization’ […]

JSON解析Google API自定义搜索错误

我有以下代码: 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) 每次我在谷歌搜索结果上运行它,我得到以下内容: FlowerPlaces.com Delivers Fresh Flowers To Your Place! Order Flowers Online or Call 800-411-9049 for Same Day Flower Delivery.”, “cacheId”=>”v94CIDza4gQJ”}]}’ (JSON::ParserError) from /usr/local/lib/ruby/1.9.1/json/common.rb:148:in `parse’ from gg.rb:15:in `’ 这是JSON试图解析的字符串版本中的同一行: Order Flowers […]