I am using Workbox 3.6.1 now and I am really enjoy it.
But I just have a question about the post data caching of Workbox.
I may need to use the data which received from a request to post data to the server.
For example,
Step 1: the user enters his ID in the input field to validate his
identity and then to help the website rendering the rest content (eg: another input field)
Step 2: And the user enter some other information and sends the data
along with his ID to the server.
To my basic knowledge so far, I understand the Workbox can do the step 1 and 2 separately (I can only implement like this way......). But I just wondering if they will be queued together and when the website comes back online, the step 1 runs and the step 2 uses the data from step 1 and runs as well. During online, it can be done by using promises or callbacks. But i want to know if they are queued offline as well.
May be there is a way which I do not know, but I would like to know the official Workbox method to implement this case OR other workarounds.
Thanks for the help.
Related
I'm trying to parse the last received message from Pushbullet. I'm currently doing it using Clicks, which means that I do every single clicks, sendkeys and all the rest needed actions automatically. In other words it is just a simulation of the user. One of the biggest con of the method is that whenever xpath or a class or id of the element changes which I'm aiming with Selenium, whole cycle fails and the test case can not proceed operating.
I want to change the way I'm doing. Particularly, I want to send a json request to Pushbullet API and then get the response in return.
I just couldn't decide from where and how to start doing.
Could you guys please tell me the way from where should I start and what are the steps that needs to be covered in order to finally reach the finish line?
Thank you in advance.
I noticed that this question is tagged under Selenium, but in your question, you express interest in switching to an API approach. I will try to provide some advice to you on this.
Selenium Approach
You mention that you tests are brittle, and if anything changes then they fail. This is usually the case with UI tests. If you would like to stick with the Selenium approach, I can try to help you write more robust locators for your WebElements that will not break constantly.
API Approach
You will need to start with the Pushbullet API documentation -- https://docs.pushbullet.com/
To get messages, it looks like you will want to use the chat endpoint -- a sample request looks like this: https://api.pushbullet.com/v2/chats, plus authentication.
Once you fetch the chat objects, you will need to write your own logic to parse each chat object and fetch the most recent message from there.
Depending on what language you are using, you will need to install a REST client package onto your project. I use C#, so RestSharp is the client I like to use.
I recommend installing a REST client interface, such as Postman, to start practicing your API calls. Once you get your API calls working in Postman, you can start writing code to make these API calls.
What other questions do you have about this?
I am having trouble finding a way to perform a simple operation without making it way more complex than it has to be.
Example: I want to say "Alexa, What is the status of my website?"
I want it to know I'm referring to http://refindustry.com/index1.php
And I want it to read the single line on that page that at current says"Our website is under construction"
It is a really simple operation each time I want it to request the defined page and read the single line of html text on the page.
Keep in mind I don't want to have to host a server or pay amazon to do this I just want her to simply request the page and read the single line.
Tried going to amazon developer and it looked insane account linking lamda requests just way more difficult that it should be.
You can get the free tier of AWS to host a lambda that can fetch the text from your website and return the response to Alexa.
Then you need to setup your skill with a few sample utterances for how to ask for the status of your website and use this lambda.
You have to have a service that will fulfil the intent from Alexa - this could be a server somewhere (so the skill would send the request via HTTP), or a Lambda function.
As Josep says, you can get a free AWS tier - write some code to fetch the page and "grab" the status, before using it in the response to Alexa. It should be pretty straight forward to do this.
If you're a little daunted about AWS, you could look at Hosted Skills - https://developer.amazon.com/blogs/alexa/post/ebc1c777-2cb2-4210-8c89-2a70dd1a0248/get-your-head-out-of-the-cloud-with-alexa-hosted-skills-preview
So, for my android app, not only do I get certain data that I would like to POST to an API endpoint via JSON format, but one of the data pieces is also an image. Everything besides the image goes into a postgresql database. I want to put the images somewhere (no important where) then put the link to that image in the database.
Here's the thing, while that image is connected to the other pieces of data I send to the API endpoint that gets put into the database, I would be sending the image somewhere else and then the link be put in at a different time. So here's my mental gymnastic I am trying to get over:
How would I send these two separate data pieces (an image and then all other data in a single JSON object) and have the image associated with that JSON object that get's put into the database without the image and data getting all mixed up due to multiple users doing the same thing?
To simplify, say I have the following information as a single JSON object going to an endpoint called api.example.com/frontdoor. The object looks something like this:
{
"visitor_id": "5d548e53-c351-4016-9078-b0a572df0bca",
"name": "John Doe",
"appointment": false,
"purpose": "blahblahblah..."
}
That JSON object is consumed by the server and is then put into their respective tables in the database.
At the same time, and image is taken and given a uuid as a file name and send to api.example.com/face, then the server processes it and somehow a adds link to the image in the proper database entry row.
The question is, how do I accomplish that? How would I go about relating these two pieces of data that get sent to two different places?
In the end, I plan on having a separate endpoint such as api.example.com/visitors provide a JSON object with a list of all visits that looks something like:
{
"visits": [
{
"visitor_id": "5d548e53-c351-4016-9078-b0a572df0bca",
"name": "John Doe",
"appointment": false,
"purpose": "blahblahblah..."
"image": "imgbin.example.com/faces/c3118272-9e9d-4c54-8824-8cf4cfaa679f.png"
},
...
]
}
Mainly, I am trying to get my head around the design of all of this so I can start writing code. Any help would be appreciated.
As I understand, your question is about executing an action on the server side where two different sub services are involved - one service to update the text data in a sql db and another to store an image and then put the image's reference back to the main data. There are two approaches that come to my mind.
1) Generate a unique id on the client side and associate that to both json object upload an the image upload. And then when your image is uploaded, the image upload service can take this ID, find the corresponding record in SQL and update the image path. However generating client side unique IDs are not a recommended approach because there is a chance of collision such that more than 1 client generates the same ID which will break the logic. To work around this, before uploading, client can make a call to an ID generation service which will uniquely generate the ID on the server side and send it back to the client and then client can perform the upload step using the same approach. The downside to this approach is that the client needs to make an extra call to the server to get the unique ID. Advantage of this approach is that the UI can get separate updates for the data and the image as in when the data upload service is successful, it can say that the data is successfully updated and when the image is uploaded at some point in time later, then it can say that image upload is completed. Thus, the responses of each upload can be managed differently in this case. However if the data and image upload has to happen together and has to be atomic (the whole upload fails if either of data or image upload fails) then this approach can't be used because the server must group both these actions in a transaction.
2) Another approach is to have a common endpoint for both image and data upload. Both image and data get uploaded together in a single call to the server and the server first generates a unique ID and then makes two parallel calls to data upload service and image upload service and both these sub service calls get this unique ID as the parameter. If both uploads have to be atomic then the server must group these sub service calls in a transaction. Regarding returning response, it can be synchronous or asynchronous. If the UI needs to be kept waiting for the uploads to succeed, then the response will be synchronous and the server will have to wait for both these sub services to complete before returning a response. But if UI doesn't need to be kept waiting then the server can respond immediately after making calls to these sub services with a message that the upload request has been accepted. In this case, the sub services calls are processed asynchronously.
In my opinion, approach 2 is better because that way server has more control over grouping the related actions together. Regarding response, it depends on the use case. If the user cares about whether his post was properly recorded on the server (like making a payment) then it is better to have synchronous implementation. However if user initiates the action and leaves (as in the case of generating a report or sending an email) then it can have asynchronous implementation. Asynchronous implementation is better in terms of server utilization because server is free to accept other requests rather than waiting for the sub services' actions to complete.
These are 2 general approaches. I am sure there will be several variations or may be entirely different approaches for this problem.
Ah, too long of an answer, hope it helps. Let me know if further questions.
I'm working on a simple ruby script with cli that will allow me to browse certain statistics inside the terminal.
I'm using API from the following website: https://worldcup.sfg.io/matches
require 'httparty'
url = "https://worldcup.sfg.io/matches"
response = HTTParty.get(url)
I have to goals in mind. First is to somehow save the JSON response (I'm not using a database) so I can avoid unnecessary requests. Second is to check if the new data is available, and if it is, to override the previously saved response.
What's the best way to go about this?
... with cli ...
So caching in memory is likely not available to you. In this case you can save the response to a file on disk.
Second is to check if the new data is available, and if it is, to override the previously saved response.
The thing is, how can you check if new data is available without doing a request for the data? Not possible (given the information you provided). So you can simply keep fetching data every 5 minutes or so and updating your local file.
I am creating a dashboard application in which i show information about the servers. I have a Servlet called "poller.java" that will collect information from the servers and send it back to a client.jsp file. In the client.jsp , i make AJAX calls every 2 minutes to call the poller.java servlet in order to get information about the servers.
The client.jsp file shows information in the form of a table like
server1 info
server 2 info
Now, i want to add one more functionality. when the user clicks on the server1, I should show a separate page (call it server1.jsp) containing the time stamps in which the AJAX call was made by calling.jsp and the server information that was retrieved. This information is available in my calling.jsp page. But, how do i show it in the next page.
Initially, i thought of writing to a file and then retrieving it in my server1.jsp file. But, I dont think it is a good approach. I am sure i am missing a much simpler way to do this. Can someone help me ?
You should name your servlet Poller.java not poller.java. Classes should always start with an uppercase. You can implement your servlet to forward to a different page for example if sombody clicks to server1 then the servlet will forward to server1.jsp. Have a look at RequestDispatcher for this. Passing information between request's should be done by request attributes. if you need to retain the information over several request you could think about using session.
In the .NET world, we use SessionState to maintain data that must persist between requests. Surely there's something similar for JSP? (The session object, perhaps.)
If you can't use session state in a servelet, you're going to have to fall back on a physical backing store. I'd use a database, or a known standard file format (like XML). Avoid home-brew file formats that require you to write your own parser.