erkie / apimodel Goto Github PK
View Code? Open in Web Editor NEWInteract with API's using Realm (realm.io) and REST
License: MIT License
Interact with API's using Realm (realm.io) and REST
License: MIT License
A builder is a class that takes care of parsing response objects into meaningful models. They should be able to be defined on an entire model, but also per request
Assertions: XCTAssertEqual failed: ("Optional("2015-12-30")") is not equal to ("Optional("2015-12-29")") -
File: NSDateTransformTests.swift:68
https://www.dropbox.com/s/eoykto1ti3jgo31/Screenshot%202016-01-19%2009.54.56.png?dl=0
How do I go about setting additional request headers?
Alamofire.Manager.sharedInstance.session.configuration.HTTPAdditionalHeaders = ["X-User-Id" : "abc"]
Alamofire.Manager.sharedInstance.session.configuration.HTTPAdditionalHeaders = ["X-User-Token" : "def"]
The rootNamespace property is never used and has no effect. Responses in format:
{"status":"ok","data":{"contacts":[{"id":"1","firstname":"jack","lastname":"white","prefi ...
Can therefore not be handled by specifying config.rootNamespace = "data"
Implement a testing framework and write tests to test base functionality.
I been working on an REST jadada for Realm now for months... Glad to see someone beat me to it! ;)
It's really impressive and the code looks really good.
It doesn't work though. At all.
Currently JSON is assumed in output and input. Implement a generic parser interface that can be overridden and configured using apiConfig
s.
Currently fromJSONMapping
is converted to camelcase to match property names on the model, but in JSONDictionary
it is not converted to anything.
So: Implement a case conversion setting on a global basis and on a per-model basis, like api_config
in api-model.
If a server response for a findArray call is not a success, only an empty array is returned, and no way to distinguish that something went wrong.
Thoughts on this?
Should the response object be passed to the calllback?
or maybe an error object?
At this moment the use of namespace on model is mandatory. In addition, the namespace is shared between both request and response.
It can happen that in some cases you don't want to wrap request or response
Lets say that you make a request with json presented bellow
{
"user": {
"email": "[email protected]",
"password": "Password1"
}
}
the expected response is parsed to object only if it is wrapped in the same namespace
{
"user": {
"id": 1,
"email": "[email protected]"
}
}
desired behavior would work also with the following response
{
"id": 1,
"email": "[email protected]"
}
The same thing is valid for unwrapped requests.
Server responses don't always use keys you'd like to use in your code. This could be handled by creating private vars in classes and public vars which are wrappers, but it would be cleaner if the model transforms could accept a 'destination key' rather than directly mapping the JSON key into the model object.
This PR -> #29, shows how validation errors are lost. But the question is who should own knowning what a validation error means? ApiModel or the implementer?
Should ApiModel conform to standard rails json for errors?
Should ApiModel Objects contain virtual (or realmed) errors?
Should Server error json be standardized? as to populate the error message from json instead of hardcoded default errror message seen here -> https://github.com/AdeptMobile/ApiModel/blob/6e33fa9aaa4143bf9a7ee9ab0ebf9d4d0141671b/Tests/ApiFormTests.swift#L84
Food for thought.
Is possible to have orphaned objects identified & deleted?
Just like api_config
in api-model. Perhaps:
import RealmSwift
import ApiModel
class Post: Object, ApiTransformable {
public class func apiConfig() -> ApiConfiguration {
return ApiConfiguration(
host: "http://example.com/api/v1/",
parser: JSONParser()
)
}
}
I'm thinking something like this:
import APIModel
import Realm
class User: Object, ApiTransformable {
dynamic var name = ""
dynamic var avatar = ""
func JSONDictionary() -> [String:Anyobject] {
var avatarPath = NSBundle.mainBundle().pathForResource("avatar", ofType:"jpg")
return [
"name": name,
"avatar": NSData(contentsOfFile: avatarPath)
]
}
}
Would love help on this.
Either:
rename everything -> prefix with `API`
Or
rename this project -> `ApiModel`
Is it possible to reference API requests in Objective c?
My response payload primary key is "id"
However I wish to store it in my model as "primaryKey".
Reasoning:
ApiForm
currently deals with all interactions towards an Api, and is more conceptually than just a form. So:Api<Post>.get("v1/posts.json") { response in /* ... */ }
Api<User>.delete("v1/posts.json") { response in /* ... */ }
Api(model: user).save()
Api
should be called, maybe ApiManager
ApiTransformable
to ApiModel
, I think...Not sure if I'm doing something wrong, but I have a request whose response is a simple array of dictionaries and it fails to map. I have resolved this by adding a line to ApiForm.swift (line 286):
if let arrayData = data as? [AnyObject] { return arrayData }
but I'm not sure if this is correct. Without this it's always trying to handle the response as a dictionary so it fails out.
Look into making it more extensible with custom routes
Our API's return object associated objects.
Is it possible for multiple object types to be mapped for one endpoint?
Any thoughts on using ObjectMapper for mapping the responses to Realm Objects?
If any configuration of the Alamofire manager is required there is currently an issue getting access to that as the sharedInstance is the only option. It should be possible to create and supply a custom manager instance.
#24 demonstrates 500 errors that are not "invalid".
Was this intentional? Should we make invalid responses include 500 status codes?
Should it be handled differently?
It should be easy to modify and turn off/on.
Try to implement ActiveResource-style finders with find(id)
etc.
If the API has a standard of using snake_case
but in Swift we use camelCase
, create case converters that can be configured globally and locally.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.