Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. class Api::V1::RestaurantsController < ApplicationController
  2. http_basic_authenticate_with name: "api", password: ENV['API_SECRET']
  3.  
  4. var latitude = 48.858564
  5. var longitude = 2.294476
  6. let PasswordString = "api:1234" //username:password
  7. let PasswordData = PasswordString.dataUsingEncoding(NSUTF8StringEncoding)
  8. let base64EncodedCredential = PasswordData!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)
  9.  
  10. let urlPath: String = "http://localhost:3000/api/v1/restaurants?latitude=(latitude)&longitude=(longitude)"
  11.  
  12. var url: NSURL = NSURL(string: urlPath)!
  13.  
  14. var request: NSMutableURLRequest = NSMutableURLRequest(URL: url)
  15. request.setValue("Basic (base64EncodedCredential)", forHTTPHeaderField: "Authorization")
  16. request.HTTPMethod = "GET"
  17.  
  18.  
  19. NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler:{ (response: NSURLResponse!, data: NSData!, error: NSError!) -> Void in
  20. var err: NSError
  21. var jsonResult: NSDictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as! NSDictionary
  22. println("(jsonResult)")
  23. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement