Skip to content

Commit

Permalink
metatdata endpoint all working (actually haven't tested the last chan…
Browse files Browse the repository at this point in the history
…ge due to hitting the rate limit for now)
  • Loading branch information
aufflick committed Mar 22, 2012
1 parent 21e1b1a commit 8e9683f
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 47 deletions.
34 changes: 14 additions & 20 deletions Sensis SAPI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,13 @@
644940B2151AFAB200A64AA6 /* AFURLConnectionOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 6449405F151AFAB200A64AA6 /* AFURLConnectionOperation.m */; };
644940B3151AFAB200A64AA6 /* AFXMLRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 64494061151AFAB200A64AA6 /* AFXMLRequestOperation.m */; };
644940B4151AFAB200A64AA6 /* UIImageView+AFNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = 64494063151AFAB200A64AA6 /* UIImageView+AFNetworking.m */; };
644940C6151AFAB200A64AA6 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 64494085151AFAB200A64AA6 /* LICENSE */; };
644940D3151AFAB200A64AA6 /* CHANGELOG.md in Resources */ = {isa = PBXBuildFile; fileRef = 644940A7151AFAB200A64AA6 /* CHANGELOG.md */; };
644940D4151AFAB200A64AA6 /* JSONKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 644940A9151AFAB200A64AA6 /* JSONKit.m */; };
644940D5151AFAB200A64AA6 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 644940AA151AFAB200A64AA6 /* README.md */; };
645EFD3A151B1F4900D50EDE /* Sensis_SAPI_GetByListingIdTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 645EFD38151B1F2F00D50EDE /* Sensis_SAPI_GetByListingIdTests.m */; };
645EFD3D151B20E800D50EDE /* SAPIGetByListingId.m in Sources */ = {isa = PBXBuildFile; fileRef = 645EFD3C151B20E800D50EDE /* SAPIGetByListingId.m */; };
645EFD45151B271800D50EDE /* SAPIListingResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 645EFD44151B271800D50EDE /* SAPIListingResult.m */; };
645EFD4B151B28D800D50EDE /* SAPISearchResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 645EFD4A151B28D800D50EDE /* SAPISearchResult.m */; };
645EFD4E151B2DBB00D50EDE /* SAPIMetadata.m in Sources */ = {isa = PBXBuildFile; fileRef = 645EFD4D151B2DBB00D50EDE /* SAPIMetadata.m */; };
645EFD52151B2E0500D50EDE /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 645EFD51151B2E0500D50EDE /* README.md */; };
64A70DB0151ADF34005859E4 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 64A70DAF151ADF34005859E4 /* LICENSE */; };
64A70DB3151AE042005859E4 /* LICENSE_ISO8601DateFormatter in Resources */ = {isa = PBXBuildFile; fileRef = 64A70DB2151AE042005859E4 /* LICENSE_ISO8601DateFormatter */; };
645EFD55151B2F4000D50EDE /* SAPIMetadataResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 645EFD54151B2F4000D50EDE /* SAPIMetadataResult.m */; };
645EFD59151B32CA00D50EDE /* Sensis_SAPI_MetadataTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 645EFD57151B318A00D50EDE /* Sensis_SAPI_MetadataTests.m */; };
64A70DB6151AE076005859E4 /* SAPIISO8601DateFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 64A70DB5151AE076005859E4 /* SAPIISO8601DateFormatter.m */; };
64A70DB7151AE076005859E4 /* SAPIISO8601DateFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 64A70DB5151AE076005859E4 /* SAPIISO8601DateFormatter.m */; };
64AB066B151977F0009C66A8 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 64AB066A151977F0009C66A8 /* UIKit.framework */; };
Expand Down Expand Up @@ -106,13 +101,15 @@
645EFD38151B1F2F00D50EDE /* Sensis_SAPI_GetByListingIdTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Sensis_SAPI_GetByListingIdTests.m; sourceTree = "<group>"; };
645EFD3B151B20E800D50EDE /* SAPIGetByListingId.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SAPIGetByListingId.h; sourceTree = "<group>"; };
645EFD3C151B20E800D50EDE /* SAPIGetByListingId.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SAPIGetByListingId.m; sourceTree = "<group>"; };
645EFD43151B271800D50EDE /* SAPIListingResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SAPIListingResult.h; sourceTree = "<group>"; };
645EFD44151B271800D50EDE /* SAPIListingResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SAPIListingResult.m; sourceTree = "<group>"; };
645EFD49151B28D800D50EDE /* SAPISearchResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SAPISearchResult.h; sourceTree = "<group>"; };
645EFD4A151B28D800D50EDE /* SAPISearchResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SAPISearchResult.m; sourceTree = "<group>"; };
645EFD4C151B2DBB00D50EDE /* SAPIMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SAPIMetadata.h; sourceTree = "<group>"; };
645EFD4D151B2DBB00D50EDE /* SAPIMetadata.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SAPIMetadata.m; sourceTree = "<group>"; };
645EFD51151B2E0500D50EDE /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.md; sourceTree = SOURCE_ROOT; };
645EFD53151B2F4000D50EDE /* SAPIMetadataResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SAPIMetadataResult.h; sourceTree = "<group>"; };
645EFD54151B2F4000D50EDE /* SAPIMetadataResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SAPIMetadataResult.m; sourceTree = "<group>"; };
645EFD56151B318A00D50EDE /* Sensis_SAPI_MetadataTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Sensis_SAPI_MetadataTests.h; sourceTree = "<group>"; };
645EFD57151B318A00D50EDE /* Sensis_SAPI_MetadataTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Sensis_SAPI_MetadataTests.m; sourceTree = "<group>"; };
64A70DAF151ADF34005859E4 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
64A70DB2151AE042005859E4 /* LICENSE_ISO8601DateFormatter */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE_ISO8601DateFormatter; sourceTree = "<group>"; };
64A70DB4151AE076005859E4 /* SAPIISO8601DateFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SAPIISO8601DateFormatter.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -225,12 +222,12 @@
645EFD4F151B2DC100D50EDE /* Endoints */ = {
isa = PBXGroup;
children = (
645EFD4C151B2DBB00D50EDE /* SAPIMetadata.h */,
645EFD4D151B2DBB00D50EDE /* SAPIMetadata.m */,
64493DE7151985F900A64AA6 /* SAPISearch.h */,
64493DE8151985F900A64AA6 /* SAPISearch.m */,
645EFD3B151B20E800D50EDE /* SAPIGetByListingId.h */,
645EFD3C151B20E800D50EDE /* SAPIGetByListingId.m */,
645EFD4C151B2DBB00D50EDE /* SAPIMetadata.h */,
645EFD4D151B2DBB00D50EDE /* SAPIMetadata.m */,
);
name = Endoints;
sourceTree = "<group>";
Expand All @@ -248,8 +245,8 @@
64493DEB1519871400A64AA6 /* SAPIResult.m */,
645EFD49151B28D800D50EDE /* SAPISearchResult.h */,
645EFD4A151B28D800D50EDE /* SAPISearchResult.m */,
645EFD43151B271800D50EDE /* SAPIListingResult.h */,
645EFD44151B271800D50EDE /* SAPIListingResult.m */,
645EFD53151B2F4000D50EDE /* SAPIMetadataResult.h */,
645EFD54151B2F4000D50EDE /* SAPIMetadataResult.m */,
64494041151AAEDD00A64AA6 /* SAPIPrivate.h */,
64A70DB2151AE042005859E4 /* LICENSE_ISO8601DateFormatter */,
64A70DB4151AE076005859E4 /* SAPIISO8601DateFormatter.h */,
Expand Down Expand Up @@ -327,6 +324,8 @@
64AB069B151977F0009C66A8 /* Sensis_SAPI_SearchTests.m */,
645EFD37151B1F2F00D50EDE /* Sensis_SAPI_GetByListingIdTests.h */,
645EFD38151B1F2F00D50EDE /* Sensis_SAPI_GetByListingIdTests.m */,
645EFD56151B318A00D50EDE /* Sensis_SAPI_MetadataTests.h */,
645EFD57151B318A00D50EDE /* Sensis_SAPI_MetadataTests.m */,
64AB0695151977F0009C66A8 /* Supporting Files */,
);
path = "Sensis SAPITests";
Expand Down Expand Up @@ -424,12 +423,6 @@
64AB0675151977F0009C66A8 /* InfoPlist.strings in Resources */,
64AB0684151977F0009C66A8 /* SAPIMasterViewController.xib in Resources */,
64AB06AF15197B33009C66A8 /* SAPISearchViewController.xib in Resources */,
64A70DB0151ADF34005859E4 /* LICENSE in Resources */,
64A70DB3151AE042005859E4 /* LICENSE_ISO8601DateFormatter in Resources */,
644940C6151AFAB200A64AA6 /* LICENSE in Resources */,
644940D3151AFAB200A64AA6 /* CHANGELOG.md in Resources */,
644940D5151AFAB200A64AA6 /* README.md in Resources */,
645EFD52151B2E0500D50EDE /* README.md in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -486,9 +479,9 @@
644940B4151AFAB200A64AA6 /* UIImageView+AFNetworking.m in Sources */,
644940D4151AFAB200A64AA6 /* JSONKit.m in Sources */,
645EFD3D151B20E800D50EDE /* SAPIGetByListingId.m in Sources */,
645EFD45151B271800D50EDE /* SAPIListingResult.m in Sources */,
645EFD4B151B28D800D50EDE /* SAPISearchResult.m in Sources */,
645EFD4E151B2DBB00D50EDE /* SAPIMetadata.m in Sources */,
645EFD55151B2F4000D50EDE /* SAPIMetadataResult.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -499,6 +492,7 @@
64AB069C151977F0009C66A8 /* Sensis_SAPI_SearchTests.m in Sources */,
64A70DB7151AE076005859E4 /* SAPIISO8601DateFormatter.m in Sources */,
645EFD3A151B1F4900D50EDE /* Sensis_SAPI_GetByListingIdTests.m in Sources */,
645EFD59151B32CA00D50EDE /* Sensis_SAPI_MetadataTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
13 changes: 0 additions & 13 deletions Sensis SAPI/SAPIListingResult.h

This file was deleted.

13 changes: 0 additions & 13 deletions Sensis SAPI/SAPIListingResult.m

This file was deleted.

15 changes: 15 additions & 0 deletions Sensis SAPI/SAPIMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@

#import "SAPIEndpoint.h"

#import "SAPIMetadataResult.h"

#define SAPIMetadataCategoriesKey @"categories"
#define SAPIMetadataCategoryGroupsKey @"categoryGroups"

@interface SAPIMetadata : SAPIEndpoint

// See also the endpoint reference for more detail: http://developers.sensis.com.au/docs/endpoint_reference/Metadata

@property (copy) NSString * dataType; // the type of metadata required
// currently this can be either "categories" or "categoryGroups" - use the above #defines

- (SAPIMetadataResult *)performQueryWithError:(SAPIError **)error;

- (void)performQueryAsyncSuccess:(void (^)(SAPIMetadataResult * result))successBlock
failure:(void (^)(SAPIError * error))failureBlock;

@end
41 changes: 41 additions & 0 deletions Sensis SAPI/SAPIMetadata.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,48 @@
//

#import "SAPIMetadata.h"
#import "SAPIPrivate.h"

@implementation SAPIMetadata

@synthesize dataType;

- (void)dealloc
{
[dataType release];

[super dealloc];
}

- (NSString *)endpoint
{
// perhaps this should be modelled as two seperate endpoints - that's really what it is.
// sticking with one for now to match SAPI docs
return [NSString stringWithFormat:@"metadata/%@", self.dataType];
}

- (Class)resultClass
{
return [SAPIMetadataResult class];
}

- (NSDictionary *)queryKeys
{
// there are actually no queryKeys since the dataType is baked into the endpoint
return [NSDictionary dictionaryWithObjectsAndKeys:
nil];
}

- (SAPIMetadataResult *)performQueryWithError:(SAPIError **)error
{
return (SAPIMetadataResult *)[self _performQueryWithError:error];
}

- (void)performQueryAsyncSuccess:(void (^)(SAPIMetadataResult * result))successBlock
failure:(void (^)(SAPIError * error))failureBlock
{
return [self _performQueryAsyncSuccess:(void (^)(SAPIResult * result))successBlock failure:failureBlock];
}


@end
20 changes: 20 additions & 0 deletions Sensis SAPI/SAPIMetadataResult.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// SAPIMetadataResult.h
// Sensis SAPI
//
// Created by Mark Aufflick on 22/03/12.
// Copyright (c) 2012 Pumptheory Pty Ltd. All rights reserved.
//

#import "SAPIResult.h"

@interface SAPIMetadataResult : SAPIResult

@property (retain) NSArray * categories; // populated if you requested category metadata
@property (retain) NSArray * categoryGroups; // populated if you requested categoryGroup metadata
@property (retain) NSArray * groups; // an alias for categoryGroups (the SAPI docs are ambiguous, so we support both keys)
// NB: this alias is not KVO compliant

// also time, code and possibly details -- defined in the baseclass SAPIResult

@end
34 changes: 34 additions & 0 deletions Sensis SAPI/SAPIMetadataResult.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// SAPIMetadataResult.m
// Sensis SAPI
//
// Created by Mark Aufflick on 22/03/12.
// Copyright (c) 2012 Pumptheory Pty Ltd. All rights reserved.
//

#import "SAPIMetadataResult.h"

@implementation SAPIMetadataResult

@synthesize categories;
@synthesize categoryGroups;

- (void)dealloc
{
[categoryGroups release];
[categories release];

[super dealloc];
}

- (NSArray *)groups
{
return self.categoryGroups;
}

- (void)setGroups:(NSArray *)groups
{
self.categoryGroups = groups;
}

@end
8 changes: 7 additions & 1 deletion Sensis SAPI/SAPIResult.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ - (id)initWithJSONDictionary:(NSDictionary *)jsonDictionary
{
if ([self respondsToSelector:NSSelectorFromString(key)])
{
NSLog(@"key: %@", key);
[self setValue:obj forKey:key];
}
}];
Expand All @@ -41,6 +40,13 @@ - (id)initWithJSONDictionary:(NSDictionary *)jsonDictionary
return self;
}

- (void)dealloc
{
[details release];

[super dealloc];
}

- (void)setNilValueForKey:(NSString *)theKey
{
// Zero is probably a reasonable default for scalar values
Expand Down
2 changes: 2 additions & 0 deletions Sensis SAPI/SAPISearchResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@
@property (retain) NSString * originalQuery;
@property (retain) NSDate * date;

// also time, code and possibly details -- defined in the baseclass SAPIResult

@end
9 changes: 9 additions & 0 deletions Sensis SAPI/SAPISearchResult.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ @implementation SAPISearchResult
@synthesize originalQuery;
@synthesize date;

- (void)dealloc
{
[executedQuery release];
[originalQuery release];
[date release];

[super dealloc];
}

- (void)setValue:(id)value forKey:(NSString *)key
{
if ([key isEqualToString:@"date"] && [value isKindOfClass:[NSString class]])
Expand Down
16 changes: 16 additions & 0 deletions Sensis SAPITests/Sensis_SAPI_MetadataTests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Sensis_SAPI_MetadataTests.h
// Sensis SAPI
//
// Created by Mark Aufflick on 22/03/12.
// Copyright (c) 2012 Pumptheory Pty Ltd. All rights reserved.
//

// Application unit tests contain unit test code that must be injected into an application to run correctly.
// See Also: http://developer.apple.com/iphone/library/documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html

#import <SenTestingKit/SenTestingKit.h>

@interface Sensis_SAPI_MetadataTests : SenTestCase

@end
69 changes: 69 additions & 0 deletions Sensis SAPITests/Sensis_SAPI_MetadataTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// Sensis_SAPI_MetadataTests.m
// Sensis SAPI
//
// Created by Mark Aufflick on 22/03/12.
// Copyright (c) 2012 Pumptheory Pty Ltd. All rights reserved.
//

#import "Sensis_SAPI_MetadataTests.h"

#import "SAPI.h"
#import "SAPIAccountKey.h"
#import "SAPIMetadata.h"

@implementation Sensis_SAPI_MetadataTests

- (void)setUp
{
[super setUp];

[SAPI setKey:SAPI_KEY];
[SAPI setEnvironment:SAPI_ENVIRONMENT];

// we need to stay slow so the tests can succeed in SAPI test environment due to rate limit
sleep(1);
}

- (void)tearDown
{
// Tear-down code here.

[super tearDown];
}

- (void)testCategories
{
SAPIMetadata * metadataQuery = [[SAPIMetadata alloc] init];
metadataQuery.dataType = SAPIMetadataCategoriesKey;
SAPIError * error = nil;
SAPIMetadataResult * res = [metadataQuery performQueryWithError:&error];

STAssertNotNil(res, [NSString stringWithFormat:@"Categories query returned no results (%@)", error]);
STAssertTrue([res.categories isKindOfClass:[NSArray class]], @"Returned results are not NSArray");
STAssertFalse([res.categories count] == 0, @"We expect a categories query to have > 0 results");

NSDictionary * firstResult = [res.categories objectAtIndex:0];
STAssertTrue([firstResult isKindOfClass:[NSDictionary class]], @"first result entry is not a dictionary");
STAssertTrue([[firstResult objectForKey:@"id"] isKindOfClass:[NSNumber class]], @"id key is not a number");
STAssertTrue([[firstResult objectForKey:@"name"] isKindOfClass:[NSString class]], @"id key is not a string");

[metadataQuery release];
}

- (void)testCategoryGroups
{
SAPIMetadata * metadataQuery = [[SAPIMetadata alloc] init];
metadataQuery.dataType = SAPIMetadataCategoryGroupsKey;
SAPIError * error = nil;
SAPIMetadataResult * res = [metadataQuery performQueryWithError:&error];

STAssertNotNil(res, [NSString stringWithFormat:@"CategoryGroups query returned no results (%@)", error]);
STAssertTrue([res.categoryGroups isKindOfClass:[NSArray class]], @"Returned results are not NSArray");
STAssertFalse([res.categoryGroups count] == 0, @"We expect a categoryGroups query to have > 0 results");

[metadataQuery release];
}


@end

0 comments on commit 8e9683f

Please sign in to comment.