【发布时间】:2017-03-05 18:20:45
【问题描述】:
我是 Ruby 新手,正在尝试使用 Ruby gem 'rest-client' 来访问我的会计系统 e-conomic.com 的 REST API。我可以通过令牌连接,例如获取客户详细信息 - 到目前为止,一切都很好。
但是,我正在努力弄清楚如何发布,从而创建一个新的客户条目,例如地址、姓名、邮件等。特别是,我希望代码既包含我的身份验证令牌详细信息(即下面的 hHeader 内容),又包含客户详细信息的有效负载。
有关通过 REST API 创建客户的详细信息: https://restdocs.e-conomic.com/#post-customer-groups
关于 rest-client ruby gem 的详细信息: https://github.com/rest-client/rest-client
我在 Windows 7 上的 Atom 编辑器中运行 Ruby 2.3.3。 我的代码如下:
Dir.chdir 'C:\Ruby23\bin'
require 'rest-client'
require 'rconomic'
require 'json'
hHeader = {"X-AppSecretToken" => 'tokenID1_sanitized', "X-AgreementGrantToken" => 'tokenID2_sanitized', "Content-Type" => 'application/json'}
hCustomer = RestClient.get("https://restapi.e-conomic.com/customers/5", hHeader) # => creates a response showing customer 5 (shown for example of GET)
您的意见将不胜感激!
马丁
【问题讨论】:
标签: ruby rest post rest-client