I'm writing an external app that loads it's data from a drupal site, the site implemented "services" module which returns JSON representation of a node and (almost) all of it's data.
the one thing the service does not return is the url of the requested node,
so I'm calling this:
[domain]/rest/mynode/ffad3c26-e684-4cca-9c4b-16334f9f3dc1.json
and getting this:
{
vid: "2087",
uid: "67133de7-9755-424d-b45b-c4bbf41cb00e",
title: "PD300",
log: "Updated by FeedsNodeProcessor",
status: "1",
comment: "0",
promote: "0",
sticky: "0",
vuuid: "097f43ef-e22c-4f35-b74d-02b8e8ac5895",
nid: "2087",
type: "product",
language: "en"... and some more
I also need the url for the current node so I can link back to it from the app, any idea?
I think you just need to concatenate in your application the string something like that:
URL= "[domain]"."/node/"."{nid}"
Related
I would like to create a public Design Automation Activity and Package so other Forge apps with unknown ClientId & Secret can use our corporate DA tools. So I am setting the isPublic: true flag on the payload but, to my great despair, isn't working.
Take a look at my POST activity payload below:
const activityParams = {
id: DA_ACTIVITY_ID,
commandLine: [
`$(engine.path)\\accoreconsole.exe ` +
`/i \"$(args[inputDwg].path)\" ` +
`/al \"$(appbundles[${DA_APP_BUNDLE_ID}].path)\" ` +
`/s \"$(settings[script].path)\"`
],
parameters: {
inputDwg: {
description: "input .dwg",
localName: "input.dwg",
ondemand: false,
required: true,
verb: "get",
zip: false
},
result: {
description: "result .json",
localName: "result.json",
ondemand: false,
required: false,
verb: "put",
zip: false
}
},
settings: {
script: "(command \"EXTRACTGEOBIMDATA\")\n"
},
description: "GeoBIM Extract Data",
engine: DA_ENGINE,
appbundles: [
fullAppBundleId
],
isPublic: true
}
The first thing I notice is that the response after successful creation of activity doesn't contain the isPublic field:
The second thing I'm forced to notice is that attempting to execute a workitem against that activity result in an error:
Note that when run with the same credentials the activity and workitem are running perfectly fine.
Design Automation V3 let you use individual alias to share an Activity or AppBundle with a specific forge app.
If you look at the documentation when creating an alias for activity and AppBundle, there is an optional parameter you can set in the request body named "receiver". You can specify a forge app client id or nickname if the forge app you want to share with have one setup in Design Automation.
Note that if the Forge app you want to set as receiver use a nickname, you must use that nickname instead of the app client id.
https://forge.autodesk.com/en/docs/design-automation/v3/reference/http/activities-id-aliases-POST/
https://forge.autodesk.com/en/docs/design-automation/v3/reference/http/appbundles-id-aliases-POST/
We don't currently allow people to create public activities. This is because it is not clear how the parties could establish a trust relationship necessary. It sounds like in your scenario the sharing would happen within the same org. Would they have the same email domain (eg. xyz#somecompany.com would share with bla#somecompany.com)?
My web app sends an API POST request to create an application and returns JSON response. I want to access one particular JSON object from that response.
My JSON starts like this
[
{
"status_code": 201,
"body": {
"created": "2021-01-28T00:00:00Z",
"modified": "2021-01-28T00:00:00Z",
"id": "a2d86d17-9b3c-4c4d-ac49-5b9d8f6d6f8f",
"applicant": {
"id": "07f1e1d3-0521-401b-813e-3f777f2673c6",
"status": "Pending",
"first_name": "",
"last_name": "",
"URL": "some onboarding url"
And I wanna take that URL in the JSON response and visit it later in my cypress automation script.
Notice that the JSON repsonse starts with a square bracket not a curly bracket, which means, the whole response is an object, I assume?
My cypress script looks like this
cy.contains('button', 'CONTINUE').click()
cy.EmailGen('candidate').then(email => {
cy.get('#emails\\[0\\]').type(`${email}`)
cy.wrap(email).as('candidateEmail')
})
//writing intercept here, before the Send application button, which triggers the POST req.
cy.intercept('/hr/v1/applications/invite').as('getURL')
cy.get('button').contains('SEND APPLICATION').click({ force: true })
//waiting on the alias of intercept and using interception to print objects from response
cy.wait('#getURL').then((interception)=> {
cy.log(interception.response.body.applicant.URL)
})
cy.Logout()
The script executes with no errors. Just that nothing is logged in the cy.log statement. Below is the screen.
I also tried using another method as given below.
cy.intercept('/hr/v1/applications/invite',(req) => {
req.reply((res=> {
expect(res.status_code).to.equal('201')
expect(res.body.applicant.status).to.equal('Pending')
}))
})
In this case, I get a assert error embedded with the request and response along with some other stuff which I am unable to understand.
The complete error goes something like this...
"expected The following error originated from your test code, not from Cypress.\n\n > A response callback passed to req.reply() threw an error while intercepting a response:\n\nexpected undefined to equal '201'\n\nRoute: {\n "matchUrlAgainstPath": true,\n "url": "/hr/v1/applications/invite"\n}\n\nIntercepted request:{} Intercepted response: {} When Cypress detects uncaught errors originating from your test code it will automatically fail the current test. to include window.zE is not a function"
Its a bit weird to read this..
My application sometimes throws this exception, which I have handled using following code.
cy.on('uncaught:exception', (err, runnable) => {
expect(err.message).to.include('window.zE is not a function')
done()
return false
})
I really hope I have explained everything here. Please, help a noob.
Regards
As Richard Matsen suggested in the comments,
I used console.log(interception.response) and checked the console output in the browser controlled by Cypress.
I Noticed that the response json structure was something different than what I got in the network tab of developers tools, while using the web app.
The response was something like below...
{headers: {…}, url: "https://example.com/hr/v1/applications/invite/batch/", method: null, httpVersion: "1.1", statusCode: 200, …}
body: Array(1)
0:
body:
applicant: {id: "c6b2d686-d4f3-483e-abc8-e4641c365845", status: "Pending", first_name: "", last_name: "", email: "qa2+candidate879#example.com", …}
applicant_status: "NONE"
applicant_status_label: "None"
created: "2021-01-29T00:00:00Z"
get_applicant_status_display: "None"
id: "ad2939f5-c8ab-490a-a9e1-b0474de69e2c"
URL: "some url"
This made me modify the json traverse to
interception.response.body[0].body.applicant.URL
If others have a neat way to handle this, please let me know!
I would like to build an air cargo app. I want each cargo to be attached to one destination airport.
I found this JSON file. Sample:
"iata": "FOB",
"lon": "-123.79444",
"iso": "US",
"status": 1,
"name": "Fort Bragg Airport",
"continent": "NA",
"type": "airport",
"lat": "39.474445",
"size": "small"
Where should I put the JSON file in a rails 4 app?
How can I autocomplete airports both in "iata" and "name" field?
Given the size(~1.7mb) of the file which method other than "filter method" should I use, preferably in reactjs?
First, I would create a rake task or something similar to run the JSON to the dedicated database table (for example model called Airport). Here is some examples for running JSON to the database. This way you can also update the airport data when it has changed and the searching becomes much easier since you can use ActiveRecord for it.
Second, I would probably place the JSON file under config/ folder.
And finally about autocomplete. Since you haven't too explicitly told what you wish from the autocomplete, you could for example use jQuery-Autocomplete with what you could write something like this
$('#autocomplete').autocomplete({
lookup: function (query, done) {
// Do ajax call with the query
$.ajax("www.your-api.com/search?query=" + query).done(function (data) {
done({result: data});
});
},
onSelect: function (suggestion) {
alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
}
});
It is quite impossible to give better instructions on how to do the autocomplete, but this way you can anyway autocomplete by 2 different fields.
I searched for a clear explanation on how this works but was not able to find one yet. I'm looking for a clear and detailed explanation with the assumption that I'm a total newbie with all these frameworks.
So here's my problem, I'm writing an app with frontend using Ember.js (with Ember-cli) and backend under Play-framework in Java. I'm trying to get my frontend to digest some json coming out from my API. Here's the json :
{
"buildings": [
{
"id": 0,
"createdDateTime": "2015-03-27T06:39:19.913Z",
"address": {
"id": 1,
"city": "City",
"civicNumber": 1287,
"country": "Canada",
"postalZipCode": "G1Q1Q9",
"provinceOrState": "QC",
"streetName": "A Street Name"
},
"cost": 1000000,
"earnings": 2300,
"mainPicturePath": "http://dummyimage.com/200x200/999/fff.png&text=Building",
"type": "DUPLEX",
"yearOfBuilt": 1998
},
{
"id": 1,
"createdDateTime": "2015-03-27T06:39:19.935Z",
"address": {
"id": 2,
"city": "City",
"civicNumber": 1289,
"country": "Canada",
"postalZipCode": "G1Q1Q9",
"provinceOrState": "QC",
"streetName": "A Street Name"
},
"cost": 980000,
"earnings": 670,
"mainPicturePath": "http://dummyimage.com/200x200/999/fff.png&text=Building",
"type": "TRIPLEX",
"yearOfBuilt": 1980
}]
}
And here's my emberjs code :
//models/building.js
export default DS.Model.extend({
type: DS.attr('string'),
address: DS.belongsTo('address', {embedded: 'always'}),
cost: DS.attr('number'),
yearOfBuilt: DS.attr('number'),
earnings: DS.attr('number'),
createdDateTime: DS.attr('date'),
mainPicturePath: DS.attr('string')
});
//models/address.js
export default DS.Model.extend({
civicNumber: DS.attr('number'),
streetName: DS.attr('string'),
city: DS.attr('string'),
provinceOrState: DS.attr('string'),
country: DS.attr('string'),
postalZipCode: DS.attr('string'),
building: DS.belongsTo('building', {embedded: 'always'})
});
//serializers/building.js
export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
address: {embedded: 'always'}
}
});
This doesn't throw any errors and works fine. The problem is, I don't fully understand the code for the embedded object address in building (I do understand how the DS models, the export from ember-cli and the belongsTo work). Could someone explains me in details how does it works (the RESTSerializer with EmbeddedRecordsMixin, the {embedded: 'always'} attribute and the other available options)? Any clarifications will be more than appreciated.
Lets also bring this to the next level, say I do not want to have an id for each address since they should never be used more than once (cannot have 2 buildings at the same address). How would I achieve that? Maybe I will store the address in the same record of my building object in the db and don't want an extra table for addresses. Based on these solutions, what would be the best approach (feel free to propose better solution if you have)?
Please be advised that I have already read the following links :
Ember-data: deserialize embedded model
http://mozmonkey.com/2013/12/loading-json-with-embedded-records-into-ember-data-1-0-0-beta/ (which doesn't say anything about EmbeddedRecordsMixin)
How to access nested object in json with Ember data (talking about the App.Adapter.Map which I don't understand either)
https://github.com/lytics/ember-data.model-fragments (Very interesting project that may quit be exactly what I'm looking for)
Thank you!
The answers to most of your questions can be found by closely reading the EmbeddedRecordsMixin Docs
Specifically:
using { embedded: 'always' } as an option to DS.attr is not a valid
way to setup embedded records.
(meaning as long as you've defined your belongsTo relationship you're good)
and
The attrs option for a resource { embedded: 'always' } is shorthand
for:
1 {
2 serialize: 'records',
3 deserialize: 'records'
4 }
But the real answer is, it's all in the code! Go read here and a little bit further down here, it's written pretty well and you should be able to trace what's going on.
Basically what happens is once you tell the serializer that there are embedded records (via {key: {embedded: 'always' } }), it will find that key in your JSON and deserialize it into an Ember object (as long as it finds a defined Ember object with that key, in your case 'address').
As far as your next level questions, I'd respond with my own question: Do your buildings have tenants? If so, they will probably have addresses, and you'll likely want to access it through tenant.address, rather than tenant.building.address, so go ahead and make address it's own table. It will likely save you some headaches in the near future.
I have a json file in my android local device, im able to read and edit the json file and store json data in it.
But the problem is arising when i want to insert new element in the json file. Im able to change the value of existing variables.
the json file data is:
var data = {items:
{id: "1", name: "Snatch", type: "crime"}
};
i want to add one more element to it so that json file will look like
var data = {items: [
{id: "1", name: "Snatch", type: "crime"},
{id: "7", name: "Douglas Adams", type: "comedy"}
};
i tried with
data.items.push{id: "7", name: "Douglas Adams", type: "comedy"}
but its not working.
im creating android app using phonegap framework with telerik IDE.
Try
data.items.push(
{id: "7", name: "Douglas Adams", type: "comedy"}
);
You are missing ()
Your first file example is missing []
Check out this links to know more about json addition and removal
Link 1 , Link 2