2

I am trying to build an iPhone application with capabilities of searching Yelp's database using an API. I have never used an API before (I'm a student- not much professional development experience), so I need a very simple walkthrough on how to pull data overall, filter, and authenticate myself to actually get the data. I'd also like to learn how to save the location's identifier into a Plist so the app can store which places the user visited. This help is much appreciated. Thank you!

I found this online, but I can't make much sense of it. Can someone explain?

class YelpClient: BDBOAuth1RequestOperationManager {

var accessToken: String!
var accessSecret: String!

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
}

init(consumerKey key: String!, consumerSecret secret: String!, accessToken: String!, accessSecret: String!) {
    self.accessToken = accessToken
    self.accessSecret = accessSecret
    var baseUrl = NSURL(string: "http://api.yelp.com/v2/")
    super.init(baseURL: baseUrl, consumerKey: key, consumerSecret: secret);

    var token = BDBOAuthToken(token: accessToken, secret: accessSecret, expiration: nil)
    self.requestSerializer.saveAccessToken(token)
}

func searchWithTerm(term: String, parameters: Dictionary<String, String>? = nil, offset: Int = 0, limit: Int = 20, success: (AFHTTPRequestOperation!, AnyObject!) -> Void, failure: (AFHTTPRequestOperation!, NSError!) -> Void) -> AFHTTPRequestOperation! {
    var params: NSMutableDictionary = [
        "term": term,
        "offset": offset,
        "limit": limit
    ]
    for (key, value) in parameters! {
        params.setValue(value, forKey: key)
    }
    return self.GET("search", parameters: params, success: success, failure: failure)
}

}
Bora
  • 248
  • 3
  • 15

0 Answers0