ParseHub Webhook with RoR - ruby-on-rails

Parsehub provides the webhook feature. But currently I'm testing my Rails app locally. So how could I provide the webhook url for a project on Parsehub to point to my local server or any specific method in my controller.
Parsehub Doc Webhook:
https://www.parsehub.com/docs/ref/api/v2/#webhooks
Webhook Url option Screenshot:

In order to use a webhook, you need to provide a publicly visible IP address for ParseHub to make requests to. You can get one by registering for a cheap VPS host (e.g. DigitalOcean for $5/month).
On that host, you want to run a webserver, and put the endpoint that the webserver listens on into the webhook textbox in ParseHub. To inspect the details of what ParseHub sends, you can just make your webserver log all the request data. You can also check out our API docs which have a description of all the fields: https://www.parsehub.com/docs/ref/api/v2/#run

The way I usually test webhooks is by using Request Bin http://requestb.in/
Essentially you get a url from them, you give this as your webhook address and anything that is posted to this URL will be caught by the website for further inspection!
You can then get these parameters and post them to your application manually, thus mimicking the entire process.

Related

Handling webhook calls in ASP.NET MVC application, implementation and testing

I have inherited this old ASP.Net MVC application and now I have to integrate a new Payment Service Provider. This PSP returns the responses to all payment requests via a POST message. The fields of the response are sent as hidden fields. The URL of the webhook must be provided in the request. After reading different SO posts along the same lines, I kinda know, in principle, what I would have to do. The PSP has a test & integration environment so I can send test request from my development environment. The problem I am facing is how to read the response. The URL for the webhook must be public, so me, running my development environment on my localhost, won't help. I can use webhook.site to get the responses, but I would like to get them in my application, so I check that my code behaves correctly and can handle properly the POST message containing all the hidden fields. Did anyone manage to find a possible solution for this problem?
TIA,
Ed
You mention that you want to test if you code behave correctly, I also see tag asp.net mvc in the post. For this requirement I can suggest you to go with azure. Azure have remote debugging feature which can easily help you test your code.
If you don't want to go with Azure, you can use ngrok software to make your localhost url public. This way you can trigger your code and debug it locally like remote debugging in azure.
There is one more way to test this thing very well. Just log the whole body of webhook (in logs or DB) and later execute it yourself through postman. This might doesn't let your webhook endpoint know the result at same time.

How to verify requests from Wiremock deployed to a remote host based on it's URL only?

I've implemented a custom Wiremock Server programmatically using Spring Boot and this service is deployed and running on a remote host.
The only way to access this Wiremock Server is URL provided by DevOps. Let's say testWiremockHost.com
All mappings are working fine and Wiremock responds properly.
But I do have couple of questions:
1) There's no response from the Server when I try GET request on testWiremockHost.com/__admin
2) My goal is to verify requests that were sent to this Wiremock after another service is triggered, so I also need to find a way to properly define instance of this remote Wiremock in my tests in order to track incoming requests. Previously, when I tried to verify the requests from 'localhost' Wiremock server everything was just fine, but unfortunately I can't do the same for the remote one.
The latest code I've tried is the following:
wiremock = new WireMockBuilder().host("testWiremockHost.com").https().build();
*send request*
wiremock.verify(1, postRequestedFor(urlEqualTo("/testEnpoint")))
I get the following error as a result:
"detail" : "Unrecognized field \"timestamp\" (class com.github.tomakehurst.wiremock.common.Errors), not marked as ignorable"
I'd appreciate any help on this, thanks in advance!

Creating a Heroku add-on

I would like to integrate my cloud service in Heroku as an add-on. I read the available tutorials on how to do this, but it is still not clear. https://devcenter.heroku.com/articles/building-a-heroku-add-on#provisioning
I couldn't understand the role of the application that we create from a template (Sinatra for example) using kensa.
Is it an intermediate between Heroku and the cloud service?
thanks in advance.
Actually, Heroku needs 2 things:
addon-manifest.json file where described all information needed for Heroku. And this json file contains 2 important urls:
'base_url'
'sso_url'
Application which will server heroku-specific API and responds wit corresponding JSON on provisioning/deprovisioning/planchange requests. These request point to 'base_url'.
So, if you own your Cloud service code, and can add new API endpoints, then you don't need any application based on kensa-template: add necessary API controllers directly in the service.
But if you can't upgrade the cloud service, then you're right, kensa-template is a ready to use with heroku intermediate.
In case of sinatra template, you just need to put necessary API calls to your cloud service in "# provision" method of app.rb file, deploy app somewhere and do 'kensa push' for your addon-manifest.json (don;t forget to update base_url to yours)
Good luck!
Bare minimum API routes for heroku add-on based on your Cloud service:
POST request to '/heroku/resources' - for provisioning
DELETE request to '/heroku/resources' - for deprovisioning
If you really want to sell it to heroku users, then you should do more stuff:
add support for heroku single sign-on
this is one more API route: POST to '/heroku/sso', but you can change it in addon-manifest.json file.
PUT '/heroku/resources/:id' for Plan change request. Note that ':id' is an id which you provided heroku in your response during provisioning.
If you implement SSO, then user can click on your add-on on heroku instance's resources page and redirect directly to your service bypass any login forms.
You can show just short info about user's resource in the page after SSO.

Sendgrid receive email locally

I am trying to implement sendgrid parse API using the 'griddler' gem in my rails application. The problem is how can I test it locally? And how to receive email in my local machine.
The are a couple ways to test SendGrid's Parse Webhook locally.
The easiest is to just simulate the Webhook by POSTing data to your endpoint yourself (via cURL or some other mechanism, like Postman [example]). The SendGrid Parse Webhook Docs has an example of the payload that will be posted to your server, so you may mimic that.
The second option, which allows for end-to-end testing rather than just simulation is by creating a tunnel your local machine and provide SendGrid with the URL of the tunnel. There are a number of free services that allow you to do just that very easily:
https://ngrok.com/
http://progrium.com/localtunnel/
If I may self-promote, I created a Ruby gem that does this:
https://github.com/ccallebs/pokey-sendgrid
It runs alongside your server and generates SendGrid webhook requests at regular intervals.

Obtaining a users subscriptions via Shopify App Proxy

Can the App proxy be used to pass through various ID's for a separate backend rails app?
I have the case where we've implemented a subscription system in a separate rails app, but we want to show the user their subscriptions from Shopify. To do this I would like to add an app proxy on Shopify, such as:
Proxy Url: subscriptions.com/api/customers/subscriptions
Proxy Path: /a/customers
But I'd like to be able to proxy /a/customers/:customer_id/subscriptions, maybe even /a/customers/:customer_id/subscriptions/:id (for a show subscription liquid response), so concatenating the ids into the url is my main goal.
On the rails side I can easily extract the path_prefix from the params, its a matter of how Shopify is matching the Proxy Paths I guess.
Is this at all possible? Or is there another way around this problem?
The extra path components get appended to the Proxy URL. The Shopify Application Proxy documentation even provides an example showing this in the Proxy Request section.
So for you example, where the proxy url is http://subscriptions.com/api/customers/subscriptions and the proxy path is /a/customers then a request to /a/customers/:customer_id/subscriptions will be proxied to http://subscriptions.com/api/customers/subscriptions/:customer_id/subscriptions
So it sounds like the proxy request is already exactly what you want.

Resources