My app communicates with the server in json rpc format - and each request from the client needs to have a new id generated by the client. jsonrpc specs example:
{"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": 1}
and the next request would have an id=2 and so on.
I read that having global variables in ember is not recommended, so I guess I should keep the id in the application route, and have a function that sets id to be id++ and return the new value. However, I dont know how to access this function as I keep getting errors on stuff like
data["id"] = Addapp.ApplicationRoute.getNewJRId();
where the ApplicationRoute is undefined...
My questions are: Would this be a proper approach?
I do this, how?
Related
When I request a webpage, it sets a cookie:
{
"name": "",
"value: "test",
"domain": "foo.bar.com",
# ... there are more fields here, but not important
}
As you see, the "name" is not set. How must I handle this cookie in my further requests? Options:
Ignore this cookie and do not use/set it it my further requests.
Try to send this cookie as is, but the problem is that the most of packages (I use Python) do not allow cookies with an empty name.
Set a random name to that cookie and use. I am afraid to do this because I do not know whether a website will recognize that cookie.
Probably missing something completely obvious in the docs but is it possible to echo request data in a Postman Example / Mock Server response based on the input request.
Example Request:
POST:
{
"firstName": "{{$randomFirstName}}",
"lastName": "{{$randomLastName}}",
"phoneNumber": "{{$randomPhoneNumber}}",
"email": "{{$randomExampleEmail}}",
"employeeId": "{{$randomInt}}"
}
Intended example response:
{
"id": {{$randomInt}},
"firstName": "{{$req.firstName}}",
"lastName": "{{$req.lastName}}",
"phoneNumber": "{{$req.phoneNumber}}",
"email": "{{$req.email}}",
"employeeId": "{{$req.employeeId}}"
}
I see you want to use Postman's dynamic 'faker' variables in the request body to be returned in the mock response. A similar use case is supported for the request URL (refer to the section on 'wildcards' here) but not body.
Here's one way to achieve this with the request body:
Create an environment 'e1' with variable 'firstName'.
Edit your mock to add the environment 'e1'.
Use the same environment variable {{firstName}} in the response body of your example.
Dynamically update the value of 'firstName' before sending the mock request. If you're using the Postman client, you can do this using the pm.environment.set method. If not, then you can use the Postman API to do this.
On the other hand, you can simply use the same faker variable {{$randomFirstVariable}} in your mock example response as well, but the value returned could differ from the one sent in the request.
I am working on integrating GMB into some of our internal apps, and would like to set up to receive real-time notifications for reviews and questions.
I have created a topic, and a subscription with a valid URL.
The next step is to tell GMB to send the notifications to the topic, and I believe the endpoint is the one below. However, it is very vague about the parameters it wants.
This is the documentation
https://developers.google.com/my-business/reference/rest/v4/accounts/updateNotifications
It wants a "Notification Settings Resource Name" in the URL, but it's not explained anywhere what that actually is. I have tried every possible value, but always get a 404 error response with the message "Requested entity was not found."
Has anyone successfully set this up? What values does the "getNotifications" endpoint want, and where in the various dashboards can this be found or created?
Any help is much appreciated!
As mentioned in the comments, you need to send the accountId as part of the URL.
To find this, you will first need to send a GET request to
https://mybusiness.googleapis.com/v4/accounts
This will return something along the following lines:
{
"accounts": [
{
"name": "accounts/102647145453118950380",
"accountName": "Tom Spencer",
"type": "PERSONAL",
"state": {
"status": "UNVERIFIED",
"vettedStatus": "NOT_VETTED"
},
"profilePhotoUrl": "//lh3.googleusercontent.com/a-/AOh14GgPkuJj03DeCa1isBAJALY4eOl09WGYVFrM4mG5=s132"
},
]
}
You can see here that accounts/102647145453118950380 is returned in the name field. Take this field, and construct the following URL:
https://mybusiness.googleapis.com/v4/accounts/102647145453118950380/notifications
Send a PUT request to this URL, with a request body resembling the following:
{
"topicName": "projects/{projectId}/topics/{topicId}",
"notificationTypes": [
"NEW_REVIEW",
"UPDATED_REVIEW"
]
}
Assuming you have pub/sub setup as per the documentation, this should send a message to your topic/subscribers whenever a new review is created or a review is updated.
I used this URL here to get the share count of a URL
https://www.linkedin.com/countserv/count/share?url=http://google.de&format=json
{
"count": 83,
"fCnt": "83",
"fCntPlusOne": "84",
"url": "http://google.de"
}
However, when I use PHP & cURL to get the share count with the same URL, I get this
{
"count": 2285,
"fCnt": "2,285",
"fCntPlusOne": "2,286",
"url": "http://google.de"
}
When disabling cookies in the WebDeveloper addon, or using another Browser, I'm getting the correct(?) count.
When I delete the cookie lidc from the cookies of LinkedIn I get the correct count, too.
So basically, my question is, why does the share count differ? Which one is the correct one? For me, it looks like the second result is the correct one.
I am trying to use ember-data to get a simple registration form to save on my server. The call technically works, but the success callback is never trigger on the promise, and I have no idea why.
The server receives the data from the front end and successfully saves it to the database. It then returns status code 201 for CREATED. I can see the successful response happening in the Chrome debugger. But even when the server responds with a successful status, the error callback is triggered on the save's promise. I've confirmed this happens every time by putting a debugger; statement in the error callback.
My router's model is hooked up like this:
model: function() {
return this.store.createRecord('registerUser');
}
And I have a simple register function in my controller:
register: function() {
var self = this;
this.get('model').save().then(function() {
self.transitionToRoute('index');
}, function(resp) {
if (resp.responseJSON) {
self.get('model').set('errors', resp.responseJSON.errors);
}
});
}
Every time my server comes back with a response, success or failure, the failure callback is hit. If I have errors in the response (for invalid data or something), the errors are successfully displayed in the form. I can see the request coming in properly, and the data is stored in the database. So, the save is technically successful, but ember doesn't seem to know that it is even though a successful 201 status is returned from the server (which can be verified in the Chrome debugger).
The only thing I can think of is that ember-data's adapter is doing something that I'm not aware of, but I am just using the default RESTAdapter and haven't touched it. Is there anything else
If it makes a difference, the server is running Play 1.2.5. I don't know if that makes a difference in the response's header or something like that.
Any help would be greatly appreciated. Thank you for your time!
Mike
SOLUTION
So, the issue was to do with the JSON response. The two problems:
I did not include an ID in the response
I did not "wrap" the response in a "registerUser". This is necessary to match the model name.
Below is a valid response:
{
"registerUser": {
"id": 11,
"email": "mike999#test.com",
"password": "12345",
"password2": "12345",
"name": "Mike"
}
}
Ember Data is expecting the model in the response, so sending back a success http status doesn't mean it will hit the success endpoint. When it tries to serialize your response (or lack of response) it's probably failing which would be why it's hitting the failure function. A big reason for the response is the id of the record.
The model returned should be in the following format
{
registerUser:{
id: "123",
attr: "asdf"
}
}
https://github.com/emberjs/data/blob/master/TRANSITION.md