Skip to content

Instantly share code, notes, and snippets.

@alexfish
Created November 16, 2013 20:40
Show Gist options
  • Save alexfish/7505005 to your computer and use it in GitHub Desktop.
Save alexfish/7505005 to your computer and use it in GitHub Desktop.
Sample method to get the URL for the mock backend provided by sinatra and calasmash
+ (NSURL *)calabashAPIURL
{
NSString *apiURLString = nil;
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"server_config" ofType:@"plist"];
NSDictionary *serverConfig = [NSDictionary dictionaryWithContentsOfFile:plistPath];
NSString *urlString = [serverConfig objectForKey:(NSString *)kURLPreference];
if(urlString.length > 0)
{
if(![urlString hasPrefix:@"http://"])
{
apiURLString = [NSString stringWithFormat:@"http://%@", urlString];
}
else
{
apiURLString = urlString;
}
NSString *portString = [serverConfig objectForKey:(NSString *)kPortPreference];
if(portString)
{
apiURLString = [apiURLString stringByAppendingString:[NSString stringWithFormat:@":%@",portString]];
}
}
return [NSURL URLWithString:apiURLString];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment