Interaction between Ruby App and Other App using GET and POST request - ruby

I have two Apps, one in Ruby and other one in PHP (Assume, there is a different team developing this app).
Ideally what happens is; Other App sends request to Ruby App with some parameters, I want to store this Parameters in database on Ruby App's side. Then Ruby App picks up this parameters does some processing and saves data back in Database and again.
Now I want to send request to Other App with new parameters. How do I achieve this?

You write the Ruby app so it is run from a web server (I believe Ruby on Rails is still a popular way to do that in Ruby land) to get the requests, and then use an HTTP library (Google finds NET:HTTPSession) to make the requests back to the other service.

Related

How to set up authorization using js-SSR and SPA?

I want to develop my own single page web application (SPA) to get to grips with the modern and highly fluid world of web development. At the same time, I would like to use the page rendering technology (SSR) with built in data into html. However, there is an authorization problem.
Suppose that the user has already logged into the account before, as I imagine re-opening the site:
First request: the client makes a request to the frontend server along with identification and authorization data (for example, user id and token; the only option is to save them in cookies), the frontend server makes a request to the api server, transferring these service data, then the api server gives the information about the user and the content of the current page (in the same json), the frontend server renders this into a finished page and delivers it to the client.
Subsequent requests: the client directly addresses the api server, transferring the same (or updated after the first request) authorization data, receives json and processes it independently.
Actually, I want to move on to the question. Do I understand this interaction correctly? Can you do it differently / better? Are there tools that allow, for example, to use the components of the frontend framework as components of the MVC backend framework, so that one server does the rendering without unnecessary requests? Or a unified tool that includes the same coding for the frontend and backend to solve these problems? I will say right away that I would not like to write a backend in JS.
I can roughly imagine how you can get by with one request when using AngularJS (with a module for single page applications) and any backend MVC framework; although there will not be a full-fledged render, but search robots will not have to wait for my first fetch, since the data will be delivered initially, for example, through the data attribute. But in this case, I plan to choose Svelte (Sapper) and Ruby on Rails as the stack, although I think this is not important.
Thank you for your attention to the question!
Are there tools that allow, for example, to use the components of the frontend framework as components of the MVC backend framework, so that one server does the rendering without unnecessary requests?
If that's what you want you can install a frontend framework in Rails using webpacker. After that you will have a folder in your rails project that will contain your Svelte components. Then you import Svelte components in erb templates and pass data as props.
I have tried that approach but personally I prefer a separate frontend and backend talking through API calls. Then in your frontend you need something like Sapper if you need SSR. With webpacker you don't(assuming you mostly use Rails for routing).
If you are worried about authorization it's not really hard to implement. And after login you can store user info on local storage for instance for subsequent requests. But of course if you install with webpacker it's all done within Rails hence it's easier.
From my experience, using webpacker it's easy and quick in the beginning but you are more likely to get headaches in the future. With separate backend and frontend takes a bit more work, especially in the beginning, but it's smoother in the long run.
This helped me set the authentication between rails api and vue frontend.
So, if you wish to separate them, just install Rails as API only and I suggest you to use Jbuilder to build your jsons and serve them to the frontend as you need them.

How to Launch two session(App and Mobile Browser) in single appium server?

Hi I have this iOS native app functionality that needs to automate in Appium-Ruby + Cucumber.
After completing the registration flow(Signup), i need to put the app in background and open safari mobile web browser,then Go to Mailinator.com and activate my account.
Could anyone help me in how to handle this?
I am new to Appium-Ruby+Cucumber.
I am using Appium 1.6 version
There are multiple alternative solutions to this rather than getting into the complications of opening the browser activity and leaving the app context in your test case..
1) Would be to integrate webdriver for browser within your appium test suite, maybe use phantomjs so the browser is headless.
Eg:
def activate_my_account
browser = Selenium::WebDriver.for(:phantomjs)
browser.get("http:://mailinator.com")
<perform your action here>
end
2) Use a api driven mail client to get the latest email using api matching the subject line. Strip out the url from the email body and use hit the url. There is no browser involvement in this solution.
3) Get the token from database and create the validation url on the fly and hit the url using curl or http or rest client in ruby. Again this is no browser involvement solution.
Let me know in the comments if you face any issues!!
Hope it helps!!

Create webhook with only ruby?

I'm creating a telegram bot in ruby , right now I'm using long polling , but I wanna change to webhooks, but I'm only found information about creating webhooks in rails , so I don't know if is possible to set a webhook in a ruby only project.
Anyone did this? or have a tutorial? Maybe a lighter application in sinatra or rails api mode?
You could start with a simple socket server: https://ruby-doc.org/stdlib-1.9.3/libdoc/socket/rdoc/Socket.html
However, creating a Rails app with one route for the web hook will not take you a lot of time. This will also give you a lot of flexibility to do more with your inbound data and app in the future e.g. admin dashboard, security, background processing, etc.

Making AJAX call from chrome extension to Meteor web app

Hi I have made a web app to practice Meteor and am now trying to make a companion chrome extension. I am having difficulty finding resources on how to make AJAX calls to my meteor app/mongodb.
An example of what I am trying to do is find specific words on a webpage and search them in my mongodb.
Any resources or information on how to best do this would be appreciated.
I suppose you know how to make Ajax call from client. So you are having difficulty in building a REST API in Meteor. Although it is not recommended to build a REST API with Meteor, you can still do it. If you use case just require a REST API and does not have much to do with reactivity, I think you should not go with Meteor, just Node and Express should be fine.
But if you really want to use Meteor, here is the solution: Meteor has a package named webapp which let you handle HTTP requests, that is enough for building a simple REST API. If you API is more complex, check out this community package nimble:restivus it has a better API and useful functions

Parse and Uber API Webhooks

I’m building an iOS app that utilizes Uber’s API and Parse. After a user requests a ride in my app and the ride status changes, I’d like to update the in app screen and send a push notification. Uber’s docs say to use web hooks for this. I’m trying to figure out how I would do this if I’m using Parse. As far as I know, a Parse backend doesn’t have the ability to receive POST data from the Uber web hooks. I was thinking of making a small express server that would receive the web hooks POST data, clean it up, and send it to Parse’s API which would in turn send it to the client as a push notification. Is there a better way to do this?
I think you're on the right track. It looks like there are some projects in the Parse OpenSource Hub you could re-use for your purpose.
The alternative is to simply do a GET /v1/requests/current every few seconds within your app.

Resources