2017-07-20 86 views
0

我有一個測試應用程序,用Ruby on Rails編寫,並且對於ngrok IP可見。我創建了一個沙箱控制器,只需點擊一下按鈕即可更改沙箱旅程的狀態。優步API webhooks requests.status_changed沒有解僱,webhooks requests.receipt_ready都是

直到今天(在演示過程中,它已經在25分鐘前工作過了),它將webhook事件發佈到我的ngrok IP,用於每次狀態更改,類型爲requests.status_changed。目前,如果我將處理過程更改爲「接受」,「到達」或「in_progress」,我會從沙箱中收到適當的回覆,但不會創建任何webhook。如果我將車輛更改爲「driver_canceled」或「completed」,我會收到requests.receipt_ready webhook事件。 (編輯:我在以下顯示的代碼),但因爲a)我從沙盒上得到了狀態改變的正確答案(雖然沒有webhook帖子),並且b)我得到接收通知網絡掛接的帖子,我認爲:

  • 我正常談話的沙箱
  • 我沒有一個網絡或防火牆的問題阻止網絡掛接到達我的服務器

我依賴於status_changed webhooks給我通知我需要採取額外的行動。這些事情是否還在發生,還是有一些我應該關注的事情來確定這些失敗的原因?


更新:

我在Rails中這樣做。我使用了一個名爲UberConnection連接類,這主要是HTTParty:

class UberConnection 
    include HTTParty 
    base_uri 'https://sandbox-api.uber.com/v1.2' 
    headers "Accept-Language" => "en_US", "Content-Type" => 
    "application/json" 
    debug_output $stdout 
end 

我用ngrok爲網絡掛接得到一個公開的姓名。我有我的webhook配置爲偵聽event_type =「requests.status_changed」的事件。他們創造UberEvent ActiveRecord對象和重複檢查或不匹配的ACTIVE_EVENTS列表過濾事件:

ACTIVE_EVENTS = ["requests.status_changed"] 

if (!UberEvent.where(event_id: params["event_id"]).blank? || !ACTIVE_EVENTS.include?(params["event_type"])) 
    Rails.logger.debug("Ignoring duplicate or filtered notice") 
    return head :ok 
end 

我也有一個沙箱控制器,將改變正在進行的乘坐狀態,所以我可以模擬出騎生命週期:

def ops_accepted 
    UberConnection.put("/sandbox/requests/#{params[:ride_id]}", 
    headers: {"Authorization" => "Bearer #{Uber.token}"}, 
    body: {status: "accepted"}.to_json) 
    flash[:notice] = "Changed ride to Accepted" 
    redirect_to action: :operator 
end 

以及類似的其他生命週期類型。

預期行爲 一旦我安排的平順性和它的加工狀態,我應該能夠打的火災ops_accepted按鈕和已更改爲接受的旅程。這應該會引發webhook事件觸發,指示狀態已更改,並且我可以基於此進行其他操作。

實際行爲 除webhook事件之外的所有事情都會觸發。

提交新的換乘

Started GET "/sandbox" for 2600:1005:b06a:1a83:9818:4356:ceda:ca11 at 2017-07-26 08:35:46 -0400 
Cannot render console from 2600:1005:b06a:1a83:9818:4356:ceda:ca11! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 
Processing by WebhooksController#operator as HTML 
    Uber Load (0.1ms) SELECT "ubers".* FROM "ubers" ORDER BY "ubers"."id" ASC LIMIT ? [["LIMIT", 1]] 
opening connection to sandbox-api.uber.com:443... 
opened 
starting SSL for sandbox-api.uber.com:443... 
SSL established 
<- "GET /v1.2/requests/current HTTP/1.1\r\nAccept-Language: en_US\r\nContent-Type: application/json\r\nAuthorization: Bearer [TOKEN REDACTED]\r\nConnection: close\r\nHost: sandbox-api.uber.com\r\n\r\n" 
-> "HTTP/1.1 200 OK\r\n" 
-> "Server: nginx\r\n" 
-> "Date: Wed, 26 Jul 2017 12:35:45 GMT\r\n" 
-> "Content-Type: application/json\r\n" 
-> "Content-Length: 431\r\n" 
-> "Connection: close\r\n" 
-> "Content-Geo-System: wgs-84\r\n" 
-> "Content-Language: en\r\n" 
-> "Etag: W/\"e9fda87d668bbe0f46ec27d8557b110b03c8c422\"\r\n" 
-> "X-Uber-App: uberex-sandbox\r\n" 
-> "X-Uber-App: optimus\r\n" 
-> "Strict-Transport-Security: max-age=604800\r\n" 
-> "X-Content-Type-Options: nosniff\r\n" 
-> "X-XSS-Protection: 1; mode=block\r\n" 
-> "Strict-Transport-Security: max-age=2592000\r\n" 
-> "X-Frame-Options: SAMEORIGIN\r\n" 
-> "Cache-Control: max-age=0\r\n" 
-> "\r\n" 
reading 431 bytes... 
-> "{\"status\":\"processing\",\"product_id\":\"6d898741-0175-4c71-ad5f-93fc66270d6a\",\"destination\":{\"latitude\":33.754177,\"longitude\":-84.371736},\"driver\":null,\"pickup\":{\"latitude\":33.7539854,\"region\":{\"latitude\":33.7489,\"country_name\":\"United States\",\"country_code\":\"US\",\"name\":\"Atlanta\",\"longitude\":-84.3881},\"eta\":6,\"longitude\":-84.3755874},\"request_id\":\"f14877e5-f060-4c4a-be91-bb66866238b9\",\"location\":null,\"vehicle\":null,\"shared\":false}" 
read 431 bytes 
Conn close 
    Rendering webhooks/operator.html.erb within layouts/application 
    Rendered webhooks/operator.html.erb within layouts/application (1.6ms) 
Completed 200 OK in 795ms (Views: 27.9ms | ActiveRecord: 0.1ms) 

更改爲接受

Started PUT "/webhooks/accept/f14877e5-f060-4c4a-be91-bb66866238b9" for 2600:1005:b06a:1a83:9818:4356:ceda:ca11 at 2017-07-26 08:48:22 -0400 
Cannot render console from 2600:1005:b06a:1a83:9818:4356:ceda:ca11! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 
Processing by WebhooksController#ops_accepted as HTML 
    Parameters: {"authenticity_token"=>"PIHCTPkaOpa8RrsvT4D+TF0PR1UvY8uukh9SC2MRw1o5StFZYo0PNtn1g0W6QQh/2f7/hQSDSVVy8CMLJv/GYg==", "ride_id"=>"f14877e5-f060-4c4a-be91-bb66866238b9"} 
    Uber Load (0.2ms) SELECT "ubers".* FROM "ubers" ORDER BY "ubers"."id" ASC LIMIT ? [["LIMIT", 1]] 
opening connection to sandbox-api.uber.com:443... 
opened 
starting SSL for sandbox-api.uber.com:443... 
SSL established 
<- "PUT /v1.2/sandbox/requests/f14877e5-f060-4c4a-be91-bb66866238b9 HTTP/1.1\r\nAccept-Language: en_US\r\nContent-Type: application/json\r\nAuthorization: Bearer [TOKEN REDACTED]\r\nConnection: close\r\nHost: sandbox-api.uber.com\r\nContent-Length: 21\r\n\r\n" 
<- "{\"status\":\"accepted\"}" 
-> "HTTP/1.1 204 No Content\r\n" 
-> "Server: nginx\r\n" 
-> "Date: Wed, 26 Jul 2017 12:48:23 GMT\r\n" 
-> "Content-Type: text/html; charset=UTF-8\r\n" 
-> "Connection: close\r\n" 
-> "Content-Language: en\r\n" 
-> "X-Uber-App: uberex-sandbox\r\n" 
-> "X-Uber-App: optimus\r\n" 
-> "Strict-Transport-Security: max-age=604800\r\n" 
-> "X-Content-Type-Options: nosniff\r\n" 
-> "X-XSS-Protection: 1; mode=block\r\n" 
-> "Strict-Transport-Security: max-age=2592000\r\n" 
-> "X-Frame-Options: SAMEORIGIN\r\n" 
-> "Cache-Control: max-age=0\r\n" 
-> "\r\n" 
Conn close 
Redirected to http://edgexpress.ngrok.io/sandbox 
Completed 302 Found in 1010ms (ActiveRecord: 0.2ms) 


Started GET "/sandbox" for 2600:1005:b06a:1a83:9818:4356:ceda:ca11 at 2017-07-26 08:48:23 -0400 
Cannot render console from 2600:1005:b06a:1a83:9818:4356:ceda:ca11! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 
Processing by WebhooksController#operator as HTML 
    Uber Load (0.1ms) SELECT "ubers".* FROM "ubers" ORDER BY "ubers"."id" ASC LIMIT ? [["LIMIT", 1]] 
opening connection to sandbox-api.uber.com:443... 
opened 
starting SSL for sandbox-api.uber.com:443... 
SSL established 
<- "GET /v1.2/requests/current HTTP/1.1\r\nAccept-Language: en_US\r\nContent-Type: application/json\r\nAuthorization: Bearer [TOKEN REDACTED]\r\nConnection: close\r\nHost: sandbox-api.uber.com\r\n\r\n" 
-> "HTTP/1.1 200 OK\r\n" 
-> "Server: nginx\r\n" 
-> "Date: Wed, 26 Jul 2017 12:48:24 GMT\r\n" 
-> "Content-Type: application/json\r\n" 
-> "Content-Length: 804\r\n" 
-> "Connection: close\r\n" 
-> "Content-Geo-System: wgs-84\r\n" 
-> "Content-Language: en\r\n" 
-> "Etag: W/\"c1f9c6d51c7094d1e7789222a522aa1d3f304068\"\r\n" 
-> "X-Uber-App: uberex-sandbox\r\n" 
-> "X-Uber-App: optimus\r\n" 
-> "Strict-Transport-Security: max-age=604800\r\n" 
-> "X-Content-Type-Options: nosniff\r\n" 
-> "X-XSS-Protection: 1; mode=block\r\n" 
-> "Strict-Transport-Security: max-age=2592000\r\n" 
-> "X-Frame-Options: SAMEORIGIN\r\n" 
-> "Cache-Control: max-age=0\r\n" 
-> "\r\n" 
reading 804 bytes... 
-> "{\"status\":\"accepted\",\"product_id\":\"6d898741-0175-4c71-ad5f-93fc66270d6a\",\"destination\":{\"latitude\":33.754177,\"eta\":2,\"longitude\":-84.371736},\"driver\":{\"phone_number\":\"(555)555-5555\",\"rating\":4.9,\"picture_url\":\"https:\\/\\/d1a3f4spazzrp4.cloudfront.net\\/uberex-sandbox\\/images\\/driver.jpg\",\"name\":\"John\",\"sms_number\":null},\"pickup\":{\"latitude\":33.7539854,\"region\":{\"latitude\":33.7489,\"country_name\":\"United States\",\"country_code\":\"US\",\"name\":\"Atlanta\",\"longitude\":-84.3881},\"eta\":1,\"longitude\":-84.3755874},\"request_id\":\"f14877e5-f060-4c4a-be91-bb66866238b9\",\"location\":{\"latitude\":33.7559,\"bearing\":-178,\"longitude\":-84.37212},\"vehicle\":{\"make\":\"Toyota\",\"picture_url\":\"https:\\/\\/d1a3f4spazzrp4.cloudfront.net\\/uberex-sandbox\\/images\\/prius.jpg\",\"model\":\"Prius\",\"license_plate\":\"UBER-PLATE\"},\"shared\":false}" 
read 804 bytes 
Conn close 
    Rendering webhooks/operator.html.erb within layouts/application 
    Rendered webhooks/operator.html.erb within layouts/application (1.8ms) 
Completed 200 OK in 965ms (Views: 28.0ms | ActiveRecord: 0.1ms) 

正如你所看到的,沒有網絡掛接解僱。現在,讓我們結束駕駛取消駕駛。

驅動程序取消

Started PUT "/webhooks/cancel/f14877e5-f060-4c4a-be91-bb66866238b9" for 2600:1005:b06a:1a83:9818:4356:ceda:ca11 at 2017-07-26 08:51:08 -0400 
Cannot render console from 2600:1005:b06a:1a83:9818:4356:ceda:ca11! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 
Processing by WebhooksController#ops_cancelled as HTML 
    Parameters: {"authenticity_token"=>"[REDACTED]", "ride_id"=>"f14877e5-f060-4c4a-be91-bb66866238b9"} 
    Uber Load (0.1ms) SELECT "ubers".* FROM "ubers" ORDER BY "ubers"."id" ASC LIMIT ? [["LIMIT", 1]] 
opening connection to sandbox-api.uber.com:443... 
opened 
starting SSL for sandbox-api.uber.com:443... 
SSL established 
<- "PUT /v1.2/sandbox/requests/f14877e5-f060-4c4a-be91-bb66866238b9 HTTP/1.1\r\nAccept-Language: en_US\r\nContent-Type: application/json\r\nAuthorization: Bearer [REDACTED]\r\nConnection: close\r\nHost: sandbox-api.uber.com\r\nContent-Length: 28\r\n\r\n" 
<- "{\"status\":\"driver_canceled\"}" 
-> "HTTP/1.1 204 No Content\r\n" 
-> "Server: nginx\r\n" 
-> "Date: Wed, 26 Jul 2017 12:51:08 GMT\r\n" 
-> "Content-Type: text/html; charset=UTF-8\r\n" 
-> "Connection: close\r\n" 
-> "Content-Language: en\r\n" 
-> "X-Uber-App: uberex-sandbox\r\n" 
-> "X-Uber-App: optimus\r\n" 
-> "Strict-Transport-Security: max-age=604800\r\n" 
-> "X-Content-Type-Options: nosniff\r\n" 
-> "X-XSS-Protection: 1; mode=block\r\n" 
-> "Strict-Transport-Security: max-age=2592000\r\n" 
-> "X-Frame-Options: SAMEORIGIN\r\n" 
-> "Cache-Control: max-age=0\r\n" 
-> "\r\n" 
Conn close 
Redirected to http://edgexpress.ngrok.io/sandbox 
Completed 302 Found in 582ms (ActiveRecord: 0.1ms) 

Started POST "/webhooks/event" for 104.36.193.85 at 2017-07-26 08:51:10 -0400 
Cannot render console from 104.36.193.85! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 
Processing by WebhooksController#event as */* 
    Parameters: {"event_id"=>"6b8e9684-c1c9-448b-92ef-54f9bbde53d0", "resource_href"=>"https://sandbox-api.uber.com/v1/requests/f14877e5-f060-4c4a-be91-bb66866238b9/receipt", "meta"=>{"status"=>"ready", "rider_id"=>"8Gb4HQ4kVZIq-Z6nR_kKYGBO_tjV1JqyU2VRJJdICrKLJDFVSv34MqsGfKZI0JO6d7-ELIws7Ia_YhwCmbvVHXRzwdIzEDOXs4aTrPRljXML10yOpwEKTn1sCyPlHmLT4g==", "user_id"=>"55d5e34c-1a9f-4dd8-87fe-1764678eea94", "resource_id"=>"f14877e5-f060-4c4a-be91-bb66866238b9"}, "event_type"=>"requests.receipt_ready", "event_time"=>1501073468, "webhook"=>{"event_id"=>"6b8e9684-c1c9-448b-92ef-54f9bbde53d0", "resource_href"=>"https://sandbox-api.uber.com/v1/requests/f14877e5-f060-4c4a-be91-bb66866238b9/receipt", "meta"=>{"status"=>"ready", "rider_id"=>"8Gb4HQ4kVZIq-Z6nR_kKYGBO_tjV1JqyU2VRJJdICrKLJDFVSv34MqsGfKZI0JO6d7-ELIws7Ia_YhwCmbvVHXRzwdIzEDOXs4aTrPRljXML10yOpwEKTn1sCyPlHmLT4g==", "user_id"=>"55d5e34c-1a9f-4dd8-87fe-1764678eea94", "resource_id"=>"f14877e5-f060-4c4a-be91-bb66866238b9"}, "event_type"=>"requests.receipt_ready", "event_time"=>1501073468}} 
Comparing 6b8e9684-c1c9-448b-92ef-54f9bbde53d0 to what's in db. . . 
    UberEvent Load (3.4ms) SELECT "uber_events".* FROM "uber_events" WHERE "uber_events"."event_id" = ? [["event_id", "6b8e9684-c1c9-448b-92ef-54f9bbde53d0"]] 
Ignoring duplicate or filtered notice 
Completed 200 OK in 7ms (ActiveRecord: 3.6ms) 

正如你可以看到,貼有收到信息,這意味着它不是我和網絡掛接海報,或配置錯誤之間的塊網絡掛接。 webhook根本不會爲我開火。

我錯過了什麼?

回答

0

當沙箱中的行程狀態發生變化時,我們目前沒有看到webhook問題。我已經用我的測試應用程序進行了測試,並且我收到了webhooks所有webhook應該被解僱的狀態變化。請檢查屏幕打印吼叫: enter image description here

+0

嗨沙沙,我仍然看到問題。我會更詳細地更新票證。 – brokenbeatnik

+0

你還在使用webhooks有問題嗎? –

+0

是的,這仍然是壞的。我將應用程序放到Google Cloud的服務器上,得到了相同的結果,這意味着它不是我的機器或我使用ngrok導致的問題。我得到了一些webhooks(收據),但不是騎的,所以這意味着它不是我的webhook聽衆。你有沒有改變沙箱中的任何東西,或者你在那裏看到問題? 我還提供了大量額外的上下文來解釋和排除我身邊的錯誤。 – brokenbeatnik