Asynchronous HTTP request - how do I know when ready ? swift 2 - swift2

I'm building a class to retrieve METAR data (weather info) for certain location.
in class initializer im using swiftHTTP to make HTTP post request to retrieve XML with data.once I have the XML data I parse it and retrieve the temperature info and assigning it to class property.
The problem is that when I instantiate the class and try to access the temperature property it is still empty.
I know that its because the call is asynchronous , but how do I design this all correct so that after instantiating I can get the temperature property already with the retrieved value ?
Thanks
Yuval

Related

Api Platform - returning data from external API

I'm currently using API Platform to display some data in Elasticsearch. This works fine, but I now have another feature that I'm looking at.
My application needs to deal with a 3rd-party API that needs to hit an endpoint and return some data.
Within my app, I'd like to be able to hit (/api/logistics/{action} - where action is an endpoint, such as login) and this then hits my app layer and returns data (3rd-party can be re-named)
The API calls to the 3rd party are fine, but I'm unsure how to display the response.
I've seen https://api-platform.com/docs/core/data-providers/ which looks like i can create a custom response.
Do i still need to create an entity/model and configure the #ApiResource() with a controller that uses my Data Provider?
If so, then what do i need to add in my annotation, since I won't have an id identifier
I'm fairly new to API Platform and I've not used the Data Provider functionality before
I will not be storing the data from the 3rd party API, just doing a HTTP call, retrieving the response and hopefully displaying it via Api Platform
Thanks
You are mosly right about the dataprovider. But as the docs page General Design Considerations states, "you have to write a plain old PHP object (POPO) representing the input and output of your endpoint. This is the class that is marked with the #ApiResource annotation. This class doesn't have to be mapped with Doctrine ORM, or any other persistence system."
So no, it does not need to be an Entity, but there must be a class marked with the #ApiResource annotation (but putting it in the Entity folder may help to make the #ApiResource() tag work - or adding the folder of your class in api/config/packages/api_platform.yaml).
For an item "get" endpoint your POPO needs an id. The poperty - or if there is only a getter, the getter - must be marked with the #ApiProperty(identifier=true) tag. Usually the easiest way to make one is by imploding/encoding some strings from the response of the external api call that together are unique for the response and will not change. Your dataprovider will have to explode/decode the id and use the components to make the external api call.
For a "post" operation you need a datapersister instead of a dataprovider. Apip will instatiate and populate your POPO and pass it to the datapersister and from there you can make the call to the external api and return an object as the result. If your object is not the same type of POPO you should specify "output"=TheOutputClass::class or put the operation on the output class and specify "input"=TheInputClass::class (replace TheOutputClass or TheInputClass by the actual class name)
For "put" and "patch" you need both a dataprovider, a datapersister and an id. They can have different input and output classes, see the docs about DTOs.
A collectionoperations with method "get" may seem convenient because you can just pass it any query string but your CollectionDataProvider must return an iterable.

Filenet Change Document Class

I'm trying to change class for a given document and below is the code that I used
Document p8Document = Factory.Document.getInstance(p8ObjectStore,
oldDocumentClassName, new Id(documentId));
p8Document.changeClass(newDocClassName);
p8Document.save(RefreshMode.REFRESH);
Upon executing the code, I can see that document class is being changed successfully. Now the problem is if I run the code again for the same guid, the below line fetches the document again with the old document class name.
Document p8Document = Factory.Document.getInstance(p8ObjectStore,
oldDocumentClassName, new Id(documentId));
By using getInstance, you are not asking the server to verify the existence of the object. Use fetchInstance instead.
From Instantiating Objects
The getInstance methods are used to instantiate an object that references a server object that is assumed to already exist. The existence of the object is not verified on the Content Engine server, and no round trip to the server is made until you perform a function on the object
getInstance is a way that you can setup an object while avoiding a trip to the CE server.
The fetchInstance methods instantiate an object by first making a round-trip to the Content Engine server and retrieving ("fetching") property values.
fetchInstance actually will retrieve the object from the CE server.

OData V4 (webapi) patch with NavigationProperty collection breaks deserailization on server

I’m trying to go against a Web API Patch method that accepts a Delta. My entity has a navigational property that is a collection. The domain model is trivial, I have a team (entity) and a collection of members (navigational property).
I’m using HttpClient directly instead of the OData client.
The problem I’m running into is that when I send a patch request with the payload = a Team, the Delta deserialized in my controller is null when I include the navigational property collection in my payload.
Eg (ignore that the missing quotes, this is typed in}:
{ Name: Foo } -> serializes to Delta successfully.
{Name: Foo, Members : [] } -> fails to serialize and Delta is null.
Is this supported? I could not find concrete documentation online about whether you can supply navigational properties as an entire collection on patch (not looking for merge support, just want full replace of the collection.)
I also tried tweaking my client to directly send a Delta payload, but the default JsonMediaTypeFormatter is unable to serialize this into a valid request body (always produces empty Json), and the ODataMediaTypeFormatter throws an exception saying it cannot write an object of type Delta, although I have initialized it with every ODataPayloadKind.
I’m sure I’m either doing something wrong or missing something basic, assuming using Delta + patch with HttpClient is not this challenging.
For OData spec, it says:
11.4.3 Update an Entity
...
The entity MUST NOT contain related entities as inline content. It MAY contain binding information for navigation properties. For single-valued navigation properties this replaces the relationship. For collection-valued navigation properties this adds to the relationship.
That is you can't put the navigation properties in the Patch request content.
From Web API OData, it has these codes and these codes. It means that it doesn't allow to patch navigation property form entity.
However, you can shoot your target by following steps:
Patch the principal entity (team)
Patch the dependent entities (members)
use the $ref to update the link
You can refer to my simple test project.

How can I test Restkit object serialization / upload?

I've figured out how to test the download mapping for objects, but I'm at an utter loss to test the inverse -- that objects properly serialize back into JSON.
You should be able to use RKMappingTest in just the same way for both serialisation and deserialisation. Supply a request mapping instead of a response mapping. The source object will be one of your model classes. The destination object will be a mutable dictionary. Expectations are set in the same way.

How to debug an entity's validation mapping in Symfony 2.4?

I would like to determine whether an entity property is required or not.
Does anyone know how to access all of the constraints for a given entity property?
I want to check if the NotBlank constraint is active for a certain propery.
information:
You can check the mapping information for a class (or object) with the help of the service:
validator.mapping.class_metadata_factory
The underlying class is:
Symfony\Component\Validator\Mapping\ClassMetadataFactory
The service provides a method getMetadataFor() that allows you to obtain the active mapping metadata for a class (or object).
This method returns an instance of...
Symfony\Component\Validator\Mapping\ClassMetadata
... that provides a getPropertyMetadata(string $property) method that returns the Metadata for a given property name.
example usage:
Inside a controller (or any other ContainerAware instance) you can do:
$factory = $this->container->get('validator.mapping.class_metadata_factory');
$classMetadata = $factory->getMetadataFor('Your\Bundle\Entity\Name');
$propertyMetadata = $classMetadata->getPropertyMetadata('propertyName');
View the list of Supported Validation Constraints Reference from Symfony web site
You can try ladybug bundle. It is very easy to use and shows in detail and nicely to see all properties and info inside an object.

Resources