Skip to content

Instantly share code, notes, and snippets.

@moudy
Created March 13, 2015 18:10
Show Gist options
  • Save moudy/7fbdc6448ce7b9c0341a to your computer and use it in GitHub Desktop.
Save moudy/7fbdc6448ce7b9c0341a to your computer and use it in GitHub Desktop.
extension DataStore {
enum Endpoint {
case OrganizationPosts(String)
case LikePost(Int)
case CreatePost
case CreatePostComment(Int)
case GetPostComments(Int)
var path: (method: Alamofire.Method, url:String) {
switch self {
case .CreatePost:
return (.POST, "organizations/me/posts")
case .OrganizationPosts(let organizationId):
return (.GET, "organizations/\(organizationId)/posts")
case .GetPostComments(let postId):
return (.GET, "posts/\(postId)/comments")
case .CreatePostComment(let postId):
return (.POST, "posts/\(postId)/comments")
case .LikePost(let postId):
return (.POST, "posts/\(postId)/like")
default:
return (.GET, "error")
}
}
func route(origin: String) -> (Alamofire.Method, String) {
return (path.method, "\(origin)/\(path.url)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment