Last active
August 29, 2015 14:06
-
-
Save jeffdonthemic/e35758017695d541f8ef to your computer and use it in GitHub Desktop.
Swift HP IDOL OnDemand
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
$ curl -v -X POST -d apikey=YOUR-HP-IDOL-ONDEMAND-APIKEY \ | |
-d url=http://ecx.images-amazon.com/images/I/41FmUAMH4mL._SY300_.jpg \ | |
https://api.idolondemand.com/1/api/sync/ocrdocument/v1 | |
< HTTP/1.1 200 OK | |
< | |
{ | |
"text_block": [ | |
{ | |
"text": "TESLA\nWAS\nTHE 4,, ,gé;)\nMAN", | |
"left": 0, | |
"top": 0, | |
"width": 300, | |
"height": 300 | |
} | |
] |
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
import Foundation | |
import XCPlayground | |
XCPSetExecutionShouldContinueIndefinitely() | |
/** | |
Paste all the code from the following file | |
- https://github.com/lingoer/SwiftyJSON/blob/master/SwiftyJSON/SwiftyJSON.swift | |
**/ | |
let apiKey = "YOUR-HP-IDOL-ONDEMAND-APIKEY" | |
let ocrImageUrl = "http://ecx.images-amazon.com/images/I/41FmUAMH4mL._SY300_.jpg" | |
let endpoint: NSURL = NSURL(string: "https://api.idolondemand.com/1/api/sync/ocrdocument/v1") | |
let request = NSMutableURLRequest(URL: endpoint) | |
request.HTTPMethod = "POST" | |
let payload = "apikey=\(apiKey)&url=\(ocrImageUrl)".dataUsingEncoding(NSUTF8StringEncoding) | |
let task = NSURLSession.sharedSession().uploadTaskWithRequest(request, fromData: payload, completionHandler: {data, response, error -> Void in | |
if let value = data { | |
var error:NSError? = nil | |
if let jsonObject : AnyObject = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: &error) { | |
let json = JSONValue(jsonObject) | |
if let ocr_results = json["text_block"][0]["text"].string { | |
println(ocr_results) | |
} | |
}else{ | |
println(error) | |
} | |
} | |
}) | |
task.resume() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment