Created
November 13, 2015 11:40
-
-
Save lucasecf/1d551900b591c84327f0 to your computer and use it in GitHub Desktop.
Example of ClientConfig use with Alamofire
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// EventClient.swift | |
// EventCast | |
// | |
// Created by Lucas Eduardo on 27/10/15. | |
// Copyright © 2015 RNCDev. All rights reserved. | |
// | |
import Alamofire | |
struct EventClient { | |
/** | |
Load all events of the local phone user | |
*/ | |
static func loadEvents(responseBlock: (events: [Event]?, error: NSError?) -> Void) { | |
//TODO: change this timeZone for the real one | |
Alamofire.request(.GET, "\(Config.Client.baseURL)/api/v1/event", parameters: ["phoneUser": PhoneUser.identifier!, "timeZone": "-0300"]) | |
.responseCollection { (response: Response<[Event], NSError>) in | |
responseBlock(events: response.result.value, error: response.result.error) | |
} | |
} | |
/** | |
Creates a new event with a eventName and with a Hashtag. The hashtag is unique, and the API returns "available: false" if the hashtag is already in use. | |
*/ | |
static func createEvent(eventName:String, withHashtag hashtag: String, responseBlock:(event: Event?, error: NSError?) -> Void) { | |
let eventParams = ["event" : ["name" : eventName, "hashcode" : hashtag, "phoneUser": PhoneUser.identifier!]] | |
Alamofire.request(.POST, "\(Config.Client.baseURL)/api/v1/event", parameters: eventParams, encoding: .JSON) | |
.responseObject { (response: Response<Event, NSError>) in | |
responseBlock(event: response.result.value, error: response.result.error) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment