Code Monkey home page Code Monkey logo

apimodel's People

Contributors

cheneveld avatar erkie avatar gf3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

apimodel's Issues

Custom builders

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

Set default request headers

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"]

rootNamespace property is never used

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"

Write tests

Implement a testing framework and write tests to test base functionality.

Finally!

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.

@erkie

Implement custom parsers

Currently JSON is assumed in output and input. Implement a generic parser interface that can be overridden and configured using apiConfigs.

Standardize case for incoming/outgoing data

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.

Thoughts on findArray networking issues

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?

Make Namespace Optional for Request and/or Response

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.

support response key to model key mapping

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.

Distinguishing between Server errors and validation errors

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.

Global and model-local configuration settings

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()
    )
  }
}

Support file uploads within models

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) 
         ]
     }
}

Rename `ApiForm` to `Api` and `Api` to `ApiManager`

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()
  • Not entirely sure about what Api should be called, maybe ApiManager
  • In the long run, I want to rename ApiTransformable to ApiModel, I think...

array of dictionaries JSON response

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.

500 server error's are not invalid

#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?

Custom case converters

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.