Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created the SearchResultsModel protocol and made YahooSearchResultsMo…
…del and FlickrSearchResultsModel conform to this new protocol. I also fixed a bug in YahooXMLResponse's XPath queries.
- Loading branch information
Showing
14 changed files
with
122 additions
and
92 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,54 @@ | ||
/* | ||
* SearchResultsModel.h | ||
* | ||
* Created by Keith Lazuka on 7/25/09. | ||
* | ||
*/ | ||
|
||
#import "Three20/Three20.h" | ||
|
||
/* | ||
* NOTE: this is where you can switch the web service between Flickr and Yahoo | ||
* and between using the JSON and XML response processors. | ||
* All you need to do is set SearchServiceDefault and | ||
* SearchResponseFormatDefault to the appropriate value. | ||
* | ||
*/ | ||
typedef enum { | ||
SearchServiceYahoo, | ||
SearchServiceFlickr, | ||
SearchServiceDefault = SearchServiceYahoo | ||
} SearchService; | ||
extern SearchService CurrentSearchService; | ||
|
||
typedef enum { | ||
SearchResponseFormatJSON, | ||
SearchResponseFormatXML, | ||
SearchResponseFormatDefault = SearchResponseFormatXML | ||
} SearchResponseFormat; | ||
extern SearchResponseFormat CurrentSearchResponseFormat; | ||
|
||
#pragma mark - | ||
|
||
/* | ||
* SearchResultsModel | ||
* | ||
* This protocol is intended for TTModels that represent a remote search service. | ||
* | ||
*/ | ||
@protocol SearchResultsModel <TTModel> | ||
|
||
@property (nonatomic, readonly) NSArray *results; // A list of domain objects constructed by the model after parsing the web service's HTTP response. In this case, it is a list of SearchResult objects. | ||
@property (nonatomic, readonly) NSUInteger totalResultsAvailableOnServer; // The total number of results available on the server (but not necessarily downloaded) for the current model configuration's search query. | ||
@property (nonatomic, retain) NSString *searchTerms; // The keywords that will be submitted to the web service in order to do the actual image search (e.g. "green apple") | ||
|
||
- (id)initWithResponseFormat:(SearchResponseFormat)responseFormat; // The designated initializer | ||
|
||
@end | ||
|
||
#pragma mark - | ||
|
||
// Factory methods for instantiating a functioning SearchResultsModel. | ||
id<SearchResultsModel> CreateSearchModelWithCurrentSettings(void); | ||
id<SearchResultsModel> CreateSearchModel(SearchService service, SearchResponseFormat responseFormat); | ||
|
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,34 @@ | ||
// | ||
// SearchResultsModel.m | ||
// | ||
// Created by Keith Lazuka on 7/25/09. | ||
// | ||
|
||
#import "SearchResultsModel.h" | ||
#import "YahooSearchResultsModel.h" | ||
#import "FlickrSearchResultsModel.h" | ||
|
||
SearchService CurrentSearchService = SearchServiceDefault; | ||
SearchResponseFormat CurrentSearchResponseFormat = SearchResponseFormatDefault; | ||
|
||
id<SearchResultsModel> CreateSearchModel(SearchService service, SearchResponseFormat responseFormat) | ||
{ | ||
id<SearchResultsModel> model = nil; | ||
switch ( service ) { | ||
case SearchServiceYahoo: | ||
model = [[[YahooSearchResultsModel alloc] initWithResponseFormat:responseFormat] autorelease]; | ||
break; | ||
case SearchServiceFlickr: | ||
model = [[[FlickrSearchResultsModel alloc] initWithResponseFormat:responseFormat] autorelease]; | ||
break; | ||
default: | ||
[NSException raise:@"CurrentSearchService unknown" format:nil]; | ||
break; | ||
} | ||
return model; | ||
} | ||
|
||
id<SearchResultsModel> CreateSearchModelWithCurrentSettings(void) | ||
{ | ||
return CreateSearchModel(CurrentSearchService, CurrentSearchResponseFormat); | ||
} |
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
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