How to handle different data type for same property for a HTTP or REST API - web-services

I work on a web application using AngularJS for the frontend and the backend for Symfony2. I want to make a web service so I can have a one page app. I am wondering about how I should handle the data exchange between the two layers.
Consider this use case:
A user wants to create a project in the application and must specify whether it be as a customer or supplier in that project. The creator of the project gives the project a name and a description. Then he enters the email address of the contact person (who will be the customer or supplier in the project depending on the choice of the user who created the project). When creating the project the system checks whether the contact person is already registered otherwise it sends an invitation to join the application and waits. It is not necessary to invite the contact person at the creation of a project that can be done later.
I imagine the API is as follows:
POST http://app.com/api/projects
Request:
{
"name": "My Project"
"descrption": "My Project'description"
"vendor": {
"user_id": 3245
}
"client": "myclient#email.com"
}
Response:
{
"name": "My Project"
"description": "My Project'description"
"vendor": {
"user_id": 3245,
"name": "John Doe"
}
"client": {
"user_id": 2754,
"name": "Peter Doe"
}
"creator": {
"user_id": 3245,
"name": "John Doe"
}
}
So we can see that the type of data exchanged in the creation of a project differs.
Can I link directly to my model application (after validation of course)?
How should I go about updating a project?
Is it better to create Transfer Objects and managed into my business logic and a TransfertObject for input and one for output?

Related

What are all the steps involved with changing an Alexa Skill name?

I submitted a skill to Amazon for Alexa, and it failed certification due to intellectual property rights. Amazon suggested that I say the service is "for" the IP rights holder, so I modified the name and am now getting this error for everything I try to do.
{
"errorMessage": "Exception: TypeError: Cannot read property 'application' of undefined"
}
So far, I updated the Skill Name, Invocation Name, and Welcome Message. Is there something else I need to update or run on the dev portal to get this to work again?
Update: When I try to start the skill from the Alexa Development portal, I see this in the logs for
console.log("event.session.application.applicationId=" + event.session.application.applicationId);
{
"version": "1.0",
"session": {
"new": true,
"sessionId": "SessionId.8b65b2f5-0193-4307-9bef-88c116d9344b",
"application": {
"applicationId": "amzn1.echo-sdk-ams.app.5987b947-c8e9-4fc4-a0b8-2ba12c57ea59"
},
"attributes": null,
"user": {
"userId": "amzn1.ask.account.ABCDEFG" // masked my account value
}
},
"request": {
"type": "IntentRequest",
"requestId": "EdwRequestId.4d19f589-cdca-4303-99dc-0dc5cec781d2",
"timestamp": "2016-04-18T16:21:04Z",
"intent": {
"name": "DontKnowIntent"
}
}
}
The application ID matches the one supplied in the Alexa Development portal, so I don't think that's causing any issues. The property 'application' is only ever called after 'session', which clearly is defined. I don't know if the null attributes is causing an error. Maybe someone can look at a successful request?
Finally, here is my code: https://github.com/Shwheelz/alexa-skills-kit-js/blob/master/my_skills/pokemonTrivia/src/index.js
I have changed the name twice before on a node app and a Java 8 app. All I had to do was change the name (also changed invocation name) under the skill information. It worked first time out. Now my skill name did not update on alexa app once and did the other time. Since you are not certified, you may want to create the skill for scratch. This should only take about 5 or 10 mins. Just do not forget to change or add the new application Id of you lambda

facebook group members Bio information

I am interested in retrieving a Facebook group members' Bio information.
I have created an app where I have requested permission of about user_about_me and the app is under review for submission.
I have coded for the app in JSP but it can only select name, gender, last_name, first_name only. It is not selecting the Bio information.
I face the same problem even in the graph API explorer, when I use
{group_ID}/members
I can retrieve list of all group members. But I can not see more details than the following:
"data": [
{
"name": "name",
"administrator": false,
"id": "USER ID"
},
..
When I click on the ID (or enter the ID in the explorer), I can only get the following:
{
"id": "member_ID",
"first_name": "firstname",
"last_name": "lastname",
"link": "https://www.facebook.com/app_scoped_user_id/...",
"name": "name ",
"updated_time": "2015-02-07T10:02:58+0000"
}
This is not showing the Bio information.
when I enter the following:
{member_ID}?fields=bio
I just get
{
"id": "10153223503039309"
}
I will appreciate if someone please identify me the problem. I believe this problem will also solve my code problem, where at the moment I am unable to retrieve the group member's Bio information too.
Is it possible that the problem will be resolved after the app's acceptance, which is under review?
Thanks you very much.
Syed
You can´t just grab more information from the user just because he is a member of some group. You would have to let him authorize your App with the correct permissions in order to get more data.

Get total number of Custom Actions on Open Graph Object

I want to access number of custom actions (that I've defined) done on my Open Graph object. Facebook will return number of Like actions in response(like this) but they don't include number of custom actions.
Apps can retrieve actions published for the authorized user. For example, a Recipe app can retrieve all the recipes I've cooked or plan on cooking and customize the app experience based the data.
This API returns the action’s metadata including timestamps along with custom properties and their values. Objects referenced from an action are returned a single level deep.
GET /{action-instance-id}
The following retrieves a specific action instance
https://graph.facebook.com/{action-instance-id}?access_token=USER_ACCESS_TOKEN
Response
{
"id": "1538292028372"
"start_time": 1303502229,
"end_time": 1303513029,
"data": {
"type": "recipebox:recipe",
"url": "http://www.example.com/pumpkinpie.html",
"id": "1234567890",
"title": "Pumpkin Pie"
},
}
The above content is from FB Documentaion

Using the Django API

First of all, any help with this would be amazing! I am currently trying to learn Django and am also fairly new to Python. I am trying to create a simple project management web service that could communicate using JSON with another application. All it needs to do is:
Give a list of all projects.
Give a list of all tasks for each of the projects.
Allow users to submit time for a project and task.
For models I currently have a 'Project' model and 'Task' model. I have filled the database with some dummy information. My project model has variables id, name, and description. Task just has project, task_name.
My view for task 1 above is
def api(request):
projects = Project.objects.all()#.order_by('id')
projects = serializers.serialize('json', projects, indent=2)
return HttpResponse(projects, mimetype='application/json')
associated url is url(r'^api/project/$', 'project.views.api'),
However this outputs the text below when typing
http://127.0.0.1:8000/api/project/
into the browser. Is there a better way to test JSON output? I would rather it only output the 'id' and 'name'. For some reason the id doesn't even show. This is what I put for id in models id = models.AutoField(primary_key=True). It works in the interactive shell.
[
{
"pk": 1,
"model": "project.project",
"fields": {
"name": "Project One",
"description": "This is the description for project one"
}
},
{
"pk": 2,
"model": "project.project",
"fields": {
"name": "Project Two",
"description": "This is Project Two"
}
}
]
I learn by example so if someone could show me how this should be done I would be extremely grateful!
By the way for outputting the list of tasks, I was thinking the url would be something like:
http://127.0.0.1:8000/api/project/?project_name
but I'm not sure how to handle that in the view.

Can we post Actions on an object outside of the app (ie FB Page, FB Place)?

Is it at all possible to post an action (owned by the app) to an object (NOT owned by the app)? Specifically on Faceook Page and Places, objects owned by FB.
For example I want to create an action called "shop", so that I can create the action
"John drank *Coke*"
in which Coke refers to the FB Page.
I have done a test via the Graph API Explorer and it seems that the app's action POST must refer to an object also owned by the same app. Mind you, I also do not know what shud be syntax to refer to objects owned by FB.
You can tag a place to a post but it will simply prefix it with " -at Walmart"
Yes, this is possible. To set the "at Walmart" part, set the action's "place" field when creating an action via a POST. For example, you can pass this:
?place=https://www.facebook.com/pages/Pizzeria-Delfina/53645450697
which should result in setting the place on an action like:
"place": {
"location": {
"city": "San Francisco, CA",
"zip": "94110",
"country": 398,
"region": 0,
"address": "3611 18th Street/2406 California St.",
"id": 2421836
},
"id": "53645450697",
"name": "Pizzeria Delfina"
},
Documentation on the basic action properties is here:
https://developers.intern.facebook.com/docs/beta/opengraph/actions/#create