Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>FB5E9F3C-8700-4AC7-B417-28D7F33CDB9B</string>
<key>IDESourceControlProjectName</key>
<string>ENAPILibrary</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>C00DEDE6-CD91-4851-B65D-250053E807CA</key>
<string>https://github.com/myellen/enios.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>ENAPILibrary/ENAPILibrary.xcodeproj/project.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>C00DEDE6-CD91-4851-B65D-250053E807CA</key>
<string>../../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>https://github.com/myellen/enios.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>110</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>C00DEDE6-CD91-4851-B65D-250053E807CA</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>C00DEDE6-CD91-4851-B65D-250053E807CA</string>
<key>IDESourceControlWCCName</key>
<string>my_enios_fork</string>
</dict>
</array>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7EE1165316A3212F00A62D4D"
BuildableName = "libENAPILibrary.a"
BlueprintName = "ENAPILibrary"
ReferencedContainer = "container:ENAPILibrary.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7EE1166416A3213000A62D4D"
BuildableName = "ENAPILibraryTests.octest"
BlueprintName = "ENAPILibraryTests"
ReferencedContainer = "container:ENAPILibrary.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>ENAPILibrary.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>7EE1165316A3212F00A62D4D</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>7EE1166416A3213000A62D4D</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
32 changes: 31 additions & 1 deletion ENAPILibrary/ENAPILibrary/ENAPIRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ static NSString __attribute__((unused)) * const ECHONEST_API_URL = @"http://deve
+ (NSArray *)securedEndpoints;
+ (BOOL)isSecuredEndpoint:(NSString *)endpoint;


/**
* Execute a Echo Nest Web Service GET request and represent the JSON response as a dictionary object.
@param endpoint The Echo Nest webservice endpoint.
Expand All @@ -100,6 +99,19 @@ static NSString __attribute__((unused)) * const ECHONEST_API_URL = @"http://deve
andParameters:(NSDictionary *)parameters
andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock;

/**
* Execute a Echo Nest Web Service GET request and represent the JSON response as a dictionary object.
@param endpoint The Echo Nest webservice endpoint.
@param parameters The parameters for this endpoint as key/value pairs.
@param completionBlock The block of code to be executed on completion of the request, the request instance is returned as a parameter to allow access to the response and/or error information.
@param allowCachedData Whether or not a cached response is allowed. The default value is YES.
@return Returns the request instance, intended to be used for debugging or canceling an individual request.
*/
+ (ENAPIRequest *)GETWithEndpoint:(NSString *)endpoint
andParameters:(NSDictionary *)parameters
andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock
allowCachedData:(BOOL)allowCachedData;

/**
* Execute a Echo Nest Web Service POST request and represent the JSON response as a dictionary object.
@param endpoint The Echo Nest webservice endpoint.
Expand All @@ -111,6 +123,19 @@ static NSString __attribute__((unused)) * const ECHONEST_API_URL = @"http://deve
andParameters:(NSDictionary *)parameters
andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock;

/**
* Execute a Echo Nest Web Service POST request and represent the JSON response as a dictionary object.
@param endpoint The Echo Nest webservice endpoint.
@param parameters The parameters for this endpoint as key/value pairs.
@param completionBlock The block of code to be executed on completion of the request, the request instance is returned as a parameter to allow access to the response data and/or error information.
@param allowCachedData Whether or not a cached response is allowed. The default value is YES.
@return returns The request instance, intended to be used for debugging or canceling an individual request.
*/
+ (ENAPIRequest *)POSTWithEndpoint:(NSString *)endpoint
andParameters:(NSDictionary *)parameters
andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock
allowCachedData:(BOOL)allowCachedData;

/**
* Cancels all active requests.
*/
Expand Down Expand Up @@ -176,5 +201,10 @@ static NSString __attribute__((unused)) * const ECHONEST_API_URL = @"http://deve
*/
@property (nonatomic, strong, readonly) NSData *data;

/**
* Whether or not cached data is allowed for the response.
*/
@property (readonly) BOOL cachedDataAllowed;


@end
42 changes: 40 additions & 2 deletions ENAPILibrary/ENAPILibrary/ENAPIRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ @implementation ENAPIRequest
@synthesize urlResponse = _urlResponse;
@synthesize connection = _connection;

@synthesize cachedDataAllowed = _cachedDataAllowed;

static NSString *EN_API_KEY = nil;
static NSString *EN_CONSUMER_KEY = nil;
static NSString *EN_SHARED_SECRET = nil;
Expand All @@ -80,13 +82,21 @@ @implementation ENAPIRequest
- (ENAPIRequest *)initWithEndpoint:(NSString *)endpoint
andParameters:(NSDictionary *)parameters
andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock {
return [self initWithEndpoint:endpoint andParameters:parameters andCompletionBlock:completionBlock allowCachedData:YES];
}

- (ENAPIRequest *)initWithEndpoint:(NSString *)endpoint
andParameters:(NSDictionary *)parameters
andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock
allowCachedData:(BOOL)allowCachedData {

self = [super init];
if (self) {

//CHECK_API_KEY
self.completionBlock = completionBlock;
_endpoint = endpoint;
_cachedDataAllowed = allowCachedData;
[self.parameters addEntriesFromDictionary:parameters];
[self.parameters setValue:[ENAPIRequest apiKey] forKey:@"api_key"];
[self.parameters setValue:@"json" forKey:@"format"];
Expand Down Expand Up @@ -174,6 +184,8 @@ - (void)initiateGetRequest {

[request setTimeoutInterval:requestTimeoutInterval];

if (!self.cachedDataAllowed) [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];

self.connection =[[NSURLConnection alloc] initWithRequest:request delegate:self];

if (self.connection == nil) {
Expand All @@ -194,6 +206,8 @@ - (void)initiatePostRequest {

[request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary] forHTTPHeaderField:@"Content-Type"];

if (!self.cachedDataAllowed) [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];

NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"--%@", boundary] dataUsingEncoding:NSUTF8StringEncoding]];

Expand Down Expand Up @@ -244,9 +258,21 @@ + (ENAPIRequest *)GETWithEndpoint:(NSString *)endpoint
andParameters:(NSDictionary *)parameters
andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock {

return [[self class] GETWithEndpoint:endpoint
andParameters:parameters
andCompletionBlock:completionBlock
allowCachedData:YES];
}

+ (ENAPIRequest *)GETWithEndpoint:(NSString *)endpoint
andParameters:(NSDictionary *)parameters
andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock
allowCachedData:(BOOL)allowCachedData {

ENAPIRequest *request = [[ENAPIRequest alloc] initWithEndpoint:endpoint
andParameters:parameters
andCompletionBlock:completionBlock];
andCompletionBlock:completionBlock
allowCachedData:allowCachedData];

[request initiateGetRequest];
return request;
Expand All @@ -256,9 +282,21 @@ + (ENAPIRequest *)POSTWithEndpoint:(NSString *)endpoint
andParameters:(NSDictionary *)parameters
andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock {

return [[self class] POSTWithEndpoint:endpoint
andParameters:parameters
andCompletionBlock:completionBlock
allowCachedData:YES];
}

+ (ENAPIRequest *)POSTWithEndpoint:(NSString *)endpoint
andParameters:(NSDictionary *)parameters
andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock
allowCachedData:(BOOL)allowCachedData {

ENAPIRequest *request = [[ENAPIRequest alloc] initWithEndpoint:endpoint
andParameters:parameters
andCompletionBlock:completionBlock];
andCompletionBlock:completionBlock
allowCachedData:allowCachedData];
[request initiatePostRequest];
return request;
}
Expand Down