Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Commit

Permalink
Adding TwitterSearch client
Browse files Browse the repository at this point in the history
  • Loading branch information
mattt committed Oct 31, 2011
1 parent 6de3863 commit 81e8eb2
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 19 deletions.
6 changes: 6 additions & 0 deletions IOSBoilerplate.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
D8EA24CF145BA4AC00EB08B3 /* right@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = D8EA24CB145BA4AC00EB08B3 /* right@2x.png */; };
D8EA24D3145BA4BC00EB08B3 /* BrowserSampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D8EA24D1145BA4BC00EB08B3 /* BrowserSampleViewController.m */; };
D8EA24D4145BA4BC00EB08B3 /* BrowserSampleViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D8EA24D2145BA4BC00EB08B3 /* BrowserSampleViewController.xib */; };
F87266BC145EF4E200B775D3 /* TwitterSearchClient.m in Sources */ = {isa = PBXBuildFile; fileRef = F87266BB145EF4E200B775D3 /* TwitterSearchClient.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -212,6 +213,8 @@
D8EA24D0145BA4BC00EB08B3 /* BrowserSampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BrowserSampleViewController.h; sourceTree = "<group>"; };
D8EA24D1145BA4BC00EB08B3 /* BrowserSampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BrowserSampleViewController.m; sourceTree = "<group>"; };
D8EA24D2145BA4BC00EB08B3 /* BrowserSampleViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BrowserSampleViewController.xib; sourceTree = "<group>"; };
F87266BA145EF4E200B775D3 /* TwitterSearchClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TwitterSearchClient.h; sourceTree = "<group>"; };
F87266BB145EF4E200B775D3 /* TwitterSearchClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TwitterSearchClient.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -422,6 +425,8 @@
09270763141E4EC900E778AE /* DataHelper.m */,
09E442CE141F97AE00AD2DAE /* ListViewController.h */,
09E442CF141F97AE00AD2DAE /* ListViewController.m */,
F87266BA145EF4E200B775D3 /* TwitterSearchClient.h */,
F87266BB145EF4E200B775D3 /* TwitterSearchClient.m */,
);
name = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -657,6 +662,7 @@
D8EA24C4145BA49100EB08B3 /* BrowserViewController.m in Sources */,
D8EA24C6145BA49100EB08B3 /* MyApplication.m in Sources */,
D8EA24D3145BA4BC00EB08B3 /* BrowserSampleViewController.m in Sources */,
F87266BC145EF4E200B775D3 /* TwitterSearchClient.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
14 changes: 4 additions & 10 deletions IOSBoilerplate/AsyncCellImagesExample.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@

#import "AsyncCellImagesExample.h"
#import "SVProgressHUD.h"
#import "JSONKit.h"
#import "AFJSONRequestOperation.h"
#import "DictionaryHelper.h"
#import "TwitterSearchClient.h"
#import "AsyncCell.h"

@implementation AsyncCellImagesExample
Expand Down Expand Up @@ -114,18 +112,14 @@ - (void)viewWillAppear:(BOOL)animated {

[SVProgressHUD showInView:self.view];

NSString *urlString = @"http://search.twitter.com/search.json?q=%23ios";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
[[TwitterSearchClient sharedClient] getPath:@"search" parameters:[NSDictionary dictionaryWithObject:@"iOS" forKey:@"q"] success:^(id object) {
[SVProgressHUD dismiss];

self.results = [JSON arrayForKey:@"results"];
self.results = [object valueForKey:@"results"];
[table reloadData];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
} failure:^(NSHTTPURLResponse *response, NSError *error) {
[SVProgressHUD dismissWithError:[error localizedDescription]];

}];
[operation start];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
Expand Down
14 changes: 14 additions & 0 deletions IOSBoilerplate/TwitterSearchClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// TwitterSearchClient.h
// IOSBoilerplate
//
// Created by Mattt Thompson on 11/10/31.
// Copyright (c) 2011年 Gowalla. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "AFHTTPClient.h"

@interface TwitterSearchClient : AFHTTPClient
+ (TwitterSearchClient *)sharedClient;
@end
47 changes: 47 additions & 0 deletions IOSBoilerplate/TwitterSearchClient.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// TwitterSearchClient.m
// IOSBoilerplate
//
// Created by Mattt Thompson on 11/10/31.
// Copyright (c) 2011年 Gowalla. All rights reserved.
//

#import "TwitterSearchClient.h"

#import "AFJSONRequestOperation.h"

NSString * const kTwitterBaseURLString = @"https://search.twitter.com/";


@implementation TwitterSearchClient

+ (TwitterSearchClient *)sharedClient {
static TwitterSearchClient *_sharedClient = nil;
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
_sharedClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:kTwitterBaseURLString]];
});

return _sharedClient;
}

- (id)initWithBaseURL:(NSURL *)url {
self = [super initWithBaseURL:url];
if (!self) {
return nil;
}

[self registerHTTPOperationClass:[AFJSONRequestOperation class]];

// Accept HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
[self setDefaultHeader:@"Accept" value:@"application/json"];

// X-UDID HTTP Header
[self setDefaultHeader:@"X-UDID" value:[[UIDevice currentDevice] uniqueIdentifier]];

return self;
}



@end
13 changes: 4 additions & 9 deletions IOSBoilerplate/VariableHeightExample.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@

#import "VariableHeightExample.h"
#import "SVProgressHUD.h"
#import "JSONKit.h"
#import "AFJSONRequestOperation.h"
#import "DictionaryHelper.h"
#import "TwitterSearchClient.h"
#import "VariableHeightCell.h"

@implementation VariableHeightExample
Expand Down Expand Up @@ -111,17 +109,14 @@ - (void)viewDidAppear:(BOOL)animated {

[SVProgressHUD showInView:self.view];

NSString *urlString = @"http://search.twitter.com/search.json?q=%23cats";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
[[TwitterSearchClient sharedClient] getPath:@"search" parameters:[NSDictionary dictionaryWithObject:@"cats" forKey:@"q"] success:^(id object) {
[SVProgressHUD dismiss];

self.results = [JSON arrayForKey:@"results"];
self.results = [object valueForKey:@"results"];
[table reloadData];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
} failure:^(NSHTTPURLResponse *response, NSError *error) {
[SVProgressHUD dismissWithError:[error localizedDescription]];
}];
[operation start];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
Expand Down

0 comments on commit 81e8eb2

Please sign in to comment.