-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ae349d
commit 2a963d4
Showing
5 changed files
with
73 additions
and
30 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// YQL.h | ||
// yql-ios | ||
// | ||
// Created by Guilherme Chapiewski on 10/19/12. | ||
// Copyright (c) 2012 Guilherme Chapiewski. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface YQL : NSObject | ||
|
||
- (NSString *)query:(NSString *)statement; | ||
|
||
@end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// YQL.m | ||
// yql-ios | ||
// | ||
// Created by Guilherme Chapiewski on 10/19/12. | ||
// Copyright (c) 2012 Guilherme Chapiewski. All rights reserved. | ||
// | ||
|
||
#import "YQL.h" | ||
|
||
#define QUERY_PREFIX @"http://query.yahooapis.com/v1/public/yql?q=" | ||
#define QUERY_SUFFIX @"&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=" | ||
|
||
@implementation YQL | ||
|
||
- (NSString *) query: (NSString *)statement { | ||
NSLog(@"Start yql call"); | ||
|
||
NSString *query = [NSString stringWithFormat:@"%@%@%@", QUERY_PREFIX, [statement stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding], QUERY_SUFFIX]; | ||
|
||
NSLog(@"Request URL: %@", query); | ||
|
||
NSData *jsonData = [[NSString stringWithContentsOfURL:[NSURL URLWithString:query] encoding:NSUTF8StringEncoding error:nil] dataUsingEncoding:NSUTF8StringEncoding]; | ||
NSError *error = nil; | ||
NSDictionary *results = jsonData ? [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error] : nil; | ||
|
||
if (error) NSLog(@"[%@ %@] JSON error: %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), error.localizedDescription); | ||
|
||
NSLog(@"Results: %@", [results valueForKeyPath:@"query.results"]); | ||
|
||
NSLog(@"Done yql call"); | ||
|
||
return [NSString stringWithFormat:@"%@", [results valueForKeyPath:@"query.results"]]; | ||
} | ||
|
||
@end |