我一直在努力将Postmates与我的电子商务rails应用程序集成,以便按需交付.我已经为测试目的构建了一个控制器和视图,并在我的路径文件中构建它(在我的开发环境中构建).作为参考,这里是Postmates的文档:docs,这是一个技术博客:博客
路线文件:
resources :postmates do
member do
post 'get_delivery'
end
end
Run Code Online (Sandbox Code Playgroud)
控制器:
require 'httparty'
require 'json'
class PostmatesController < ApplicationController
def get_delivery
api_key = **hidden**
@customer = 'cus_K8mRn4ovuNyNKV'
@urlstring_to_post = 'https://api.postmates.com/v1/customers/' + @customer + '/delivery_quotes'
@result = HTTParty.post(@urlstring_to_post.to_str,
:body => { :dropoff_address => "205 E 95th Street, New York, NY 10128",
:pickup_address => "619 W 54th St, New York, NY 10019"
}.to_json,
:basic_auth => { :username => api_key },
:headers => { 'Content-Type' => 'application/json' })
end …Run Code Online (Sandbox Code Playgroud)