Ember - Sending particular values in PUT request - ember.js

I have a form which I am using to edit details via form. Ember does a PUT request like required but I need it to only send particular values and not everything within the JSON object. The object is structured as:
{
consoles: {
"id": "1",
"name": "Street Fighter",
"type":"Beat-em-up"
"versions": "10",
"consoles": [
{
"id": "1",
"name": "Microsoft",
"console": "Xbox 360"
},{
"id": "2",
"name": "Microsoft",
"console": "Xbox One"
},{
"id": "3",
"name": "Sony",
"console": "Playstation 4"
}
],
"Characters":[],
"Reviews":[]
}
}
The only editable values within my form are:
name
type
versions
When I press the update button, everything is sent in a PUT request. Is it possible for ONLY name, type and versions to be sent in the request?
I'm aware of overriding updateRecord but I wouldn't know where to start if this was what I needed to do.

You can write your own Serializer to only send specific attributes up to the server.
See the docs here

Related

List users as non admin with custom fields

As per the documentation, I should be able to get a list of users with a custom schema as long as the field in the schema has a value of ALL_DOMAIN_USERS in the readAccessType property. That is the exact set up I have in the admin console; Moreover, when I perform a get request to the schema get endpoint for the schema in question, I get confirmation that the schema fields are set to ALL_DOMAIN_USERS in the readAccessType property.
The problem is when I perform a users list request, I don't get the custom schema in the response. The request is the following:
GET /admin/directory/v1/users?customer=my_customer&projection=full&query=franc&viewType=domain_public
HTTP/1.1
Host: www.googleapis.com
Content-length: 0
Authorization: Bearer fakeTokena0AfH6SMD6jF2DwJbgiDZ
The response I get back is the following:
{
"nextPageToken": "tokenData",
"kind": "admin#directory#users",
"etag": "etagData",
"users": [
{
"externalIds": [
{
"type": "organization",
"value": "value"
}
],
"organizations": [
{
"department": "department",
"customType": "",
"name": "Name",
"title": "Title"
}
],
"kind": "admin#directory#user",
"name": {
"fullName": "Full Name",
"givenName": "Full",
"familyName": "Name"
},
"phones": [
{
"type": "work",
"value": "(999)999-9999"
}
],
"thumbnailPhotoUrl": "https://photolinkurl",
"primaryEmail": "user#domain.com",
"relations": [
{
"type": "manager",
"value": "user#domain.com"
}
],
"emails": [
{
"primary": true,
"address": "user#domain.com"
}
],
"etag": "etagData",
"thumbnailPhotoEtag": "photoEtagData",
"id": "xxxxxxxxxxxxxxxxxx",
"addresses": [
{
"locality": "Locality",
"region": "XX",
"formatted": "999 Some St Some State 99999",
"primary": true,
"streetAddress": "999 Some St",
"postalCode": "99999",
"type": "work"
}
]
}
]
}
However, if I perform the same request with a super admin user, I get an extra property in the response:
"customSchemas": {
"Dir": {
"fieldOne": false,
"fieldTwo": "value",
"fieldThree": value
}
}
My understanding is that I should get the custom schema with a non admin user as long as the custom schema fields are set to be visible by all domain users. This is not happening. I opened a support ticket with G Suite but the guy that provided "support", send me in this direction. I believe this is a bug or maybe I overlooked something.
I contacted G Suite support and in fact, this issue is a domain specific problem.
It took several weeks for the issue to be addressed by the support engineers at Google but it was finally resolved. The behaviour is the intended one now.

jsonapi + ember 2.0 + pagination

How to do pagination in latest version of ember-data (v2.2) and a jsonapi backend?
I am in control of the backend implementation so I can implement any strategy, but I would prefer to follow the standard as described here:
http://jsonapi.org/format/#fetching-pagination
However, that description is a bit cryptic to me without an example.
And how to handle that smoothly on the client (ember) side?
Is there some built in stuff in ember-data to process the paging-links?
EDIT:
I guess to get started I must process the meta information. By overriding the serializer. At the time deserialize is called I can read the meta from the payload but at that time I don't have an object to store it on. Later when my object is done deserialized I don't have access to the payload with the meta information.
Does that make sence? Here is my example payload:
{
"data": {
"id": "1",
"type": "user",
"attributes": {
"firstname": "John",
"lastname": "Doe",
"email": "john.doe#example.com",
}
},
"included": [{
"id": "68",
"type": "activity",
"attributes": {
"title": "Yoga",
}
}, {
"id": "65",
"type": "activity",
"attributes": {
"title": "Slalom",
}
}],
"meta": {
"activity-total": "23",
"activity-pagesize": "2",
"activity-offset": "0"
}
}
Where to put my code that reads the meta information and stores it on the user object?
You could use the Ember Infinity Addon. It does all the magic for you.

Where/when should I remove the relationship type to avoid an unknown keys warning?

I'm using Ember Data with a server application that follows the json:api standard. When I normalize the response from the server, I'm adding a relationshipType attribute from the links so that Ember Data knows what type of model to build when the relationship is polymorphic.
For example, here's the response from the server:
{
"members": {
"id": "1",
"created_at": "2014-10-15T18:35:00.000Z",
"updated_at": "2014-10-15T18:35:00.000Z",
"links": {
"user": {
"id": "1",
"type": "users",
"href": "http://test.host/api/v1/users/1"
},
"organization": {
"id": "2",
"type": "customers",
"href": "http://test.host/api/v1/customers/2"
}
}
}
}
The organization relationship is polymorphic, and the type in this instance is customers.
In the Ember application, I'm normalizing the response into following (which follows the RESTSerializer convention):
{
"members": {
"id": "1",
"created_at": "2014-10-15T18:35:00.000Z",
"updated_at": "2014-10-15T18:35:00.000Z",
"user": "1",
"userType": "users",
"organization": "2",
"organizationType": "customers"
}
}
This works, and Ember Data builds the correct user relationship and organization relationship (using the Customer model).
But, I'm receiving the following warning:
WARNING: The payload for '(subclass of DS.Model)' contains these unknown keys:
[userType,organizationType]. Make sure they've been defined in your model.
I'd like to remove these relationshipType keys and their values after they've been used.
Where should I do this?
Have you tried using https://github.com/kurko/ember-json-api? I may have some other overrides in my app to handle polymorphism but hopefully the package will get you closer.
Also see my pending PR.

Message property missing from post object retrieved?

I am trying to retrieve all comments of a certain user (not on a specific post but in a general way) using the Graph API.
I have come to understand that I need to query a user's posts and that the result will also contain that user's comments.
I manage to retrieve the list of posts for a specific user and I do see the comments the user posted.
However, the message property is always missing:
{
"id": "100005227004296_112167712300795",
"from": {
"name": "Karen Amebbgkdbif Lausen",
"id": "100005227004296"
},
"story": "\"Karens erster Kommentar zu...\" on Mike Amebkhdchid Letuchysky's photo.",
"story_tags": {
"35": [
{
"id": "100005200843894",
"name": "Mike Amebkhdchid Letuchysky",
"offset": 35,
"length": 27,
"type": "user"
}
]
},
"privacy": {
"value": ""
},
"type": "status",
"application": {
"name": "Photos",
"id": "2305272732"
},
"created_time": "2013-02-17T20:59:52+0000",
"updated_time": "2013-02-17T20:59:52+0000",
"comments": {
"count": 0
}
}
The story property contains a part of the message, but not all of it.
How can I access the full comment (text)?
Thanks in advance!
Alex
You may need to pull back additional properties such as type, status_type and description. If you like a link or comment on something else where and that appears in your timeline it can be returned from the post feed.
Try these fields in the graph API explorer to see what data is returned:
id,created_time,from,message,type,description,story,status_type

get Post like count with Facebook AP

i am trying to retrieve a facebook POSTs information (ie: LIKE count) using the facebook API
The URL which used to work was in this format:
https://graph.facebook.com/?ids=[AUTHOR_ID]_[POST_ID]
(author and post ID omitted on purpose)
Now it returns a false data feed. Has the URL structure to retrieve POST information changed?
With October 2013 Breaking Changes, likes.count field is no longer available in the feed.
You need to make a call for each POST_ID with the summary field enabled.
https://graph.facebook.com/POST_ID/likes?summary=true&access_token=XXXXXXXXXXXX
There will be a "summary" element with a "total_count" field.
Nope, that still works for me - just tested with one of my posts:
"id": "<SNIP>",
//removed most fields
"actions": [
{
"name": "Comment",
"link": "https://www.facebook.com/X/posts/Y"
},
{
"name": "Like",
"link": "https://www.facebook.com/X/posts/Y"
}
],
"type": "photo",
"status_type": "added_photos",
"object_id": "SNIP",
"application": {
"name": "Facebook for Android",
"namespace": "fbandroid",
"id": "350685531728"
},
"created_time": "2012-10-12T06:52:10+0000",
"updated_time": "2012-10-12T07:48:34+0000",
"likes": {
"data": [
// four likers' details
],
"count": 28
},
//snip
Check you still have read_stream Permission from your user, that the post hasn't been deleted, etc