mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-28 19:50:49 +00:00
fixes #2214
This commit is contained in:
parent
9ad139c554
commit
d99de3199c
@ -1,4 +0,0 @@
|
||||
platform :ios, '6.0'
|
||||
xcodeproj 'WordnikApiClient/WordnikApiClient.xcodeproj'
|
||||
pod 'AFNetworking', '~> 1.0'
|
||||
|
@ -1,69 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGUser.h"
|
||||
#import "SWGWordList.h"
|
||||
#import "SWGApiTokenStatus.h"
|
||||
#import "SWGAuthenticationToken.h"
|
||||
|
||||
|
||||
|
||||
@interface SWGAccountApi: NSObject
|
||||
|
||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
|
||||
-(unsigned long) requestQueueSize;
|
||||
+(SWGAccountApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
||||
+(void) setBasePath:(NSString*)basePath;
|
||||
+(NSString*) getBasePath;
|
||||
/**
|
||||
|
||||
Authenticates a User
|
||||
|
||||
@param username A confirmed Wordnik username
|
||||
@param password The user's password
|
||||
*/
|
||||
-(NSNumber*) authenticateWithCompletionBlock :(NSString*) username
|
||||
password:(NSString*) password
|
||||
completionHandler: (void (^)(SWGAuthenticationToken* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Authenticates a user
|
||||
|
||||
@param username A confirmed Wordnik username
|
||||
@param body The user's password
|
||||
*/
|
||||
-(NSNumber*) authenticatePostWithCompletionBlock :(NSString*) username
|
||||
body:(NSString*) body
|
||||
completionHandler: (void (^)(SWGAuthenticationToken* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Fetches WordList objects for the logged-in user.
|
||||
|
||||
@param auth_token auth_token of logged-in user
|
||||
@param skip Results to skip
|
||||
@param limit Maximum number of results to return
|
||||
*/
|
||||
-(NSNumber*) getWordListsForLoggedInUserWithCompletionBlock :(NSString*) auth_token
|
||||
skip:(NSNumber*) skip
|
||||
limit:(NSNumber*) limit
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Returns usage statistics for the API account.
|
||||
|
||||
@param api_key Wordnik authentication token
|
||||
*/
|
||||
-(NSNumber*) getApiTokenStatusWithCompletionBlock :(NSString*) api_key
|
||||
completionHandler: (void (^)(SWGApiTokenStatus* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Returns the logged-in User
|
||||
Requires a valid auth_token to be set.
|
||||
@param auth_token The auth token of the logged-in user, obtained by calling /account.{format}/authenticate/{username} (described above)
|
||||
*/
|
||||
-(NSNumber*) getLoggedInUserWithCompletionBlock :(NSString*) auth_token
|
||||
completionHandler: (void (^)(SWGUser* output, NSError* error))completionBlock;
|
||||
|
||||
@end
|
@ -1,318 +0,0 @@
|
||||
#import "SWGAccountApi.h"
|
||||
#import "SWGFile.h"
|
||||
#import "SWGApiClient.h"
|
||||
#import "SWGUser.h"
|
||||
#import "SWGWordList.h"
|
||||
#import "SWGApiTokenStatus.h"
|
||||
#import "SWGAuthenticationToken.h"
|
||||
|
||||
|
||||
|
||||
|
||||
@implementation SWGAccountApi
|
||||
static NSString * basePath = @"http://api.wordnik.com/v4";
|
||||
|
||||
+(SWGAccountApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key {
|
||||
static SWGAccountApi* singletonAPI = nil;
|
||||
|
||||
if (singletonAPI == nil) {
|
||||
singletonAPI = [[SWGAccountApi alloc] init];
|
||||
[singletonAPI addHeader:headerValue forKey:key];
|
||||
}
|
||||
return singletonAPI;
|
||||
}
|
||||
|
||||
+(void) setBasePath:(NSString*)path {
|
||||
basePath = path;
|
||||
}
|
||||
|
||||
+(NSString*) getBasePath {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
-(SWGApiClient*) apiClient {
|
||||
return [SWGApiClient sharedClientFromPool:basePath];
|
||||
}
|
||||
|
||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
|
||||
[[self apiClient] setHeaderValue:value forKey:key];
|
||||
}
|
||||
|
||||
-(id) init {
|
||||
self = [super init];
|
||||
[self apiClient];
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void) setHeaderValue:(NSString*) value
|
||||
forKey:(NSString*)key {
|
||||
[[self apiClient] setHeaderValue:value forKey:key];
|
||||
}
|
||||
|
||||
-(unsigned long) requestQueueSize {
|
||||
return [SWGApiClient requestQueueSize];
|
||||
}
|
||||
|
||||
|
||||
-(NSNumber*) authenticateWithCompletionBlock:(NSString*) username
|
||||
password:(NSString*) password
|
||||
completionHandler: (void (^)(SWGAuthenticationToken* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/account.{format}/authenticate/{username}", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [SWGApiClient escape:username]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(password != nil)
|
||||
queryParams[@"password"] = password;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
if(username == nil) {
|
||||
// error
|
||||
}
|
||||
if(password == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary:requestUrl
|
||||
method:@"GET"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType:requestContentType
|
||||
responseContentType:responseContentType
|
||||
completionBlock:^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
SWGAuthenticationToken *result = nil;
|
||||
if (data) {
|
||||
result = [[SWGAuthenticationToken alloc]initWithValues: data];
|
||||
}
|
||||
completionBlock(result , nil);}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) authenticatePostWithCompletionBlock:(NSString*) username
|
||||
body:(NSString*) body
|
||||
completionHandler: (void (^)(SWGAuthenticationToken* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/account.{format}/authenticate/{username}", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [SWGApiClient escape:username]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
if(body != nil && [body isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] init];
|
||||
for (id dict in (NSArray*)body) {
|
||||
if([dict respondsToSelector:@selector(asDictionary)]) {
|
||||
[objs addObject:[(SWGObject*)dict asDictionary]];
|
||||
}
|
||||
else{
|
||||
[objs addObject:dict];
|
||||
}
|
||||
}
|
||||
bodyDictionary = objs;
|
||||
}
|
||||
else if([body respondsToSelector:@selector(asDictionary)]) {
|
||||
bodyDictionary = [(SWGObject*)body asDictionary];
|
||||
}
|
||||
else if([body isKindOfClass:[NSString class]]) {
|
||||
// convert it to a dictionary
|
||||
NSError * error;
|
||||
NSString * str = (NSString*)body;
|
||||
NSDictionary *JSON =
|
||||
[NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding]
|
||||
options:NSJSONReadingMutableContainers
|
||||
error:&error];
|
||||
bodyDictionary = JSON;
|
||||
}
|
||||
else if([body isKindOfClass: [SWGFile class]]) {
|
||||
requestContentType = @"form-data";
|
||||
bodyDictionary = body;
|
||||
}
|
||||
else{
|
||||
NSLog(@"don't know what to do with %@", body);
|
||||
}
|
||||
|
||||
if(username == nil) {
|
||||
// error
|
||||
}
|
||||
if(body == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary:requestUrl
|
||||
method:@"POST"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType:requestContentType
|
||||
responseContentType:responseContentType
|
||||
completionBlock:^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
SWGAuthenticationToken *result = nil;
|
||||
if (data) {
|
||||
result = [[SWGAuthenticationToken alloc]initWithValues: data];
|
||||
}
|
||||
completionBlock(result , nil);}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getWordListsForLoggedInUserWithCompletionBlock:(NSString*) auth_token
|
||||
skip:(NSNumber*) skip
|
||||
limit:(NSNumber*) limit
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/account.{format}/wordLists", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(skip != nil)
|
||||
queryParams[@"skip"] = skip;
|
||||
if(limit != nil)
|
||||
queryParams[@"limit"] = limit;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
if(auth_token != nil)
|
||||
headerParams[@"auth_token"] = auth_token;
|
||||
id bodyDictionary = nil;
|
||||
if(auth_token == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary: requestUrl
|
||||
method: @"GET"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
|
||||
if([data isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]];
|
||||
for (NSDictionary* dict in (NSArray*)data) {
|
||||
SWGWordList* d = [[SWGWordList alloc]initWithValues: dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
completionBlock(objs, nil);
|
||||
}
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getApiTokenStatusWithCompletionBlock:(NSString*) api_key
|
||||
completionHandler: (void (^)(SWGApiTokenStatus* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/account.{format}/apiTokenStatus", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
if(api_key != nil)
|
||||
headerParams[@"api_key"] = api_key;
|
||||
id bodyDictionary = nil;
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary:requestUrl
|
||||
method:@"GET"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType:requestContentType
|
||||
responseContentType:responseContentType
|
||||
completionBlock:^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
SWGApiTokenStatus *result = nil;
|
||||
if (data) {
|
||||
result = [[SWGApiTokenStatus alloc]initWithValues: data];
|
||||
}
|
||||
completionBlock(result , nil);}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getLoggedInUserWithCompletionBlock:(NSString*) auth_token
|
||||
completionHandler: (void (^)(SWGUser* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/account.{format}/user", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
if(auth_token != nil)
|
||||
headerParams[@"auth_token"] = auth_token;
|
||||
id bodyDictionary = nil;
|
||||
if(auth_token == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary:requestUrl
|
||||
method:@"GET"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType:requestContentType
|
||||
responseContentType:responseContentType
|
||||
completionBlock:^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
SWGUser *result = nil;
|
||||
if (data) {
|
||||
result = [[SWGUser alloc]initWithValues: data];
|
||||
}
|
||||
completionBlock(result , nil);}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
@ -1,64 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "AFHTTPClient.h"
|
||||
|
||||
@interface SWGApiClient : AFHTTPClient
|
||||
|
||||
@property(nonatomic, assign) NSURLRequestCachePolicy cachePolicy;
|
||||
@property(nonatomic, assign) NSTimeInterval timeoutInterval;
|
||||
@property(nonatomic, assign) BOOL logRequests;
|
||||
@property(nonatomic, assign) BOOL logCacheHits;
|
||||
@property(nonatomic, assign) BOOL logServerResponses;
|
||||
@property(nonatomic, assign) BOOL logJSON;
|
||||
@property(nonatomic, assign) BOOL logHTTP;
|
||||
@property(nonatomic, readonly) NSOperationQueue* queue;
|
||||
|
||||
+(SWGApiClient *)sharedClientFromPool:(NSString *)baseUrl;
|
||||
|
||||
+(NSOperationQueue*) sharedQueue;
|
||||
|
||||
+(void)setLoggingEnabled:(bool) state;
|
||||
|
||||
+(void)clearCache;
|
||||
|
||||
+(void)setCacheEnabled:(BOOL) enabled;
|
||||
|
||||
+(unsigned long)requestQueueSize;
|
||||
|
||||
+(void) setOfflineState:(BOOL) state;
|
||||
|
||||
+(AFNetworkReachabilityStatus) getReachabilityStatus;
|
||||
|
||||
+(NSNumber*) nextRequestId;
|
||||
|
||||
+(NSNumber*) queueRequest;
|
||||
|
||||
+(void) cancelRequest:(NSNumber*)requestId;
|
||||
|
||||
+(NSString*) escape:(id)unescaped;
|
||||
|
||||
+(void) setReachabilityChangeBlock:(void(^)(int))changeBlock;
|
||||
|
||||
+(void) configureCacheReachibilityForHost:(NSString*)host;
|
||||
|
||||
-(void)setHeaderValue:(NSString*) value
|
||||
forKey:(NSString*) forKey;
|
||||
|
||||
-(NSNumber*) dictionary:(NSString*) path
|
||||
method:(NSString*) method
|
||||
queryParams:(NSDictionary*) queryParams
|
||||
body:(id) body
|
||||
headerParams:(NSDictionary*) headerParams
|
||||
requestContentType:(NSString*) requestContentType
|
||||
responseContentType:(NSString*) responseContentType
|
||||
completionBlock:(void (^)(NSDictionary*, NSError *))completionBlock;
|
||||
|
||||
-(NSNumber*) stringWithCompletionBlock:(NSString*) path
|
||||
method:(NSString*) method
|
||||
queryParams:(NSDictionary*) queryParams
|
||||
body:(id) body
|
||||
headerParams:(NSDictionary*) headerParams
|
||||
requestContentType:(NSString*) requestContentType
|
||||
responseContentType:(NSString*) responseContentType
|
||||
completionBlock:(void (^)(NSString*, NSError *))completionBlock;
|
||||
@end
|
||||
|
@ -1,419 +0,0 @@
|
||||
#import "SWGApiClient.h"
|
||||
#import "SWGFile.h"
|
||||
|
||||
#import "AFJSONRequestOperation.h"
|
||||
|
||||
@implementation SWGApiClient
|
||||
|
||||
static long requestId = 0;
|
||||
static bool offlineState = true;
|
||||
static NSMutableSet * queuedRequests = nil;
|
||||
static bool cacheEnabled = false;
|
||||
static AFNetworkReachabilityStatus reachabilityStatus = AFNetworkReachabilityStatusNotReachable;
|
||||
static NSOperationQueue* sharedQueue;
|
||||
static void (^reachabilityChangeBlock)(int);
|
||||
static bool loggingEnabled = false;
|
||||
|
||||
+(void)setLoggingEnabled:(bool) state {
|
||||
loggingEnabled = state;
|
||||
}
|
||||
|
||||
+(void)clearCache {
|
||||
[[NSURLCache sharedURLCache] removeAllCachedResponses];
|
||||
}
|
||||
|
||||
+(void)setCacheEnabled:(BOOL)enabled {
|
||||
cacheEnabled = enabled;
|
||||
}
|
||||
|
||||
+(void)configureCacheWithMemoryAndDiskCapacity:(unsigned long) memorySize
|
||||
diskSize:(unsigned long) diskSize {
|
||||
NSAssert(memorySize > 0, @"invalid in-memory cache size");
|
||||
NSAssert(diskSize >= 0, @"invalid disk cache size");
|
||||
|
||||
NSURLCache *cache =
|
||||
[[NSURLCache alloc]
|
||||
initWithMemoryCapacity:memorySize
|
||||
diskCapacity:diskSize
|
||||
diskPath:@"swagger_url_cache"];
|
||||
|
||||
[NSURLCache setSharedURLCache:cache];
|
||||
}
|
||||
|
||||
+(NSOperationQueue*) sharedQueue {
|
||||
return sharedQueue;
|
||||
}
|
||||
|
||||
+(SWGApiClient *)sharedClientFromPool:(NSString *)baseUrl {
|
||||
static NSMutableDictionary *_pool = nil;
|
||||
if (queuedRequests == nil) {
|
||||
queuedRequests = [[NSMutableSet alloc]init];
|
||||
}
|
||||
if(_pool == nil) {
|
||||
// setup static vars
|
||||
// create queue
|
||||
sharedQueue = [[NSOperationQueue alloc] init];
|
||||
|
||||
// create pool
|
||||
_pool = [[NSMutableDictionary alloc] init];
|
||||
|
||||
// initialize URL cache
|
||||
[SWGApiClient configureCacheWithMemoryAndDiskCapacity:4*1024*1024 diskSize:32*1024*1024];
|
||||
|
||||
// configure reachability
|
||||
[SWGApiClient configureCacheReachibilityForHost:baseUrl];
|
||||
}
|
||||
|
||||
@synchronized(self) {
|
||||
SWGApiClient * client = [_pool objectForKey:baseUrl];
|
||||
if (client == nil) {
|
||||
client = [[SWGApiClient alloc] initWithBaseURL:[NSURL URLWithString:baseUrl]];
|
||||
[client registerHTTPOperationClass:[AFJSONRequestOperation class]];
|
||||
client.parameterEncoding = AFJSONParameterEncoding;
|
||||
[_pool setValue:client forKey:baseUrl ];
|
||||
if(loggingEnabled)
|
||||
NSLog(@"new client for path %@", baseUrl);
|
||||
}
|
||||
if(loggingEnabled)
|
||||
NSLog(@"returning client for path %@", baseUrl);
|
||||
return client;
|
||||
}
|
||||
}
|
||||
|
||||
-(void)setHeaderValue:(NSString*) value
|
||||
forKey:(NSString*) forKey {
|
||||
[self setDefaultHeader:forKey value:value];
|
||||
}
|
||||
|
||||
+(unsigned long)requestQueueSize {
|
||||
return [queuedRequests count];
|
||||
}
|
||||
|
||||
+(NSNumber*) nextRequestId {
|
||||
long nextId = ++requestId;
|
||||
if(loggingEnabled)
|
||||
NSLog(@"got id %ld", nextId);
|
||||
return [NSNumber numberWithLong:nextId];
|
||||
}
|
||||
|
||||
+(NSNumber*) queueRequest {
|
||||
NSNumber* requestId = [SWGApiClient nextRequestId];
|
||||
if(loggingEnabled)
|
||||
NSLog(@"added %@ to request queue", requestId);
|
||||
[queuedRequests addObject:requestId];
|
||||
return requestId;
|
||||
}
|
||||
|
||||
+(void) cancelRequest:(NSNumber*)requestId {
|
||||
[queuedRequests removeObject:requestId];
|
||||
}
|
||||
|
||||
+(NSString*) escape:(id)unescaped {
|
||||
if([unescaped isKindOfClass:[NSString class]]){
|
||||
return (NSString *)CFBridgingRelease
|
||||
(CFURLCreateStringByAddingPercentEscapes(
|
||||
NULL,
|
||||
(__bridge CFStringRef) unescaped,
|
||||
NULL,
|
||||
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
|
||||
kCFStringEncodingUTF8));
|
||||
}
|
||||
else {
|
||||
return [NSString stringWithFormat:@"%@", unescaped];
|
||||
}
|
||||
}
|
||||
|
||||
-(Boolean) executeRequestWithId:(NSNumber*) requestId {
|
||||
NSSet* matchingItems = [queuedRequests objectsPassingTest:^BOOL(id obj, BOOL *stop) {
|
||||
if([obj intValue] == [requestId intValue])
|
||||
return TRUE;
|
||||
else return FALSE;
|
||||
}];
|
||||
|
||||
if(matchingItems.count == 1) {
|
||||
if(loggingEnabled)
|
||||
NSLog(@"removing request id %@", requestId);
|
||||
[queuedRequests removeObject:requestId];
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
-(id)initWithBaseURL:(NSURL *)url {
|
||||
self = [super initWithBaseURL:url];
|
||||
if (!self)
|
||||
return nil;
|
||||
return self;
|
||||
}
|
||||
|
||||
+(AFNetworkReachabilityStatus) getReachabilityStatus {
|
||||
return reachabilityStatus;
|
||||
}
|
||||
|
||||
+(void) setReachabilityChangeBlock:(void(^)(int))changeBlock {
|
||||
reachabilityChangeBlock = changeBlock;
|
||||
}
|
||||
|
||||
+(void) setOfflineState:(BOOL) state {
|
||||
offlineState = state;
|
||||
}
|
||||
|
||||
+(void) configureCacheReachibilityForHost:(NSString*)host {
|
||||
[[SWGApiClient sharedClientFromPool:host ] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
|
||||
reachabilityStatus = status;
|
||||
switch (status) {
|
||||
case AFNetworkReachabilityStatusUnknown:
|
||||
if(loggingEnabled)
|
||||
NSLog(@"reachability changed to AFNetworkReachabilityStatusUnknown");
|
||||
[SWGApiClient setOfflineState:true];
|
||||
break;
|
||||
|
||||
case AFNetworkReachabilityStatusNotReachable:
|
||||
if(loggingEnabled)
|
||||
NSLog(@"reachability changed to AFNetworkReachabilityStatusNotReachable");
|
||||
[SWGApiClient setOfflineState:true];
|
||||
break;
|
||||
|
||||
case AFNetworkReachabilityStatusReachableViaWWAN:
|
||||
if(loggingEnabled)
|
||||
NSLog(@"reachability changed to AFNetworkReachabilityStatusReachableViaWWAN");
|
||||
[SWGApiClient setOfflineState:false];
|
||||
break;
|
||||
|
||||
case AFNetworkReachabilityStatusReachableViaWiFi:
|
||||
if(loggingEnabled)
|
||||
NSLog(@"reachability changed to AFNetworkReachabilityStatusReachableViaWiFi");
|
||||
[SWGApiClient setOfflineState:false];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// call the reachability block, if configured
|
||||
if(reachabilityChangeBlock != nil) {
|
||||
reachabilityChangeBlock(status);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
-(NSString*) pathWithQueryParamsToString:(NSString*) path
|
||||
queryParams:(NSDictionary*) queryParams {
|
||||
NSString * separator = nil;
|
||||
int counter = 0;
|
||||
|
||||
NSMutableString * requestUrl = [NSMutableString stringWithFormat:@"%@", path];
|
||||
if(queryParams != nil){
|
||||
for(NSString * key in [queryParams keyEnumerator]){
|
||||
if(counter == 0) separator = @"?";
|
||||
else separator = @"&";
|
||||
NSString * value;
|
||||
if([[queryParams valueForKey:key] isKindOfClass:[NSString class]]){
|
||||
value = [SWGApiClient escape:[queryParams valueForKey:key]];
|
||||
}
|
||||
else {
|
||||
value = [NSString stringWithFormat:@"%@", [queryParams valueForKey:key]];
|
||||
}
|
||||
[requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator,
|
||||
[SWGApiClient escape:key], value]];
|
||||
counter += 1;
|
||||
}
|
||||
}
|
||||
return requestUrl;
|
||||
}
|
||||
|
||||
- (NSString*)descriptionForRequest:(NSURLRequest*)request {
|
||||
return [[request URL] absoluteString];
|
||||
}
|
||||
|
||||
- (void)logRequest:(NSURLRequest*)request {
|
||||
NSLog(@"request: %@", [self descriptionForRequest:request]);
|
||||
}
|
||||
|
||||
- (void)logResponse:(id)data forRequest:(NSURLRequest*)request error:(NSError*)error {
|
||||
NSLog(@"request: %@ response: %@ ", [self descriptionForRequest:request], data );
|
||||
}
|
||||
|
||||
|
||||
-(NSNumber*) dictionary:(NSString*) path
|
||||
method:(NSString*) method
|
||||
queryParams:(NSDictionary*) queryParams
|
||||
body:(id) body
|
||||
headerParams:(NSDictionary*) headerParams
|
||||
requestContentType:(NSString*) requestContentType
|
||||
responseContentType:(NSString*) responseContentType
|
||||
completionBlock:(void (^)(NSDictionary*, NSError *))completionBlock {
|
||||
|
||||
NSMutableURLRequest * request = nil;
|
||||
|
||||
if ([body isKindOfClass:[SWGFile class]]){
|
||||
SWGFile * file = (SWGFile*) body;
|
||||
|
||||
request = [self multipartFormRequestWithMethod:@"POST"
|
||||
path:path
|
||||
parameters:nil
|
||||
constructingBodyWithBlock: ^(id <AFMultipartFormData> formData) {
|
||||
[formData appendPartWithFileData:[file data]
|
||||
name:@"image"
|
||||
fileName:[file name]
|
||||
mimeType:[file mimeType]];
|
||||
}];
|
||||
}
|
||||
else {
|
||||
request = [self requestWithMethod:method
|
||||
path:[self pathWithQueryParamsToString:path queryParams:queryParams]
|
||||
parameters:body];
|
||||
}
|
||||
BOOL hasHeaderParams = false;
|
||||
if(headerParams != nil && [headerParams count] > 0)
|
||||
hasHeaderParams = true;
|
||||
if(offlineState) {
|
||||
NSLog(@"%@ cache forced", path);
|
||||
[request setCachePolicy:NSURLRequestReturnCacheDataDontLoad];
|
||||
}
|
||||
else if(!hasHeaderParams && [method isEqualToString:@"GET"] && cacheEnabled) {
|
||||
NSLog(@"%@ cache enabled", path);
|
||||
[request setCachePolicy:NSURLRequestUseProtocolCachePolicy];
|
||||
}
|
||||
else {
|
||||
NSLog(@"%@ cache disabled", path);
|
||||
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
|
||||
}
|
||||
|
||||
if(body != nil) {
|
||||
if([body isKindOfClass:[NSDictionary class]] || [body isKindOfClass:[NSArray class]]){
|
||||
[request setValue:requestContentType forHTTPHeaderField:@"Content-Type"];
|
||||
}
|
||||
else if ([body isKindOfClass:[SWGFile class]]) {}
|
||||
else {
|
||||
NSAssert(false, @"unsupported post type!");
|
||||
}
|
||||
}
|
||||
if(headerParams != nil){
|
||||
for(NSString * key in [headerParams keyEnumerator]){
|
||||
[request setValue:[headerParams valueForKey:key] forHTTPHeaderField:key];
|
||||
}
|
||||
}
|
||||
[request setValue:[headerParams valueForKey:responseContentType] forHTTPHeaderField:@"Accept"];
|
||||
|
||||
// Always disable cookies!
|
||||
[request setHTTPShouldHandleCookies:NO];
|
||||
|
||||
|
||||
if (self.logRequests) {
|
||||
[self logRequest:request];
|
||||
}
|
||||
|
||||
NSNumber* requestId = [SWGApiClient queueRequest];
|
||||
AFJSONRequestOperation *op =
|
||||
[AFJSONRequestOperation
|
||||
JSONRequestOperationWithRequest:request
|
||||
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
|
||||
if([self executeRequestWithId:requestId]) {
|
||||
if(self.logServerResponses)
|
||||
[self logResponse:JSON forRequest:request error:nil];
|
||||
completionBlock(JSON, nil);
|
||||
}
|
||||
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id data) {
|
||||
if([self executeRequestWithId:requestId]) {
|
||||
if(self.logServerResponses)
|
||||
[self logResponse:nil forRequest:request error:error];
|
||||
completionBlock(nil, error);
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
[self enqueueHTTPRequestOperation:op];
|
||||
return requestId;
|
||||
}
|
||||
|
||||
-(NSNumber*) stringWithCompletionBlock:(NSString*) path
|
||||
method:(NSString*) method
|
||||
queryParams:(NSDictionary*) queryParams
|
||||
body:(id) body
|
||||
headerParams:(NSDictionary*) headerParams
|
||||
requestContentType:(NSString*) requestContentType
|
||||
responseContentType:(NSString*) responseContentType
|
||||
completionBlock:(void (^)(NSString*, NSError *))completionBlock {
|
||||
AFHTTPClient *client = self;
|
||||
client.parameterEncoding = AFJSONParameterEncoding;
|
||||
|
||||
NSMutableURLRequest * request = nil;
|
||||
|
||||
if ([body isKindOfClass:[SWGFile class]]){
|
||||
SWGFile * file = (SWGFile*) body;
|
||||
|
||||
request = [self multipartFormRequestWithMethod:@"POST"
|
||||
path:path
|
||||
parameters:nil
|
||||
constructingBodyWithBlock: ^(id <AFMultipartFormData> formData) {
|
||||
[formData appendPartWithFileData:[file data]
|
||||
name:@"image"
|
||||
fileName:[file name]
|
||||
mimeType:[file mimeType]];
|
||||
}];
|
||||
}
|
||||
else {
|
||||
request = [self requestWithMethod:method
|
||||
path:[self pathWithQueryParamsToString:path queryParams:queryParams]
|
||||
parameters:body];
|
||||
}
|
||||
|
||||
BOOL hasHeaderParams = false;
|
||||
if(headerParams != nil && [headerParams count] > 0)
|
||||
hasHeaderParams = true;
|
||||
if(offlineState) {
|
||||
NSLog(@"%@ cache forced", path);
|
||||
[request setCachePolicy:NSURLRequestReturnCacheDataDontLoad];
|
||||
}
|
||||
else if(!hasHeaderParams && [method isEqualToString:@"GET"] && cacheEnabled) {
|
||||
NSLog(@"%@ cache enabled", path);
|
||||
[request setCachePolicy:NSURLRequestUseProtocolCachePolicy];
|
||||
}
|
||||
else {
|
||||
NSLog(@"%@ cache disabled", path);
|
||||
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
|
||||
}
|
||||
|
||||
if(body != nil) {
|
||||
if([body isKindOfClass:[NSDictionary class]]){
|
||||
[request setValue:requestContentType forHTTPHeaderField:@"Content-Type"];
|
||||
}
|
||||
else if ([body isKindOfClass:[SWGFile class]]){}
|
||||
else {
|
||||
NSAssert(false, @"unsupported post type!");
|
||||
}
|
||||
}
|
||||
if(headerParams != nil){
|
||||
for(NSString * key in [headerParams keyEnumerator]){
|
||||
[request setValue:[headerParams valueForKey:key] forHTTPHeaderField:key];
|
||||
}
|
||||
}
|
||||
[request setValue:[headerParams valueForKey:responseContentType] forHTTPHeaderField:@"Accept"];
|
||||
|
||||
// Always disable cookies!
|
||||
[request setHTTPShouldHandleCookies:NO];
|
||||
|
||||
NSNumber* requestId = [SWGApiClient queueRequest];
|
||||
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
|
||||
[op setCompletionBlockWithSuccess:
|
||||
^(AFHTTPRequestOperation *resp,
|
||||
id responseObject) {
|
||||
NSString *response = [resp responseString];
|
||||
if([self executeRequestWithId:requestId]) {
|
||||
if(self.logServerResponses)
|
||||
[self logResponse:responseObject forRequest:request error:nil];
|
||||
completionBlock(response, nil);
|
||||
}
|
||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||
if([self executeRequestWithId:requestId]) {
|
||||
if(self.logServerResponses)
|
||||
[self logResponse:nil forRequest:request error:error];
|
||||
completionBlock(nil, error);
|
||||
}
|
||||
}];
|
||||
|
||||
[self enqueueHTTPRequestOperation:op];
|
||||
return requestId;
|
||||
}
|
||||
|
||||
@end
|
@ -1,31 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGApiTokenStatus : SWGObject
|
||||
|
||||
@property(nonatomic) NSNumber* valid;
|
||||
|
||||
@property(nonatomic) NSString* token;
|
||||
|
||||
@property(nonatomic) NSNumber* resetsInMillis;
|
||||
|
||||
@property(nonatomic) NSNumber* remainingCalls;
|
||||
|
||||
@property(nonatomic) NSNumber* expiresInMillis;
|
||||
|
||||
@property(nonatomic) NSNumber* totalRequests;
|
||||
|
||||
- (id) valid: (NSNumber*) valid
|
||||
token: (NSString*) token
|
||||
resetsInMillis: (NSNumber*) resetsInMillis
|
||||
remainingCalls: (NSNumber*) remainingCalls
|
||||
expiresInMillis: (NSNumber*) expiresInMillis
|
||||
totalRequests: (NSNumber*) totalRequests;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,51 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGApiTokenStatus.h"
|
||||
|
||||
@implementation SWGApiTokenStatus
|
||||
|
||||
-(id)valid: (NSNumber*) valid
|
||||
token: (NSString*) token
|
||||
resetsInMillis: (NSNumber*) resetsInMillis
|
||||
remainingCalls: (NSNumber*) remainingCalls
|
||||
expiresInMillis: (NSNumber*) expiresInMillis
|
||||
totalRequests: (NSNumber*) totalRequests
|
||||
{
|
||||
_valid = valid;
|
||||
_token = token;
|
||||
_resetsInMillis = resetsInMillis;
|
||||
_remainingCalls = remainingCalls;
|
||||
_expiresInMillis = expiresInMillis;
|
||||
_totalRequests = totalRequests;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_valid = dict[@"valid"];
|
||||
_token = dict[@"token"];
|
||||
_resetsInMillis = dict[@"resetsInMillis"];
|
||||
_remainingCalls = dict[@"remainingCalls"];
|
||||
_expiresInMillis = dict[@"expiresInMillis"];
|
||||
_totalRequests = dict[@"totalRequests"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_valid != nil) dict[@"valid"] = _valid ;
|
||||
if(_token != nil) dict[@"token"] = _token ;
|
||||
if(_resetsInMillis != nil) dict[@"resetsInMillis"] = _resetsInMillis ;
|
||||
if(_remainingCalls != nil) dict[@"remainingCalls"] = _remainingCalls ;
|
||||
if(_expiresInMillis != nil) dict[@"expiresInMillis"] = _expiresInMillis ;
|
||||
if(_totalRequests != nil) dict[@"totalRequests"] = _totalRequests ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,56 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
#import "SWGDate.h"
|
||||
|
||||
|
||||
@interface SWGAudioFile : SWGObject
|
||||
|
||||
@property(nonatomic) NSString* attributionUrl;
|
||||
|
||||
@property(nonatomic) NSNumber* commentCount;
|
||||
|
||||
@property(nonatomic) NSNumber* voteCount;
|
||||
|
||||
@property(nonatomic) NSString* fileUrl;
|
||||
|
||||
@property(nonatomic) NSString* audioType;
|
||||
|
||||
@property(nonatomic) NSNumber* _id;
|
||||
|
||||
@property(nonatomic) NSNumber* duration;
|
||||
|
||||
@property(nonatomic) NSString* attributionText;
|
||||
|
||||
@property(nonatomic) NSString* createdBy;
|
||||
|
||||
@property(nonatomic) NSString* description;
|
||||
|
||||
@property(nonatomic) SWGDate* createdAt;
|
||||
|
||||
@property(nonatomic) NSNumber* voteWeightedAverage;
|
||||
|
||||
@property(nonatomic) NSNumber* voteAverage;
|
||||
|
||||
@property(nonatomic) NSString* word;
|
||||
|
||||
- (id) attributionUrl: (NSString*) attributionUrl
|
||||
commentCount: (NSNumber*) commentCount
|
||||
voteCount: (NSNumber*) voteCount
|
||||
fileUrl: (NSString*) fileUrl
|
||||
audioType: (NSString*) audioType
|
||||
_id: (NSNumber*) _id
|
||||
duration: (NSNumber*) duration
|
||||
attributionText: (NSString*) attributionText
|
||||
createdBy: (NSString*) createdBy
|
||||
description: (NSString*) description
|
||||
createdAt: (SWGDate*) createdAt
|
||||
voteWeightedAverage: (NSNumber*) voteWeightedAverage
|
||||
voteAverage: (NSNumber*) voteAverage
|
||||
word: (NSString*) word;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,102 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGAudioFile.h"
|
||||
|
||||
@implementation SWGAudioFile
|
||||
|
||||
-(id)attributionUrl: (NSString*) attributionUrl
|
||||
commentCount: (NSNumber*) commentCount
|
||||
voteCount: (NSNumber*) voteCount
|
||||
fileUrl: (NSString*) fileUrl
|
||||
audioType: (NSString*) audioType
|
||||
_id: (NSNumber*) _id
|
||||
duration: (NSNumber*) duration
|
||||
attributionText: (NSString*) attributionText
|
||||
createdBy: (NSString*) createdBy
|
||||
description: (NSString*) description
|
||||
createdAt: (SWGDate*) createdAt
|
||||
voteWeightedAverage: (NSNumber*) voteWeightedAverage
|
||||
voteAverage: (NSNumber*) voteAverage
|
||||
word: (NSString*) word
|
||||
{
|
||||
_attributionUrl = attributionUrl;
|
||||
_commentCount = commentCount;
|
||||
_voteCount = voteCount;
|
||||
_fileUrl = fileUrl;
|
||||
_audioType = audioType;
|
||||
__id = _id;
|
||||
_duration = duration;
|
||||
_attributionText = attributionText;
|
||||
_createdBy = createdBy;
|
||||
_description = description;
|
||||
_createdAt = createdAt;
|
||||
_voteWeightedAverage = voteWeightedAverage;
|
||||
_voteAverage = voteAverage;
|
||||
_word = word;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_attributionUrl = dict[@"attributionUrl"];
|
||||
_commentCount = dict[@"commentCount"];
|
||||
_voteCount = dict[@"voteCount"];
|
||||
_fileUrl = dict[@"fileUrl"];
|
||||
_audioType = dict[@"audioType"];
|
||||
__id = dict[@"id"];
|
||||
_duration = dict[@"duration"];
|
||||
_attributionText = dict[@"attributionText"];
|
||||
_createdBy = dict[@"createdBy"];
|
||||
_description = dict[@"description"];
|
||||
id createdAt_dict = dict[@"createdAt"];
|
||||
if(createdAt_dict != nil)
|
||||
_createdAt = [[SWGDate alloc]initWithValues:createdAt_dict];
|
||||
_voteWeightedAverage = dict[@"voteWeightedAverage"];
|
||||
_voteAverage = dict[@"voteAverage"];
|
||||
_word = dict[@"word"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_attributionUrl != nil) dict[@"attributionUrl"] = _attributionUrl ;
|
||||
if(_commentCount != nil) dict[@"commentCount"] = _commentCount ;
|
||||
if(_voteCount != nil) dict[@"voteCount"] = _voteCount ;
|
||||
if(_fileUrl != nil) dict[@"fileUrl"] = _fileUrl ;
|
||||
if(_audioType != nil) dict[@"audioType"] = _audioType ;
|
||||
if(__id != nil) dict[@"id"] = __id ;
|
||||
if(_duration != nil) dict[@"duration"] = _duration ;
|
||||
if(_attributionText != nil) dict[@"attributionText"] = _attributionText ;
|
||||
if(_createdBy != nil) dict[@"createdBy"] = _createdBy ;
|
||||
if(_description != nil) dict[@"description"] = _description ;
|
||||
if(_createdAt != nil){
|
||||
if([_createdAt isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGDate *createdAt in (NSArray*)_createdAt) {
|
||||
[array addObject:[(SWGObject*)createdAt asDictionary]];
|
||||
}
|
||||
dict[@"createdAt"] = array;
|
||||
}
|
||||
else if(_createdAt && [_createdAt isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_createdAt toString];
|
||||
if(dateString){
|
||||
dict[@"createdAt"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_createdAt != nil) dict[@"createdAt"] = [(SWGObject*)_createdAt asDictionary];
|
||||
}
|
||||
}
|
||||
if(_voteWeightedAverage != nil) dict[@"voteWeightedAverage"] = _voteWeightedAverage ;
|
||||
if(_voteAverage != nil) dict[@"voteAverage"] = _voteAverage ;
|
||||
if(_word != nil) dict[@"word"] = _word ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,22 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGAuthenticationToken : SWGObject
|
||||
|
||||
@property(nonatomic) NSString* token;
|
||||
|
||||
@property(nonatomic) NSNumber* userId;
|
||||
|
||||
@property(nonatomic) NSString* userSignature;
|
||||
|
||||
- (id) token: (NSString*) token
|
||||
userId: (NSNumber*) userId
|
||||
userSignature: (NSString*) userSignature;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,39 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGAuthenticationToken.h"
|
||||
|
||||
@implementation SWGAuthenticationToken
|
||||
|
||||
-(id)token: (NSString*) token
|
||||
userId: (NSNumber*) userId
|
||||
userSignature: (NSString*) userSignature
|
||||
{
|
||||
_token = token;
|
||||
_userId = userId;
|
||||
_userSignature = userSignature;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_token = dict[@"token"];
|
||||
_userId = dict[@"userId"];
|
||||
_userSignature = dict[@"userSignature"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_token != nil) dict[@"token"] = _token ;
|
||||
if(_userId != nil) dict[@"userId"] = _userId ;
|
||||
if(_userSignature != nil) dict[@"userSignature"] = _userSignature ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,28 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGBigram : SWGObject
|
||||
|
||||
@property(nonatomic) NSNumber* count;
|
||||
|
||||
@property(nonatomic) NSString* gram2;
|
||||
|
||||
@property(nonatomic) NSString* gram1;
|
||||
|
||||
@property(nonatomic) NSNumber* wlmi;
|
||||
|
||||
@property(nonatomic) NSNumber* mi;
|
||||
|
||||
- (id) count: (NSNumber*) count
|
||||
gram2: (NSString*) gram2
|
||||
gram1: (NSString*) gram1
|
||||
wlmi: (NSNumber*) wlmi
|
||||
mi: (NSNumber*) mi;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,47 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGBigram.h"
|
||||
|
||||
@implementation SWGBigram
|
||||
|
||||
-(id)count: (NSNumber*) count
|
||||
gram2: (NSString*) gram2
|
||||
gram1: (NSString*) gram1
|
||||
wlmi: (NSNumber*) wlmi
|
||||
mi: (NSNumber*) mi
|
||||
{
|
||||
_count = count;
|
||||
_gram2 = gram2;
|
||||
_gram1 = gram1;
|
||||
_wlmi = wlmi;
|
||||
_mi = mi;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_count = dict[@"count"];
|
||||
_gram2 = dict[@"gram2"];
|
||||
_gram1 = dict[@"gram1"];
|
||||
_wlmi = dict[@"wlmi"];
|
||||
_mi = dict[@"mi"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_count != nil) dict[@"count"] = _count ;
|
||||
if(_gram2 != nil) dict[@"gram2"] = _gram2 ;
|
||||
if(_gram1 != nil) dict[@"gram1"] = _gram1 ;
|
||||
if(_wlmi != nil) dict[@"wlmi"] = _wlmi ;
|
||||
if(_mi != nil) dict[@"mi"] = _mi ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,19 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGCitation : SWGObject
|
||||
|
||||
@property(nonatomic) NSString* cite;
|
||||
|
||||
@property(nonatomic) NSString* source;
|
||||
|
||||
- (id) cite: (NSString*) cite
|
||||
source: (NSString*) source;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,35 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGCitation.h"
|
||||
|
||||
@implementation SWGCitation
|
||||
|
||||
-(id)cite: (NSString*) cite
|
||||
source: (NSString*) source
|
||||
{
|
||||
_cite = cite;
|
||||
_source = source;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_cite = dict[@"cite"];
|
||||
_source = dict[@"source"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_cite != nil) dict[@"cite"] = _cite ;
|
||||
if(_source != nil) dict[@"source"] = _source ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,19 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGContentProvider : SWGObject
|
||||
|
||||
@property(nonatomic) NSNumber* _id;
|
||||
|
||||
@property(nonatomic) NSString* name;
|
||||
|
||||
- (id) _id: (NSNumber*) _id
|
||||
name: (NSString*) name;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,35 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGContentProvider.h"
|
||||
|
||||
@implementation SWGContentProvider
|
||||
|
||||
-(id)_id: (NSNumber*) _id
|
||||
name: (NSString*) name
|
||||
{
|
||||
__id = _id;
|
||||
_name = name;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
__id = dict[@"id"];
|
||||
_name = dict[@"name"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(__id != nil) dict[@"id"] = __id ;
|
||||
if(_name != nil) dict[@"name"] = _name ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,12 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
@interface SWGDate : SWGObject {
|
||||
@private
|
||||
NSDate *_date;
|
||||
}
|
||||
@property(nonatomic, readonly) NSDate* date;
|
||||
|
||||
- (id) initWithValues: (NSString*)input;
|
||||
-(NSString*) toString;
|
||||
@end
|
@ -1,34 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
|
||||
@implementation SWGDate
|
||||
|
||||
@synthesize date = _date;
|
||||
|
||||
- (id) initWithValues:(NSString*)input {
|
||||
if([input isKindOfClass:[NSString class]]){
|
||||
NSDateFormatter* df = [NSDateFormatter new];
|
||||
NSLocale *locale = [[NSLocale new]
|
||||
initWithLocaleIdentifier:@"en_US_POSIX"];
|
||||
[df setLocale:locale];
|
||||
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
|
||||
|
||||
_date = [df dateFromString:input];
|
||||
}
|
||||
else if([input isKindOfClass:[NSNumber class]]) {
|
||||
NSTimeInterval interval = [input doubleValue];
|
||||
_date = [[NSDate alloc] initWithTimeIntervalSince1970:interval];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSString*) toString {
|
||||
NSDateFormatter* df = [NSDateFormatter new];
|
||||
NSLocale *locale = [[NSLocale new]
|
||||
initWithLocaleIdentifier:@"en_US_POSIX"];
|
||||
[df setLocale:locale];
|
||||
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
|
||||
|
||||
return [df stringFromDate:_date];
|
||||
}
|
||||
|
||||
@end
|
@ -1,67 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
#import "SWGLabel.h"
|
||||
#import "SWGExampleUsage.h"
|
||||
#import "SWGTextPron.h"
|
||||
#import "SWGCitation.h"
|
||||
#import "SWGRelated.h"
|
||||
#import "SWGNote.h"
|
||||
|
||||
|
||||
@interface SWGDefinition : SWGObject
|
||||
|
||||
@property(nonatomic) NSString* extendedText;
|
||||
|
||||
@property(nonatomic) NSString* text;
|
||||
|
||||
@property(nonatomic) NSString* sourceDictionary;
|
||||
|
||||
@property(nonatomic) NSArray* citations;
|
||||
|
||||
@property(nonatomic) NSArray* labels;
|
||||
|
||||
@property(nonatomic) NSNumber* score;
|
||||
|
||||
@property(nonatomic) NSArray* exampleUses;
|
||||
|
||||
@property(nonatomic) NSString* attributionUrl;
|
||||
|
||||
@property(nonatomic) NSString* seqString;
|
||||
|
||||
@property(nonatomic) NSString* attributionText;
|
||||
|
||||
@property(nonatomic) NSArray* relatedWords;
|
||||
|
||||
@property(nonatomic) NSString* sequence;
|
||||
|
||||
@property(nonatomic) NSString* word;
|
||||
|
||||
@property(nonatomic) NSArray* notes;
|
||||
|
||||
@property(nonatomic) NSArray* textProns;
|
||||
|
||||
@property(nonatomic) NSString* partOfSpeech;
|
||||
|
||||
- (id) extendedText: (NSString*) extendedText
|
||||
text: (NSString*) text
|
||||
sourceDictionary: (NSString*) sourceDictionary
|
||||
citations: (NSArray*) citations
|
||||
labels: (NSArray*) labels
|
||||
score: (NSNumber*) score
|
||||
exampleUses: (NSArray*) exampleUses
|
||||
attributionUrl: (NSString*) attributionUrl
|
||||
seqString: (NSString*) seqString
|
||||
attributionText: (NSString*) attributionText
|
||||
relatedWords: (NSArray*) relatedWords
|
||||
sequence: (NSString*) sequence
|
||||
word: (NSString*) word
|
||||
notes: (NSArray*) notes
|
||||
textProns: (NSArray*) textProns
|
||||
partOfSpeech: (NSString*) partOfSpeech;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,307 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGDefinition.h"
|
||||
|
||||
@implementation SWGDefinition
|
||||
|
||||
-(id)extendedText: (NSString*) extendedText
|
||||
text: (NSString*) text
|
||||
sourceDictionary: (NSString*) sourceDictionary
|
||||
citations: (NSArray*) citations
|
||||
labels: (NSArray*) labels
|
||||
score: (NSNumber*) score
|
||||
exampleUses: (NSArray*) exampleUses
|
||||
attributionUrl: (NSString*) attributionUrl
|
||||
seqString: (NSString*) seqString
|
||||
attributionText: (NSString*) attributionText
|
||||
relatedWords: (NSArray*) relatedWords
|
||||
sequence: (NSString*) sequence
|
||||
word: (NSString*) word
|
||||
notes: (NSArray*) notes
|
||||
textProns: (NSArray*) textProns
|
||||
partOfSpeech: (NSString*) partOfSpeech
|
||||
{
|
||||
_extendedText = extendedText;
|
||||
_text = text;
|
||||
_sourceDictionary = sourceDictionary;
|
||||
_citations = citations;
|
||||
_labels = labels;
|
||||
_score = score;
|
||||
_exampleUses = exampleUses;
|
||||
_attributionUrl = attributionUrl;
|
||||
_seqString = seqString;
|
||||
_attributionText = attributionText;
|
||||
_relatedWords = relatedWords;
|
||||
_sequence = sequence;
|
||||
_word = word;
|
||||
_notes = notes;
|
||||
_textProns = textProns;
|
||||
_partOfSpeech = partOfSpeech;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_extendedText = dict[@"extendedText"];
|
||||
_text = dict[@"text"];
|
||||
_sourceDictionary = dict[@"sourceDictionary"];
|
||||
id citations_dict = dict[@"citations"];
|
||||
if([citations_dict isKindOfClass:[NSArray class]]) {
|
||||
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*)citations_dict count]];
|
||||
|
||||
if([(NSArray*)citations_dict count] > 0) {
|
||||
for (NSDictionary* dict in (NSArray*)citations_dict) {
|
||||
SWGCitation* d = [[SWGCitation alloc] initWithValues:dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
|
||||
_citations = [[NSArray alloc] initWithArray:objs];
|
||||
}
|
||||
else {
|
||||
_citations = [[NSArray alloc] init];
|
||||
}
|
||||
}
|
||||
else {
|
||||
_citations = [[NSArray alloc] init];
|
||||
}
|
||||
id labels_dict = dict[@"labels"];
|
||||
if([labels_dict isKindOfClass:[NSArray class]]) {
|
||||
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*)labels_dict count]];
|
||||
|
||||
if([(NSArray*)labels_dict count] > 0) {
|
||||
for (NSDictionary* dict in (NSArray*)labels_dict) {
|
||||
SWGLabel* d = [[SWGLabel alloc] initWithValues:dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
|
||||
_labels = [[NSArray alloc] initWithArray:objs];
|
||||
}
|
||||
else {
|
||||
_labels = [[NSArray alloc] init];
|
||||
}
|
||||
}
|
||||
else {
|
||||
_labels = [[NSArray alloc] init];
|
||||
}
|
||||
_score = dict[@"score"];
|
||||
id exampleUses_dict = dict[@"exampleUses"];
|
||||
if([exampleUses_dict isKindOfClass:[NSArray class]]) {
|
||||
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*)exampleUses_dict count]];
|
||||
|
||||
if([(NSArray*)exampleUses_dict count] > 0) {
|
||||
for (NSDictionary* dict in (NSArray*)exampleUses_dict) {
|
||||
SWGExampleUsage* d = [[SWGExampleUsage alloc] initWithValues:dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
|
||||
_exampleUses = [[NSArray alloc] initWithArray:objs];
|
||||
}
|
||||
else {
|
||||
_exampleUses = [[NSArray alloc] init];
|
||||
}
|
||||
}
|
||||
else {
|
||||
_exampleUses = [[NSArray alloc] init];
|
||||
}
|
||||
_attributionUrl = dict[@"attributionUrl"];
|
||||
_seqString = dict[@"seqString"];
|
||||
_attributionText = dict[@"attributionText"];
|
||||
id relatedWords_dict = dict[@"relatedWords"];
|
||||
if([relatedWords_dict isKindOfClass:[NSArray class]]) {
|
||||
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*)relatedWords_dict count]];
|
||||
|
||||
if([(NSArray*)relatedWords_dict count] > 0) {
|
||||
for (NSDictionary* dict in (NSArray*)relatedWords_dict) {
|
||||
SWGRelated* d = [[SWGRelated alloc] initWithValues:dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
|
||||
_relatedWords = [[NSArray alloc] initWithArray:objs];
|
||||
}
|
||||
else {
|
||||
_relatedWords = [[NSArray alloc] init];
|
||||
}
|
||||
}
|
||||
else {
|
||||
_relatedWords = [[NSArray alloc] init];
|
||||
}
|
||||
_sequence = dict[@"sequence"];
|
||||
_word = dict[@"word"];
|
||||
id notes_dict = dict[@"notes"];
|
||||
if([notes_dict isKindOfClass:[NSArray class]]) {
|
||||
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*)notes_dict count]];
|
||||
|
||||
if([(NSArray*)notes_dict count] > 0) {
|
||||
for (NSDictionary* dict in (NSArray*)notes_dict) {
|
||||
SWGNote* d = [[SWGNote alloc] initWithValues:dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
|
||||
_notes = [[NSArray alloc] initWithArray:objs];
|
||||
}
|
||||
else {
|
||||
_notes = [[NSArray alloc] init];
|
||||
}
|
||||
}
|
||||
else {
|
||||
_notes = [[NSArray alloc] init];
|
||||
}
|
||||
id textProns_dict = dict[@"textProns"];
|
||||
if([textProns_dict isKindOfClass:[NSArray class]]) {
|
||||
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*)textProns_dict count]];
|
||||
|
||||
if([(NSArray*)textProns_dict count] > 0) {
|
||||
for (NSDictionary* dict in (NSArray*)textProns_dict) {
|
||||
SWGTextPron* d = [[SWGTextPron alloc] initWithValues:dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
|
||||
_textProns = [[NSArray alloc] initWithArray:objs];
|
||||
}
|
||||
else {
|
||||
_textProns = [[NSArray alloc] init];
|
||||
}
|
||||
}
|
||||
else {
|
||||
_textProns = [[NSArray alloc] init];
|
||||
}
|
||||
_partOfSpeech = dict[@"partOfSpeech"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_extendedText != nil) dict[@"extendedText"] = _extendedText ;
|
||||
if(_text != nil) dict[@"text"] = _text ;
|
||||
if(_sourceDictionary != nil) dict[@"sourceDictionary"] = _sourceDictionary ;
|
||||
if(_citations != nil){
|
||||
if([_citations isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGCitation *citations in (NSArray*)_citations) {
|
||||
[array addObject:[(SWGObject*)citations asDictionary]];
|
||||
}
|
||||
dict[@"citations"] = array;
|
||||
}
|
||||
else if(_citations && [_citations isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_citations toString];
|
||||
if(dateString){
|
||||
dict[@"citations"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_citations != nil) dict[@"citations"] = [(SWGObject*)_citations asDictionary];
|
||||
}
|
||||
}
|
||||
if(_labels != nil){
|
||||
if([_labels isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGLabel *labels in (NSArray*)_labels) {
|
||||
[array addObject:[(SWGObject*)labels asDictionary]];
|
||||
}
|
||||
dict[@"labels"] = array;
|
||||
}
|
||||
else if(_labels && [_labels isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_labels toString];
|
||||
if(dateString){
|
||||
dict[@"labels"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_labels != nil) dict[@"labels"] = [(SWGObject*)_labels asDictionary];
|
||||
}
|
||||
}
|
||||
if(_score != nil) dict[@"score"] = _score ;
|
||||
if(_exampleUses != nil){
|
||||
if([_exampleUses isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGExampleUsage *exampleUses in (NSArray*)_exampleUses) {
|
||||
[array addObject:[(SWGObject*)exampleUses asDictionary]];
|
||||
}
|
||||
dict[@"exampleUses"] = array;
|
||||
}
|
||||
else if(_exampleUses && [_exampleUses isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_exampleUses toString];
|
||||
if(dateString){
|
||||
dict[@"exampleUses"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_exampleUses != nil) dict[@"exampleUses"] = [(SWGObject*)_exampleUses asDictionary];
|
||||
}
|
||||
}
|
||||
if(_attributionUrl != nil) dict[@"attributionUrl"] = _attributionUrl ;
|
||||
if(_seqString != nil) dict[@"seqString"] = _seqString ;
|
||||
if(_attributionText != nil) dict[@"attributionText"] = _attributionText ;
|
||||
if(_relatedWords != nil){
|
||||
if([_relatedWords isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGRelated *relatedWords in (NSArray*)_relatedWords) {
|
||||
[array addObject:[(SWGObject*)relatedWords asDictionary]];
|
||||
}
|
||||
dict[@"relatedWords"] = array;
|
||||
}
|
||||
else if(_relatedWords && [_relatedWords isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_relatedWords toString];
|
||||
if(dateString){
|
||||
dict[@"relatedWords"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_relatedWords != nil) dict[@"relatedWords"] = [(SWGObject*)_relatedWords asDictionary];
|
||||
}
|
||||
}
|
||||
if(_sequence != nil) dict[@"sequence"] = _sequence ;
|
||||
if(_word != nil) dict[@"word"] = _word ;
|
||||
if(_notes != nil){
|
||||
if([_notes isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGNote *notes in (NSArray*)_notes) {
|
||||
[array addObject:[(SWGObject*)notes asDictionary]];
|
||||
}
|
||||
dict[@"notes"] = array;
|
||||
}
|
||||
else if(_notes && [_notes isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_notes toString];
|
||||
if(dateString){
|
||||
dict[@"notes"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_notes != nil) dict[@"notes"] = [(SWGObject*)_notes asDictionary];
|
||||
}
|
||||
}
|
||||
if(_textProns != nil){
|
||||
if([_textProns isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGTextPron *textProns in (NSArray*)_textProns) {
|
||||
[array addObject:[(SWGObject*)textProns asDictionary]];
|
||||
}
|
||||
dict[@"textProns"] = array;
|
||||
}
|
||||
else if(_textProns && [_textProns isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_textProns toString];
|
||||
if(dateString){
|
||||
dict[@"textProns"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_textProns != nil) dict[@"textProns"] = [(SWGObject*)_textProns asDictionary];
|
||||
}
|
||||
}
|
||||
if(_partOfSpeech != nil) dict[@"partOfSpeech"] = _partOfSpeech ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,20 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
#import "SWGDefinition.h"
|
||||
|
||||
|
||||
@interface SWGDefinitionSearchResults : SWGObject
|
||||
|
||||
@property(nonatomic) NSArray* results;
|
||||
|
||||
@property(nonatomic) NSNumber* totalResults;
|
||||
|
||||
- (id) results: (NSArray*) results
|
||||
totalResults: (NSNumber*) totalResults;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,71 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGDefinitionSearchResults.h"
|
||||
|
||||
@implementation SWGDefinitionSearchResults
|
||||
|
||||
-(id)results: (NSArray*) results
|
||||
totalResults: (NSNumber*) totalResults
|
||||
{
|
||||
_results = results;
|
||||
_totalResults = totalResults;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
id results_dict = dict[@"results"];
|
||||
if([results_dict isKindOfClass:[NSArray class]]) {
|
||||
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*)results_dict count]];
|
||||
|
||||
if([(NSArray*)results_dict count] > 0) {
|
||||
for (NSDictionary* dict in (NSArray*)results_dict) {
|
||||
SWGDefinition* d = [[SWGDefinition alloc] initWithValues:dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
|
||||
_results = [[NSArray alloc] initWithArray:objs];
|
||||
}
|
||||
else {
|
||||
_results = [[NSArray alloc] init];
|
||||
}
|
||||
}
|
||||
else {
|
||||
_results = [[NSArray alloc] init];
|
||||
}
|
||||
_totalResults = dict[@"totalResults"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_results != nil){
|
||||
if([_results isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGDefinition *results in (NSArray*)_results) {
|
||||
[array addObject:[(SWGObject*)results asDictionary]];
|
||||
}
|
||||
dict[@"results"] = array;
|
||||
}
|
||||
else if(_results && [_results isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_results toString];
|
||||
if(dateString){
|
||||
dict[@"results"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_results != nil) dict[@"results"] = [(SWGObject*)_results asDictionary];
|
||||
}
|
||||
}
|
||||
if(_totalResults != nil) dict[@"totalResults"] = _totalResults ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,52 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
#import "SWGSentence.h"
|
||||
#import "SWGContentProvider.h"
|
||||
#import "SWGScoredWord.h"
|
||||
|
||||
|
||||
@interface SWGExample : SWGObject
|
||||
|
||||
@property(nonatomic) NSNumber* _id;
|
||||
|
||||
@property(nonatomic) NSNumber* exampleId;
|
||||
|
||||
@property(nonatomic) NSString* title;
|
||||
|
||||
@property(nonatomic) NSString* text;
|
||||
|
||||
@property(nonatomic) SWGScoredWord* score;
|
||||
|
||||
@property(nonatomic) SWGSentence* sentence;
|
||||
|
||||
@property(nonatomic) NSString* word;
|
||||
|
||||
@property(nonatomic) SWGContentProvider* provider;
|
||||
|
||||
@property(nonatomic) NSNumber* year;
|
||||
|
||||
@property(nonatomic) NSNumber* rating;
|
||||
|
||||
@property(nonatomic) NSNumber* documentId;
|
||||
|
||||
@property(nonatomic) NSString* url;
|
||||
|
||||
- (id) _id: (NSNumber*) _id
|
||||
exampleId: (NSNumber*) exampleId
|
||||
title: (NSString*) title
|
||||
text: (NSString*) text
|
||||
score: (SWGScoredWord*) score
|
||||
sentence: (SWGSentence*) sentence
|
||||
word: (NSString*) word
|
||||
provider: (SWGContentProvider*) provider
|
||||
year: (NSNumber*) year
|
||||
rating: (NSNumber*) rating
|
||||
documentId: (NSNumber*) documentId
|
||||
url: (NSString*) url;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,132 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGExample.h"
|
||||
|
||||
@implementation SWGExample
|
||||
|
||||
-(id)_id: (NSNumber*) _id
|
||||
exampleId: (NSNumber*) exampleId
|
||||
title: (NSString*) title
|
||||
text: (NSString*) text
|
||||
score: (SWGScoredWord*) score
|
||||
sentence: (SWGSentence*) sentence
|
||||
word: (NSString*) word
|
||||
provider: (SWGContentProvider*) provider
|
||||
year: (NSNumber*) year
|
||||
rating: (NSNumber*) rating
|
||||
documentId: (NSNumber*) documentId
|
||||
url: (NSString*) url
|
||||
{
|
||||
__id = _id;
|
||||
_exampleId = exampleId;
|
||||
_title = title;
|
||||
_text = text;
|
||||
_score = score;
|
||||
_sentence = sentence;
|
||||
_word = word;
|
||||
_provider = provider;
|
||||
_year = year;
|
||||
_rating = rating;
|
||||
_documentId = documentId;
|
||||
_url = url;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
__id = dict[@"id"];
|
||||
_exampleId = dict[@"exampleId"];
|
||||
_title = dict[@"title"];
|
||||
_text = dict[@"text"];
|
||||
id score_dict = dict[@"score"];
|
||||
if(score_dict != nil)
|
||||
_score = [[SWGScoredWord alloc]initWithValues:score_dict];
|
||||
id sentence_dict = dict[@"sentence"];
|
||||
if(sentence_dict != nil)
|
||||
_sentence = [[SWGSentence alloc]initWithValues:sentence_dict];
|
||||
_word = dict[@"word"];
|
||||
id provider_dict = dict[@"provider"];
|
||||
if(provider_dict != nil)
|
||||
_provider = [[SWGContentProvider alloc]initWithValues:provider_dict];
|
||||
_year = dict[@"year"];
|
||||
_rating = dict[@"rating"];
|
||||
_documentId = dict[@"documentId"];
|
||||
_url = dict[@"url"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(__id != nil) dict[@"id"] = __id ;
|
||||
if(_exampleId != nil) dict[@"exampleId"] = _exampleId ;
|
||||
if(_title != nil) dict[@"title"] = _title ;
|
||||
if(_text != nil) dict[@"text"] = _text ;
|
||||
if(_score != nil){
|
||||
if([_score isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGScoredWord *score in (NSArray*)_score) {
|
||||
[array addObject:[(SWGObject*)score asDictionary]];
|
||||
}
|
||||
dict[@"score"] = array;
|
||||
}
|
||||
else if(_score && [_score isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_score toString];
|
||||
if(dateString){
|
||||
dict[@"score"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_score != nil) dict[@"score"] = [(SWGObject*)_score asDictionary];
|
||||
}
|
||||
}
|
||||
if(_sentence != nil){
|
||||
if([_sentence isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGSentence *sentence in (NSArray*)_sentence) {
|
||||
[array addObject:[(SWGObject*)sentence asDictionary]];
|
||||
}
|
||||
dict[@"sentence"] = array;
|
||||
}
|
||||
else if(_sentence && [_sentence isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_sentence toString];
|
||||
if(dateString){
|
||||
dict[@"sentence"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_sentence != nil) dict[@"sentence"] = [(SWGObject*)_sentence asDictionary];
|
||||
}
|
||||
}
|
||||
if(_word != nil) dict[@"word"] = _word ;
|
||||
if(_provider != nil){
|
||||
if([_provider isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGContentProvider *provider in (NSArray*)_provider) {
|
||||
[array addObject:[(SWGObject*)provider asDictionary]];
|
||||
}
|
||||
dict[@"provider"] = array;
|
||||
}
|
||||
else if(_provider && [_provider isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_provider toString];
|
||||
if(dateString){
|
||||
dict[@"provider"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_provider != nil) dict[@"provider"] = [(SWGObject*)_provider asDictionary];
|
||||
}
|
||||
}
|
||||
if(_year != nil) dict[@"year"] = _year ;
|
||||
if(_rating != nil) dict[@"rating"] = _rating ;
|
||||
if(_documentId != nil) dict[@"documentId"] = _documentId ;
|
||||
if(_url != nil) dict[@"url"] = _url ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,21 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
#import "SWGFacet.h"
|
||||
#import "SWGExample.h"
|
||||
|
||||
|
||||
@interface SWGExampleSearchResults : SWGObject
|
||||
|
||||
@property(nonatomic) NSArray* facets;
|
||||
|
||||
@property(nonatomic) NSArray* examples;
|
||||
|
||||
- (id) facets: (NSArray*) facets
|
||||
examples: (NSArray*) examples;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,107 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGExampleSearchResults.h"
|
||||
|
||||
@implementation SWGExampleSearchResults
|
||||
|
||||
-(id)facets: (NSArray*) facets
|
||||
examples: (NSArray*) examples
|
||||
{
|
||||
_facets = facets;
|
||||
_examples = examples;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
id facets_dict = dict[@"facets"];
|
||||
if([facets_dict isKindOfClass:[NSArray class]]) {
|
||||
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*)facets_dict count]];
|
||||
|
||||
if([(NSArray*)facets_dict count] > 0) {
|
||||
for (NSDictionary* dict in (NSArray*)facets_dict) {
|
||||
SWGFacet* d = [[SWGFacet alloc] initWithValues:dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
|
||||
_facets = [[NSArray alloc] initWithArray:objs];
|
||||
}
|
||||
else {
|
||||
_facets = [[NSArray alloc] init];
|
||||
}
|
||||
}
|
||||
else {
|
||||
_facets = [[NSArray alloc] init];
|
||||
}
|
||||
id examples_dict = dict[@"examples"];
|
||||
if([examples_dict isKindOfClass:[NSArray class]]) {
|
||||
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*)examples_dict count]];
|
||||
|
||||
if([(NSArray*)examples_dict count] > 0) {
|
||||
for (NSDictionary* dict in (NSArray*)examples_dict) {
|
||||
SWGExample* d = [[SWGExample alloc] initWithValues:dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
|
||||
_examples = [[NSArray alloc] initWithArray:objs];
|
||||
}
|
||||
else {
|
||||
_examples = [[NSArray alloc] init];
|
||||
}
|
||||
}
|
||||
else {
|
||||
_examples = [[NSArray alloc] init];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_facets != nil){
|
||||
if([_facets isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGFacet *facets in (NSArray*)_facets) {
|
||||
[array addObject:[(SWGObject*)facets asDictionary]];
|
||||
}
|
||||
dict[@"facets"] = array;
|
||||
}
|
||||
else if(_facets && [_facets isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_facets toString];
|
||||
if(dateString){
|
||||
dict[@"facets"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_facets != nil) dict[@"facets"] = [(SWGObject*)_facets asDictionary];
|
||||
}
|
||||
}
|
||||
if(_examples != nil){
|
||||
if([_examples isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGExample *examples in (NSArray*)_examples) {
|
||||
[array addObject:[(SWGObject*)examples asDictionary]];
|
||||
}
|
||||
dict[@"examples"] = array;
|
||||
}
|
||||
else if(_examples && [_examples isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_examples toString];
|
||||
if(dateString){
|
||||
dict[@"examples"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_examples != nil) dict[@"examples"] = [(SWGObject*)_examples asDictionary];
|
||||
}
|
||||
}
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,16 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGExampleUsage : SWGObject
|
||||
|
||||
@property(nonatomic) NSString* text;
|
||||
|
||||
- (id) text: (NSString*) text;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,31 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGExampleUsage.h"
|
||||
|
||||
@implementation SWGExampleUsage
|
||||
|
||||
-(id)text: (NSString*) text
|
||||
{
|
||||
_text = text;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_text = dict[@"text"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_text != nil) dict[@"text"] = _text ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,20 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
#import "SWGFacetValue.h"
|
||||
|
||||
|
||||
@interface SWGFacet : SWGObject
|
||||
|
||||
@property(nonatomic) NSArray* facetValues;
|
||||
|
||||
@property(nonatomic) NSString* name;
|
||||
|
||||
- (id) facetValues: (NSArray*) facetValues
|
||||
name: (NSString*) name;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,71 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGFacet.h"
|
||||
|
||||
@implementation SWGFacet
|
||||
|
||||
-(id)facetValues: (NSArray*) facetValues
|
||||
name: (NSString*) name
|
||||
{
|
||||
_facetValues = facetValues;
|
||||
_name = name;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
id facetValues_dict = dict[@"facetValues"];
|
||||
if([facetValues_dict isKindOfClass:[NSArray class]]) {
|
||||
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*)facetValues_dict count]];
|
||||
|
||||
if([(NSArray*)facetValues_dict count] > 0) {
|
||||
for (NSDictionary* dict in (NSArray*)facetValues_dict) {
|
||||
SWGFacetValue* d = [[SWGFacetValue alloc] initWithValues:dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
|
||||
_facetValues = [[NSArray alloc] initWithArray:objs];
|
||||
}
|
||||
else {
|
||||
_facetValues = [[NSArray alloc] init];
|
||||
}
|
||||
}
|
||||
else {
|
||||
_facetValues = [[NSArray alloc] init];
|
||||
}
|
||||
_name = dict[@"name"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_facetValues != nil){
|
||||
if([_facetValues isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGFacetValue *facetValues in (NSArray*)_facetValues) {
|
||||
[array addObject:[(SWGObject*)facetValues asDictionary]];
|
||||
}
|
||||
dict[@"facetValues"] = array;
|
||||
}
|
||||
else if(_facetValues && [_facetValues isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_facetValues toString];
|
||||
if(dateString){
|
||||
dict[@"facetValues"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_facetValues != nil) dict[@"facetValues"] = [(SWGObject*)_facetValues asDictionary];
|
||||
}
|
||||
}
|
||||
if(_name != nil) dict[@"name"] = _name ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,19 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGFacetValue : SWGObject
|
||||
|
||||
@property(nonatomic) NSNumber* count;
|
||||
|
||||
@property(nonatomic) NSString* value;
|
||||
|
||||
- (id) count: (NSNumber*) count
|
||||
value: (NSString*) value;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,35 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGFacetValue.h"
|
||||
|
||||
@implementation SWGFacetValue
|
||||
|
||||
-(id)count: (NSNumber*) count
|
||||
value: (NSString*) value
|
||||
{
|
||||
_count = count;
|
||||
_value = value;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_count = dict[@"count"];
|
||||
_value = dict[@"value"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_count != nil) dict[@"count"] = _count ;
|
||||
if(_value != nil) dict[@"value"] = _value ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,13 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface SWGFile : NSObject
|
||||
|
||||
@property(nonatomic, readonly) NSString* name;
|
||||
@property(nonatomic, readonly) NSString* mimeType;
|
||||
@property(nonatomic, readonly) NSData* data;
|
||||
|
||||
- (id) initWithNameData: (NSString*) filename
|
||||
mimeType: (NSString*) mimeType
|
||||
data: (NSData*) data;
|
||||
|
||||
@end
|
@ -1,26 +0,0 @@
|
||||
#import "SWGFile.h"
|
||||
|
||||
@implementation SWGFile
|
||||
|
||||
@synthesize name = _name;
|
||||
@synthesize mimeType = _mimeType;
|
||||
@synthesize data = _data;
|
||||
|
||||
- (id) init {
|
||||
self = [super init];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithNameData: (NSString*) filename
|
||||
mimeType: (NSString*) fileMimeType
|
||||
data: (NSData*) data {
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_name = filename;
|
||||
_mimeType = fileMimeType;
|
||||
_data = data;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
@ -1,19 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGFrequency : SWGObject
|
||||
|
||||
@property(nonatomic) NSNumber* count;
|
||||
|
||||
@property(nonatomic) NSNumber* year;
|
||||
|
||||
- (id) count: (NSNumber*) count
|
||||
year: (NSNumber*) year;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,35 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGFrequency.h"
|
||||
|
||||
@implementation SWGFrequency
|
||||
|
||||
-(id)count: (NSNumber*) count
|
||||
year: (NSNumber*) year
|
||||
{
|
||||
_count = count;
|
||||
_year = year;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_count = dict[@"count"];
|
||||
_year = dict[@"year"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_count != nil) dict[@"count"] = _count ;
|
||||
if(_year != nil) dict[@"year"] = _year ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,29 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
#import "SWGFrequency.h"
|
||||
|
||||
|
||||
@interface SWGFrequencySummary : SWGObject
|
||||
|
||||
@property(nonatomic) NSNumber* unknownYearCount;
|
||||
|
||||
@property(nonatomic) NSNumber* totalCount;
|
||||
|
||||
@property(nonatomic) NSString* frequencyString;
|
||||
|
||||
@property(nonatomic) NSString* word;
|
||||
|
||||
@property(nonatomic) NSArray* frequency;
|
||||
|
||||
- (id) unknownYearCount: (NSNumber*) unknownYearCount
|
||||
totalCount: (NSNumber*) totalCount
|
||||
frequencyString: (NSString*) frequencyString
|
||||
word: (NSString*) word
|
||||
frequency: (NSArray*) frequency;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,83 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGFrequencySummary.h"
|
||||
|
||||
@implementation SWGFrequencySummary
|
||||
|
||||
-(id)unknownYearCount: (NSNumber*) unknownYearCount
|
||||
totalCount: (NSNumber*) totalCount
|
||||
frequencyString: (NSString*) frequencyString
|
||||
word: (NSString*) word
|
||||
frequency: (NSArray*) frequency
|
||||
{
|
||||
_unknownYearCount = unknownYearCount;
|
||||
_totalCount = totalCount;
|
||||
_frequencyString = frequencyString;
|
||||
_word = word;
|
||||
_frequency = frequency;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_unknownYearCount = dict[@"unknownYearCount"];
|
||||
_totalCount = dict[@"totalCount"];
|
||||
_frequencyString = dict[@"frequencyString"];
|
||||
_word = dict[@"word"];
|
||||
id frequency_dict = dict[@"frequency"];
|
||||
if([frequency_dict isKindOfClass:[NSArray class]]) {
|
||||
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*)frequency_dict count]];
|
||||
|
||||
if([(NSArray*)frequency_dict count] > 0) {
|
||||
for (NSDictionary* dict in (NSArray*)frequency_dict) {
|
||||
SWGFrequency* d = [[SWGFrequency alloc] initWithValues:dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
|
||||
_frequency = [[NSArray alloc] initWithArray:objs];
|
||||
}
|
||||
else {
|
||||
_frequency = [[NSArray alloc] init];
|
||||
}
|
||||
}
|
||||
else {
|
||||
_frequency = [[NSArray alloc] init];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_unknownYearCount != nil) dict[@"unknownYearCount"] = _unknownYearCount ;
|
||||
if(_totalCount != nil) dict[@"totalCount"] = _totalCount ;
|
||||
if(_frequencyString != nil) dict[@"frequencyString"] = _frequencyString ;
|
||||
if(_word != nil) dict[@"word"] = _word ;
|
||||
if(_frequency != nil){
|
||||
if([_frequency isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGFrequency *frequency in (NSArray*)_frequency) {
|
||||
[array addObject:[(SWGObject*)frequency asDictionary]];
|
||||
}
|
||||
dict[@"frequency"] = array;
|
||||
}
|
||||
else if(_frequency && [_frequency isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_frequency toString];
|
||||
if(dateString){
|
||||
dict[@"frequency"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_frequency != nil) dict[@"frequency"] = [(SWGObject*)_frequency asDictionary];
|
||||
}
|
||||
}
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,19 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGLabel : SWGObject
|
||||
|
||||
@property(nonatomic) NSString* text;
|
||||
|
||||
@property(nonatomic) NSString* type;
|
||||
|
||||
- (id) text: (NSString*) text
|
||||
type: (NSString*) type;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,35 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGLabel.h"
|
||||
|
||||
@implementation SWGLabel
|
||||
|
||||
-(id)text: (NSString*) text
|
||||
type: (NSString*) type
|
||||
{
|
||||
_text = text;
|
||||
_type = type;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_text = dict[@"text"];
|
||||
_type = dict[@"type"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_text != nil) dict[@"text"] = _text ;
|
||||
if(_type != nil) dict[@"type"] = _type ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,25 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGNote : SWGObject
|
||||
|
||||
@property(nonatomic) NSString* noteType;
|
||||
|
||||
@property(nonatomic) NSArray* appliesTo;
|
||||
|
||||
@property(nonatomic) NSString* value;
|
||||
|
||||
@property(nonatomic) NSNumber* pos;
|
||||
|
||||
- (id) noteType: (NSString*) noteType
|
||||
appliesTo: (NSArray*) appliesTo
|
||||
value: (NSString*) value
|
||||
pos: (NSNumber*) pos;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,43 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGNote.h"
|
||||
|
||||
@implementation SWGNote
|
||||
|
||||
-(id)noteType: (NSString*) noteType
|
||||
appliesTo: (NSArray*) appliesTo
|
||||
value: (NSString*) value
|
||||
pos: (NSNumber*) pos
|
||||
{
|
||||
_noteType = noteType;
|
||||
_appliesTo = appliesTo;
|
||||
_value = value;
|
||||
_pos = pos;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_noteType = dict[@"noteType"];
|
||||
_appliesTo = dict[@"appliesTo"];
|
||||
_value = dict[@"value"];
|
||||
_pos = dict[@"pos"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_noteType != nil) dict[@"noteType"] = _noteType ;
|
||||
if(_appliesTo != nil) dict[@"appliesTo"] = _appliesTo ;
|
||||
if(_value != nil) dict[@"value"] = _value ;
|
||||
if(_pos != nil) dict[@"pos"] = _pos ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,6 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface SWGObject : NSObject
|
||||
- (id) initWithValues:(NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
@end
|
@ -1,17 +0,0 @@
|
||||
#import "SWGObject.h"
|
||||
|
||||
@implementation SWGObject
|
||||
|
||||
- (id) initWithValues:(NSDictionary*)dict {
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSDictionary*) asDictionary{
|
||||
return [NSDictionary init];
|
||||
}
|
||||
|
||||
- (NSString*)description {
|
||||
return [NSString stringWithFormat:@"%@ %@", [super description], [self asDictionary]];
|
||||
}
|
||||
|
||||
@end
|
@ -1,34 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGRelated : SWGObject
|
||||
|
||||
@property(nonatomic) NSString* label1;
|
||||
|
||||
@property(nonatomic) NSString* relationshipType;
|
||||
|
||||
@property(nonatomic) NSString* label2;
|
||||
|
||||
@property(nonatomic) NSString* label3;
|
||||
|
||||
@property(nonatomic) NSArray* words;
|
||||
|
||||
@property(nonatomic) NSString* gram;
|
||||
|
||||
@property(nonatomic) NSString* label4;
|
||||
|
||||
- (id) label1: (NSString*) label1
|
||||
relationshipType: (NSString*) relationshipType
|
||||
label2: (NSString*) label2
|
||||
label3: (NSString*) label3
|
||||
words: (NSArray*) words
|
||||
gram: (NSString*) gram
|
||||
label4: (NSString*) label4;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,55 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGRelated.h"
|
||||
|
||||
@implementation SWGRelated
|
||||
|
||||
-(id)label1: (NSString*) label1
|
||||
relationshipType: (NSString*) relationshipType
|
||||
label2: (NSString*) label2
|
||||
label3: (NSString*) label3
|
||||
words: (NSArray*) words
|
||||
gram: (NSString*) gram
|
||||
label4: (NSString*) label4
|
||||
{
|
||||
_label1 = label1;
|
||||
_relationshipType = relationshipType;
|
||||
_label2 = label2;
|
||||
_label3 = label3;
|
||||
_words = words;
|
||||
_gram = gram;
|
||||
_label4 = label4;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_label1 = dict[@"label1"];
|
||||
_relationshipType = dict[@"relationshipType"];
|
||||
_label2 = dict[@"label2"];
|
||||
_label3 = dict[@"label3"];
|
||||
_words = dict[@"words"];
|
||||
_gram = dict[@"gram"];
|
||||
_label4 = dict[@"label4"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_label1 != nil) dict[@"label1"] = _label1 ;
|
||||
if(_relationshipType != nil) dict[@"relationshipType"] = _relationshipType ;
|
||||
if(_label2 != nil) dict[@"label2"] = _label2 ;
|
||||
if(_label3 != nil) dict[@"label3"] = _label3 ;
|
||||
if(_words != nil) dict[@"words"] = _words ;
|
||||
if(_gram != nil) dict[@"gram"] = _gram ;
|
||||
if(_label4 != nil) dict[@"label4"] = _label4 ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,46 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGScoredWord : SWGObject
|
||||
|
||||
@property(nonatomic) NSNumber* position;
|
||||
|
||||
@property(nonatomic) NSNumber* _id;
|
||||
|
||||
@property(nonatomic) NSNumber* docTermCount;
|
||||
|
||||
@property(nonatomic) NSString* lemma;
|
||||
|
||||
@property(nonatomic) NSString* wordType;
|
||||
|
||||
@property(nonatomic) NSNumber* score;
|
||||
|
||||
@property(nonatomic) NSNumber* sentenceId;
|
||||
|
||||
@property(nonatomic) NSString* word;
|
||||
|
||||
@property(nonatomic) NSNumber* stopword;
|
||||
|
||||
@property(nonatomic) NSNumber* baseWordScore;
|
||||
|
||||
@property(nonatomic) NSString* partOfSpeech;
|
||||
|
||||
- (id) position: (NSNumber*) position
|
||||
_id: (NSNumber*) _id
|
||||
docTermCount: (NSNumber*) docTermCount
|
||||
lemma: (NSString*) lemma
|
||||
wordType: (NSString*) wordType
|
||||
score: (NSNumber*) score
|
||||
sentenceId: (NSNumber*) sentenceId
|
||||
word: (NSString*) word
|
||||
stopword: (NSNumber*) stopword
|
||||
baseWordScore: (NSNumber*) baseWordScore
|
||||
partOfSpeech: (NSString*) partOfSpeech;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,71 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGScoredWord.h"
|
||||
|
||||
@implementation SWGScoredWord
|
||||
|
||||
-(id)position: (NSNumber*) position
|
||||
_id: (NSNumber*) _id
|
||||
docTermCount: (NSNumber*) docTermCount
|
||||
lemma: (NSString*) lemma
|
||||
wordType: (NSString*) wordType
|
||||
score: (NSNumber*) score
|
||||
sentenceId: (NSNumber*) sentenceId
|
||||
word: (NSString*) word
|
||||
stopword: (NSNumber*) stopword
|
||||
baseWordScore: (NSNumber*) baseWordScore
|
||||
partOfSpeech: (NSString*) partOfSpeech
|
||||
{
|
||||
_position = position;
|
||||
__id = _id;
|
||||
_docTermCount = docTermCount;
|
||||
_lemma = lemma;
|
||||
_wordType = wordType;
|
||||
_score = score;
|
||||
_sentenceId = sentenceId;
|
||||
_word = word;
|
||||
_stopword = stopword;
|
||||
_baseWordScore = baseWordScore;
|
||||
_partOfSpeech = partOfSpeech;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_position = dict[@"position"];
|
||||
__id = dict[@"id"];
|
||||
_docTermCount = dict[@"docTermCount"];
|
||||
_lemma = dict[@"lemma"];
|
||||
_wordType = dict[@"wordType"];
|
||||
_score = dict[@"score"];
|
||||
_sentenceId = dict[@"sentenceId"];
|
||||
_word = dict[@"word"];
|
||||
_stopword = dict[@"stopword"];
|
||||
_baseWordScore = dict[@"baseWordScore"];
|
||||
_partOfSpeech = dict[@"partOfSpeech"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_position != nil) dict[@"position"] = _position ;
|
||||
if(__id != nil) dict[@"id"] = __id ;
|
||||
if(_docTermCount != nil) dict[@"docTermCount"] = _docTermCount ;
|
||||
if(_lemma != nil) dict[@"lemma"] = _lemma ;
|
||||
if(_wordType != nil) dict[@"wordType"] = _wordType ;
|
||||
if(_score != nil) dict[@"score"] = _score ;
|
||||
if(_sentenceId != nil) dict[@"sentenceId"] = _sentenceId ;
|
||||
if(_word != nil) dict[@"word"] = _word ;
|
||||
if(_stopword != nil) dict[@"stopword"] = _stopword ;
|
||||
if(_baseWordScore != nil) dict[@"baseWordScore"] = _baseWordScore ;
|
||||
if(_partOfSpeech != nil) dict[@"partOfSpeech"] = _partOfSpeech ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,16 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGScrabbleScoreResult : SWGObject
|
||||
|
||||
@property(nonatomic) NSNumber* value;
|
||||
|
||||
- (id) value: (NSNumber*) value;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,31 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGScrabbleScoreResult.h"
|
||||
|
||||
@implementation SWGScrabbleScoreResult
|
||||
|
||||
-(id)value: (NSNumber*) value
|
||||
{
|
||||
_value = value;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_value = dict[@"value"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_value != nil) dict[@"value"] = _value ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,32 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
#import "SWGScoredWord.h"
|
||||
|
||||
|
||||
@interface SWGSentence : SWGObject
|
||||
|
||||
@property(nonatomic) NSNumber* hasScoredWords;
|
||||
|
||||
@property(nonatomic) NSNumber* _id;
|
||||
|
||||
@property(nonatomic) NSArray* scoredWords;
|
||||
|
||||
@property(nonatomic) NSString* display;
|
||||
|
||||
@property(nonatomic) NSNumber* rating;
|
||||
|
||||
@property(nonatomic) NSNumber* documentMetadataId;
|
||||
|
||||
- (id) hasScoredWords: (NSNumber*) hasScoredWords
|
||||
_id: (NSNumber*) _id
|
||||
scoredWords: (NSArray*) scoredWords
|
||||
display: (NSString*) display
|
||||
rating: (NSNumber*) rating
|
||||
documentMetadataId: (NSNumber*) documentMetadataId;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,87 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGSentence.h"
|
||||
|
||||
@implementation SWGSentence
|
||||
|
||||
-(id)hasScoredWords: (NSNumber*) hasScoredWords
|
||||
_id: (NSNumber*) _id
|
||||
scoredWords: (NSArray*) scoredWords
|
||||
display: (NSString*) display
|
||||
rating: (NSNumber*) rating
|
||||
documentMetadataId: (NSNumber*) documentMetadataId
|
||||
{
|
||||
_hasScoredWords = hasScoredWords;
|
||||
__id = _id;
|
||||
_scoredWords = scoredWords;
|
||||
_display = display;
|
||||
_rating = rating;
|
||||
_documentMetadataId = documentMetadataId;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_hasScoredWords = dict[@"hasScoredWords"];
|
||||
__id = dict[@"id"];
|
||||
id scoredWords_dict = dict[@"scoredWords"];
|
||||
if([scoredWords_dict isKindOfClass:[NSArray class]]) {
|
||||
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*)scoredWords_dict count]];
|
||||
|
||||
if([(NSArray*)scoredWords_dict count] > 0) {
|
||||
for (NSDictionary* dict in (NSArray*)scoredWords_dict) {
|
||||
SWGScoredWord* d = [[SWGScoredWord alloc] initWithValues:dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
|
||||
_scoredWords = [[NSArray alloc] initWithArray:objs];
|
||||
}
|
||||
else {
|
||||
_scoredWords = [[NSArray alloc] init];
|
||||
}
|
||||
}
|
||||
else {
|
||||
_scoredWords = [[NSArray alloc] init];
|
||||
}
|
||||
_display = dict[@"display"];
|
||||
_rating = dict[@"rating"];
|
||||
_documentMetadataId = dict[@"documentMetadataId"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_hasScoredWords != nil) dict[@"hasScoredWords"] = _hasScoredWords ;
|
||||
if(__id != nil) dict[@"id"] = __id ;
|
||||
if(_scoredWords != nil){
|
||||
if([_scoredWords isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGScoredWord *scoredWords in (NSArray*)_scoredWords) {
|
||||
[array addObject:[(SWGObject*)scoredWords asDictionary]];
|
||||
}
|
||||
dict[@"scoredWords"] = array;
|
||||
}
|
||||
else if(_scoredWords && [_scoredWords isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_scoredWords toString];
|
||||
if(dateString){
|
||||
dict[@"scoredWords"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_scoredWords != nil) dict[@"scoredWords"] = [(SWGObject*)_scoredWords asDictionary];
|
||||
}
|
||||
}
|
||||
if(_display != nil) dict[@"display"] = _display ;
|
||||
if(_rating != nil) dict[@"rating"] = _rating ;
|
||||
if(_documentMetadataId != nil) dict[@"documentMetadataId"] = _documentMetadataId ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,25 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGSimpleDefinition : SWGObject
|
||||
|
||||
@property(nonatomic) NSString* text;
|
||||
|
||||
@property(nonatomic) NSString* source;
|
||||
|
||||
@property(nonatomic) NSString* note;
|
||||
|
||||
@property(nonatomic) NSString* partOfSpeech;
|
||||
|
||||
- (id) text: (NSString*) text
|
||||
source: (NSString*) source
|
||||
note: (NSString*) note
|
||||
partOfSpeech: (NSString*) partOfSpeech;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,43 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGSimpleDefinition.h"
|
||||
|
||||
@implementation SWGSimpleDefinition
|
||||
|
||||
-(id)text: (NSString*) text
|
||||
source: (NSString*) source
|
||||
note: (NSString*) note
|
||||
partOfSpeech: (NSString*) partOfSpeech
|
||||
{
|
||||
_text = text;
|
||||
_source = source;
|
||||
_note = note;
|
||||
_partOfSpeech = partOfSpeech;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_text = dict[@"text"];
|
||||
_source = dict[@"source"];
|
||||
_note = dict[@"note"];
|
||||
_partOfSpeech = dict[@"partOfSpeech"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_text != nil) dict[@"text"] = _text ;
|
||||
if(_source != nil) dict[@"source"] = _source ;
|
||||
if(_note != nil) dict[@"note"] = _note ;
|
||||
if(_partOfSpeech != nil) dict[@"partOfSpeech"] = _partOfSpeech ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,25 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGSimpleExample : SWGObject
|
||||
|
||||
@property(nonatomic) NSNumber* _id;
|
||||
|
||||
@property(nonatomic) NSString* title;
|
||||
|
||||
@property(nonatomic) NSString* text;
|
||||
|
||||
@property(nonatomic) NSString* url;
|
||||
|
||||
- (id) _id: (NSNumber*) _id
|
||||
title: (NSString*) title
|
||||
text: (NSString*) text
|
||||
url: (NSString*) url;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,43 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGSimpleExample.h"
|
||||
|
||||
@implementation SWGSimpleExample
|
||||
|
||||
-(id)_id: (NSNumber*) _id
|
||||
title: (NSString*) title
|
||||
text: (NSString*) text
|
||||
url: (NSString*) url
|
||||
{
|
||||
__id = _id;
|
||||
_title = title;
|
||||
_text = text;
|
||||
_url = url;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
__id = dict[@"id"];
|
||||
_title = dict[@"title"];
|
||||
_text = dict[@"text"];
|
||||
_url = dict[@"url"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(__id != nil) dict[@"id"] = __id ;
|
||||
if(_title != nil) dict[@"title"] = _title ;
|
||||
if(_text != nil) dict[@"text"] = _text ;
|
||||
if(_url != nil) dict[@"url"] = _url ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,16 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGStringValue : SWGObject
|
||||
|
||||
@property(nonatomic) NSString* word;
|
||||
|
||||
- (id) word: (NSString*) word;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,31 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGStringValue.h"
|
||||
|
||||
@implementation SWGStringValue
|
||||
|
||||
-(id)word: (NSString*) word
|
||||
{
|
||||
_word = word;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_word = dict[@"word"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_word != nil) dict[@"word"] = _word ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,22 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGSyllable : SWGObject
|
||||
|
||||
@property(nonatomic) NSString* text;
|
||||
|
||||
@property(nonatomic) NSNumber* seq;
|
||||
|
||||
@property(nonatomic) NSString* type;
|
||||
|
||||
- (id) text: (NSString*) text
|
||||
seq: (NSNumber*) seq
|
||||
type: (NSString*) type;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,39 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGSyllable.h"
|
||||
|
||||
@implementation SWGSyllable
|
||||
|
||||
-(id)text: (NSString*) text
|
||||
seq: (NSNumber*) seq
|
||||
type: (NSString*) type
|
||||
{
|
||||
_text = text;
|
||||
_seq = seq;
|
||||
_type = type;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_text = dict[@"text"];
|
||||
_seq = dict[@"seq"];
|
||||
_type = dict[@"type"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_text != nil) dict[@"text"] = _text ;
|
||||
if(_seq != nil) dict[@"seq"] = _seq ;
|
||||
if(_type != nil) dict[@"type"] = _type ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,22 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGTextPron : SWGObject
|
||||
|
||||
@property(nonatomic) NSString* raw;
|
||||
|
||||
@property(nonatomic) NSNumber* seq;
|
||||
|
||||
@property(nonatomic) NSString* rawType;
|
||||
|
||||
- (id) raw: (NSString*) raw
|
||||
seq: (NSNumber*) seq
|
||||
rawType: (NSString*) rawType;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,39 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGTextPron.h"
|
||||
|
||||
@implementation SWGTextPron
|
||||
|
||||
-(id)raw: (NSString*) raw
|
||||
seq: (NSNumber*) seq
|
||||
rawType: (NSString*) rawType
|
||||
{
|
||||
_raw = raw;
|
||||
_seq = seq;
|
||||
_rawType = rawType;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_raw = dict[@"raw"];
|
||||
_seq = dict[@"seq"];
|
||||
_rawType = dict[@"rawType"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_raw != nil) dict[@"raw"] = _raw ;
|
||||
if(_seq != nil) dict[@"seq"] = _seq ;
|
||||
if(_rawType != nil) dict[@"rawType"] = _rawType ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,37 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGUser : SWGObject
|
||||
|
||||
@property(nonatomic) NSNumber* _id;
|
||||
|
||||
@property(nonatomic) NSString* username;
|
||||
|
||||
@property(nonatomic) NSString* email;
|
||||
|
||||
@property(nonatomic) NSNumber* status;
|
||||
|
||||
@property(nonatomic) NSString* faceBookId;
|
||||
|
||||
@property(nonatomic) NSString* userName;
|
||||
|
||||
@property(nonatomic) NSString* displayName;
|
||||
|
||||
@property(nonatomic) NSString* password;
|
||||
|
||||
- (id) _id: (NSNumber*) _id
|
||||
username: (NSString*) username
|
||||
email: (NSString*) email
|
||||
status: (NSNumber*) status
|
||||
faceBookId: (NSString*) faceBookId
|
||||
userName: (NSString*) userName
|
||||
displayName: (NSString*) displayName
|
||||
password: (NSString*) password;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,59 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGUser.h"
|
||||
|
||||
@implementation SWGUser
|
||||
|
||||
-(id)_id: (NSNumber*) _id
|
||||
username: (NSString*) username
|
||||
email: (NSString*) email
|
||||
status: (NSNumber*) status
|
||||
faceBookId: (NSString*) faceBookId
|
||||
userName: (NSString*) userName
|
||||
displayName: (NSString*) displayName
|
||||
password: (NSString*) password
|
||||
{
|
||||
__id = _id;
|
||||
_username = username;
|
||||
_email = email;
|
||||
_status = status;
|
||||
_faceBookId = faceBookId;
|
||||
_userName = userName;
|
||||
_displayName = displayName;
|
||||
_password = password;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
__id = dict[@"id"];
|
||||
_username = dict[@"username"];
|
||||
_email = dict[@"email"];
|
||||
_status = dict[@"status"];
|
||||
_faceBookId = dict[@"faceBookId"];
|
||||
_userName = dict[@"userName"];
|
||||
_displayName = dict[@"displayName"];
|
||||
_password = dict[@"password"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(__id != nil) dict[@"id"] = __id ;
|
||||
if(_username != nil) dict[@"username"] = _username ;
|
||||
if(_email != nil) dict[@"email"] = _email ;
|
||||
if(_status != nil) dict[@"status"] = _status ;
|
||||
if(_faceBookId != nil) dict[@"faceBookId"] = _faceBookId ;
|
||||
if(_userName != nil) dict[@"userName"] = _userName ;
|
||||
if(_displayName != nil) dict[@"displayName"] = _displayName ;
|
||||
if(_password != nil) dict[@"password"] = _password ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,195 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGFrequencySummary.h"
|
||||
#import "SWGBigram.h"
|
||||
#import "SWGWordObject.h"
|
||||
#import "SWGExampleSearchResults.h"
|
||||
#import "SWGExample.h"
|
||||
#import "SWGScrabbleScoreResult.h"
|
||||
#import "SWGTextPron.h"
|
||||
#import "SWGSyllable.h"
|
||||
#import "SWGRelated.h"
|
||||
#import "SWGDefinition.h"
|
||||
#import "SWGAudioFile.h"
|
||||
|
||||
|
||||
|
||||
@interface SWGWordApi: NSObject
|
||||
|
||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
|
||||
-(unsigned long) requestQueueSize;
|
||||
+(SWGWordApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
||||
+(void) setBasePath:(NSString*)basePath;
|
||||
+(NSString*) getBasePath;
|
||||
/**
|
||||
|
||||
Returns examples for a word
|
||||
|
||||
@param word Word to return examples for
|
||||
@param includeDuplicates Show duplicate examples from different sources
|
||||
@param useCanonical If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
@param skip Results to skip
|
||||
@param limit Maximum number of results to return
|
||||
*/
|
||||
-(NSNumber*) getExamplesWithCompletionBlock :(NSString*) word
|
||||
includeDuplicates:(NSString*) includeDuplicates
|
||||
useCanonical:(NSString*) useCanonical
|
||||
skip:(NSNumber*) skip
|
||||
limit:(NSNumber*) limit
|
||||
completionHandler: (void (^)(SWGExampleSearchResults* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Given a word as a string, returns the WordObject that represents it
|
||||
|
||||
@param word String value of WordObject to return
|
||||
@param useCanonical If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
@param includeSuggestions Return suggestions (for correct spelling, case variants, etc.)
|
||||
*/
|
||||
-(NSNumber*) getWordWithCompletionBlock :(NSString*) word
|
||||
useCanonical:(NSString*) useCanonical
|
||||
includeSuggestions:(NSString*) includeSuggestions
|
||||
completionHandler: (void (^)(SWGWordObject* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Return definitions for a word
|
||||
|
||||
@param word Word to return definitions for
|
||||
@param partOfSpeech CSV list of part-of-speech types
|
||||
@param sourceDictionaries Source dictionary to return definitions from. If 'all' is received, results are returned from all sources. If multiple values are received (e.g. 'century,wiktionary'), results are returned from the first specified dictionary that has definitions. If left blank, results are returned from the first dictionary that has definitions. By default, dictionaries are searched in this order: ahd, wiktionary, webster, century, wordnet
|
||||
@param limit Maximum number of results to return
|
||||
@param includeRelated Return related words with definitions
|
||||
@param useCanonical If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
@param includeTags Return a closed set of XML tags in response
|
||||
*/
|
||||
-(NSNumber*) getDefinitionsWithCompletionBlock :(NSString*) word
|
||||
partOfSpeech:(NSString*) partOfSpeech
|
||||
sourceDictionaries:(NSString*) sourceDictionaries
|
||||
limit:(NSNumber*) limit
|
||||
includeRelated:(NSString*) includeRelated
|
||||
useCanonical:(NSString*) useCanonical
|
||||
includeTags:(NSString*) includeTags
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Returns a top example for a word
|
||||
|
||||
@param word Word to fetch examples for
|
||||
@param useCanonical If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
*/
|
||||
-(NSNumber*) getTopExampleWithCompletionBlock :(NSString*) word
|
||||
useCanonical:(NSString*) useCanonical
|
||||
completionHandler: (void (^)(SWGExample* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Given a word as a string, returns relationships from the Word Graph
|
||||
|
||||
@param word Word to fetch relationships for
|
||||
@param relationshipTypes Limits the total results per type of relationship type
|
||||
@param useCanonical If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
@param limitPerRelationshipType Restrict to the supplied relatinship types
|
||||
*/
|
||||
-(NSNumber*) getRelatedWordsWithCompletionBlock :(NSString*) word
|
||||
relationshipTypes:(NSString*) relationshipTypes
|
||||
useCanonical:(NSString*) useCanonical
|
||||
limitPerRelationshipType:(NSNumber*) limitPerRelationshipType
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Returns text pronunciations for a given word
|
||||
|
||||
@param word Word to get pronunciations for
|
||||
@param sourceDictionary Get from a single dictionary
|
||||
@param typeFormat Text pronunciation type
|
||||
@param useCanonical If true will try to return a correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
@param limit Maximum number of results to return
|
||||
*/
|
||||
-(NSNumber*) getTextPronunciationsWithCompletionBlock :(NSString*) word
|
||||
sourceDictionary:(NSString*) sourceDictionary
|
||||
typeFormat:(NSString*) typeFormat
|
||||
useCanonical:(NSString*) useCanonical
|
||||
limit:(NSNumber*) limit
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Returns syllable information for a word
|
||||
|
||||
@param word Word to get syllables for
|
||||
@param sourceDictionary Get from a single dictionary. Valid options: ahd, century, wiktionary, webster, and wordnet.
|
||||
@param useCanonical If true will try to return a correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
@param limit Maximum number of results to return
|
||||
*/
|
||||
-(NSNumber*) getHyphenationWithCompletionBlock :(NSString*) word
|
||||
sourceDictionary:(NSString*) sourceDictionary
|
||||
useCanonical:(NSString*) useCanonical
|
||||
limit:(NSNumber*) limit
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Returns word usage over time
|
||||
|
||||
@param word Word to return
|
||||
@param useCanonical If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
@param startYear Starting Year
|
||||
@param endYear Ending Year
|
||||
*/
|
||||
-(NSNumber*) getWordFrequencyWithCompletionBlock :(NSString*) word
|
||||
useCanonical:(NSString*) useCanonical
|
||||
startYear:(NSNumber*) startYear
|
||||
endYear:(NSNumber*) endYear
|
||||
completionHandler: (void (^)(SWGFrequencySummary* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Fetches bi-gram phrases for a word
|
||||
|
||||
@param word Word to fetch phrases for
|
||||
@param limit Maximum number of results to return
|
||||
@param wlmi Minimum WLMI for the phrase
|
||||
@param useCanonical If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
*/
|
||||
-(NSNumber*) getPhrasesWithCompletionBlock :(NSString*) word
|
||||
limit:(NSNumber*) limit
|
||||
wlmi:(NSNumber*) wlmi
|
||||
useCanonical:(NSString*) useCanonical
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Fetches etymology data
|
||||
|
||||
@param word Word to return
|
||||
@param useCanonical If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
*/
|
||||
-(NSNumber*) getEtymologiesWithCompletionBlock :(NSString*) word
|
||||
useCanonical:(NSString*) useCanonical
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Fetches audio metadata for a word.
|
||||
The metadata includes a time-expiring fileUrl which allows reading the audio file directly from the API. Currently only audio pronunciations from the American Heritage Dictionary in mp3 format are supported.
|
||||
@param word Word to get audio for.
|
||||
@param useCanonical Use the canonical form of the word
|
||||
@param limit Maximum number of results to return
|
||||
*/
|
||||
-(NSNumber*) getAudioWithCompletionBlock :(NSString*) word
|
||||
useCanonical:(NSString*) useCanonical
|
||||
limit:(NSNumber*) limit
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Returns the Scrabble score for a word
|
||||
|
||||
@param word Word to get scrabble score for.
|
||||
*/
|
||||
-(NSNumber*) getScrabbleScoreWithCompletionBlock :(NSString*) word
|
||||
completionHandler: (void (^)(SWGScrabbleScoreResult* output, NSError* error))completionBlock;
|
||||
|
||||
@end
|
@ -1,691 +0,0 @@
|
||||
#import "SWGWordApi.h"
|
||||
#import "SWGFile.h"
|
||||
#import "SWGApiClient.h"
|
||||
#import "SWGFrequencySummary.h"
|
||||
#import "SWGBigram.h"
|
||||
#import "SWGWordObject.h"
|
||||
#import "SWGExampleSearchResults.h"
|
||||
#import "SWGExample.h"
|
||||
#import "SWGScrabbleScoreResult.h"
|
||||
#import "SWGTextPron.h"
|
||||
#import "SWGSyllable.h"
|
||||
#import "SWGRelated.h"
|
||||
#import "SWGDefinition.h"
|
||||
#import "SWGAudioFile.h"
|
||||
|
||||
|
||||
|
||||
|
||||
@implementation SWGWordApi
|
||||
static NSString * basePath = @"http://api.wordnik.com/v4";
|
||||
|
||||
+(SWGWordApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key {
|
||||
static SWGWordApi* singletonAPI = nil;
|
||||
|
||||
if (singletonAPI == nil) {
|
||||
singletonAPI = [[SWGWordApi alloc] init];
|
||||
[singletonAPI addHeader:headerValue forKey:key];
|
||||
}
|
||||
return singletonAPI;
|
||||
}
|
||||
|
||||
+(void) setBasePath:(NSString*)path {
|
||||
basePath = path;
|
||||
}
|
||||
|
||||
+(NSString*) getBasePath {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
-(SWGApiClient*) apiClient {
|
||||
return [SWGApiClient sharedClientFromPool:basePath];
|
||||
}
|
||||
|
||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
|
||||
[[self apiClient] setHeaderValue:value forKey:key];
|
||||
}
|
||||
|
||||
-(id) init {
|
||||
self = [super init];
|
||||
[self apiClient];
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void) setHeaderValue:(NSString*) value
|
||||
forKey:(NSString*)key {
|
||||
[[self apiClient] setHeaderValue:value forKey:key];
|
||||
}
|
||||
|
||||
-(unsigned long) requestQueueSize {
|
||||
return [SWGApiClient requestQueueSize];
|
||||
}
|
||||
|
||||
|
||||
-(NSNumber*) getExamplesWithCompletionBlock:(NSString*) word
|
||||
includeDuplicates:(NSString*) includeDuplicates
|
||||
useCanonical:(NSString*) useCanonical
|
||||
skip:(NSNumber*) skip
|
||||
limit:(NSNumber*) limit
|
||||
completionHandler: (void (^)(SWGExampleSearchResults* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/word.{format}/{word}/examples", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"word", @"}"]] withString: [SWGApiClient escape:word]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(includeDuplicates != nil)
|
||||
queryParams[@"includeDuplicates"] = includeDuplicates;
|
||||
if(useCanonical != nil)
|
||||
queryParams[@"useCanonical"] = useCanonical;
|
||||
if(skip != nil)
|
||||
queryParams[@"skip"] = skip;
|
||||
if(limit != nil)
|
||||
queryParams[@"limit"] = limit;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
if(word == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary:requestUrl
|
||||
method:@"GET"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType:requestContentType
|
||||
responseContentType:responseContentType
|
||||
completionBlock:^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
SWGExampleSearchResults *result = nil;
|
||||
if (data) {
|
||||
result = [[SWGExampleSearchResults alloc]initWithValues: data];
|
||||
}
|
||||
completionBlock(result , nil);}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getWordWithCompletionBlock:(NSString*) word
|
||||
useCanonical:(NSString*) useCanonical
|
||||
includeSuggestions:(NSString*) includeSuggestions
|
||||
completionHandler: (void (^)(SWGWordObject* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/word.{format}/{word}", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"word", @"}"]] withString: [SWGApiClient escape:word]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(useCanonical != nil)
|
||||
queryParams[@"useCanonical"] = useCanonical;
|
||||
if(includeSuggestions != nil)
|
||||
queryParams[@"includeSuggestions"] = includeSuggestions;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
if(word == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary:requestUrl
|
||||
method:@"GET"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType:requestContentType
|
||||
responseContentType:responseContentType
|
||||
completionBlock:^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
SWGWordObject *result = nil;
|
||||
if (data) {
|
||||
result = [[SWGWordObject alloc]initWithValues: data];
|
||||
}
|
||||
completionBlock(result , nil);}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getDefinitionsWithCompletionBlock:(NSString*) word
|
||||
partOfSpeech:(NSString*) partOfSpeech
|
||||
sourceDictionaries:(NSString*) sourceDictionaries
|
||||
limit:(NSNumber*) limit
|
||||
includeRelated:(NSString*) includeRelated
|
||||
useCanonical:(NSString*) useCanonical
|
||||
includeTags:(NSString*) includeTags
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/word.{format}/{word}/definitions", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"word", @"}"]] withString: [SWGApiClient escape:word]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(limit != nil)
|
||||
queryParams[@"limit"] = limit;
|
||||
if(partOfSpeech != nil)
|
||||
queryParams[@"partOfSpeech"] = partOfSpeech;
|
||||
if(includeRelated != nil)
|
||||
queryParams[@"includeRelated"] = includeRelated;
|
||||
if(sourceDictionaries != nil)
|
||||
queryParams[@"sourceDictionaries"] = sourceDictionaries;
|
||||
if(useCanonical != nil)
|
||||
queryParams[@"useCanonical"] = useCanonical;
|
||||
if(includeTags != nil)
|
||||
queryParams[@"includeTags"] = includeTags;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
if(word == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary: requestUrl
|
||||
method: @"GET"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
|
||||
if([data isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]];
|
||||
for (NSDictionary* dict in (NSArray*)data) {
|
||||
SWGDefinition* d = [[SWGDefinition alloc]initWithValues: dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
completionBlock(objs, nil);
|
||||
}
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getTopExampleWithCompletionBlock:(NSString*) word
|
||||
useCanonical:(NSString*) useCanonical
|
||||
completionHandler: (void (^)(SWGExample* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/word.{format}/{word}/topExample", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"word", @"}"]] withString: [SWGApiClient escape:word]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(useCanonical != nil)
|
||||
queryParams[@"useCanonical"] = useCanonical;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
if(word == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary:requestUrl
|
||||
method:@"GET"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType:requestContentType
|
||||
responseContentType:responseContentType
|
||||
completionBlock:^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
SWGExample *result = nil;
|
||||
if (data) {
|
||||
result = [[SWGExample alloc]initWithValues: data];
|
||||
}
|
||||
completionBlock(result , nil);}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getRelatedWordsWithCompletionBlock:(NSString*) word
|
||||
relationshipTypes:(NSString*) relationshipTypes
|
||||
useCanonical:(NSString*) useCanonical
|
||||
limitPerRelationshipType:(NSNumber*) limitPerRelationshipType
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/word.{format}/{word}/relatedWords", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"word", @"}"]] withString: [SWGApiClient escape:word]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(useCanonical != nil)
|
||||
queryParams[@"useCanonical"] = useCanonical;
|
||||
if(relationshipTypes != nil)
|
||||
queryParams[@"relationshipTypes"] = relationshipTypes;
|
||||
if(limitPerRelationshipType != nil)
|
||||
queryParams[@"limitPerRelationshipType"] = limitPerRelationshipType;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
if(word == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary: requestUrl
|
||||
method: @"GET"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
|
||||
if([data isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]];
|
||||
for (NSDictionary* dict in (NSArray*)data) {
|
||||
SWGRelated* d = [[SWGRelated alloc]initWithValues: dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
completionBlock(objs, nil);
|
||||
}
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getTextPronunciationsWithCompletionBlock:(NSString*) word
|
||||
sourceDictionary:(NSString*) sourceDictionary
|
||||
typeFormat:(NSString*) typeFormat
|
||||
useCanonical:(NSString*) useCanonical
|
||||
limit:(NSNumber*) limit
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/word.{format}/{word}/pronunciations", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"word", @"}"]] withString: [SWGApiClient escape:word]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(useCanonical != nil)
|
||||
queryParams[@"useCanonical"] = useCanonical;
|
||||
if(sourceDictionary != nil)
|
||||
queryParams[@"sourceDictionary"] = sourceDictionary;
|
||||
if(typeFormat != nil)
|
||||
queryParams[@"typeFormat"] = typeFormat;
|
||||
if(limit != nil)
|
||||
queryParams[@"limit"] = limit;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
if(word == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary: requestUrl
|
||||
method: @"GET"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
|
||||
if([data isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]];
|
||||
for (NSDictionary* dict in (NSArray*)data) {
|
||||
SWGTextPron* d = [[SWGTextPron alloc]initWithValues: dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
completionBlock(objs, nil);
|
||||
}
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getHyphenationWithCompletionBlock:(NSString*) word
|
||||
sourceDictionary:(NSString*) sourceDictionary
|
||||
useCanonical:(NSString*) useCanonical
|
||||
limit:(NSNumber*) limit
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/word.{format}/{word}/hyphenation", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"word", @"}"]] withString: [SWGApiClient escape:word]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(useCanonical != nil)
|
||||
queryParams[@"useCanonical"] = useCanonical;
|
||||
if(sourceDictionary != nil)
|
||||
queryParams[@"sourceDictionary"] = sourceDictionary;
|
||||
if(limit != nil)
|
||||
queryParams[@"limit"] = limit;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
if(word == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary: requestUrl
|
||||
method: @"GET"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
|
||||
if([data isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]];
|
||||
for (NSDictionary* dict in (NSArray*)data) {
|
||||
SWGSyllable* d = [[SWGSyllable alloc]initWithValues: dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
completionBlock(objs, nil);
|
||||
}
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getWordFrequencyWithCompletionBlock:(NSString*) word
|
||||
useCanonical:(NSString*) useCanonical
|
||||
startYear:(NSNumber*) startYear
|
||||
endYear:(NSNumber*) endYear
|
||||
completionHandler: (void (^)(SWGFrequencySummary* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/word.{format}/{word}/frequency", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"word", @"}"]] withString: [SWGApiClient escape:word]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(useCanonical != nil)
|
||||
queryParams[@"useCanonical"] = useCanonical;
|
||||
if(startYear != nil)
|
||||
queryParams[@"startYear"] = startYear;
|
||||
if(endYear != nil)
|
||||
queryParams[@"endYear"] = endYear;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
if(word == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary:requestUrl
|
||||
method:@"GET"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType:requestContentType
|
||||
responseContentType:responseContentType
|
||||
completionBlock:^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
SWGFrequencySummary *result = nil;
|
||||
if (data) {
|
||||
result = [[SWGFrequencySummary alloc]initWithValues: data];
|
||||
}
|
||||
completionBlock(result , nil);}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getPhrasesWithCompletionBlock:(NSString*) word
|
||||
limit:(NSNumber*) limit
|
||||
wlmi:(NSNumber*) wlmi
|
||||
useCanonical:(NSString*) useCanonical
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/word.{format}/{word}/phrases", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"word", @"}"]] withString: [SWGApiClient escape:word]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(limit != nil)
|
||||
queryParams[@"limit"] = limit;
|
||||
if(wlmi != nil)
|
||||
queryParams[@"wlmi"] = wlmi;
|
||||
if(useCanonical != nil)
|
||||
queryParams[@"useCanonical"] = useCanonical;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
if(word == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary: requestUrl
|
||||
method: @"GET"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
|
||||
if([data isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]];
|
||||
for (NSDictionary* dict in (NSArray*)data) {
|
||||
SWGBigram* d = [[SWGBigram alloc]initWithValues: dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
completionBlock(objs, nil);
|
||||
}
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getEtymologiesWithCompletionBlock:(NSString*) word
|
||||
useCanonical:(NSString*) useCanonical
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/word.{format}/{word}/etymologies", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"word", @"}"]] withString: [SWGApiClient escape:word]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(useCanonical != nil)
|
||||
queryParams[@"useCanonical"] = useCanonical;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
if(word == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary: requestUrl
|
||||
method: @"GET"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
|
||||
if([data isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]];
|
||||
for (NSDictionary* dict in (NSArray*)data) {
|
||||
// NSString
|
||||
|
||||
NSString* d = [[NSString alloc]initWithString: data];
|
||||
[objs addObject:d];
|
||||
}
|
||||
completionBlock(objs, nil);
|
||||
}
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getAudioWithCompletionBlock:(NSString*) word
|
||||
useCanonical:(NSString*) useCanonical
|
||||
limit:(NSNumber*) limit
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/word.{format}/{word}/audio", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"word", @"}"]] withString: [SWGApiClient escape:word]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(useCanonical != nil)
|
||||
queryParams[@"useCanonical"] = useCanonical;
|
||||
if(limit != nil)
|
||||
queryParams[@"limit"] = limit;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
if(word == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary: requestUrl
|
||||
method: @"GET"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
|
||||
if([data isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]];
|
||||
for (NSDictionary* dict in (NSArray*)data) {
|
||||
SWGAudioFile* d = [[SWGAudioFile alloc]initWithValues: dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
completionBlock(objs, nil);
|
||||
}
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getScrabbleScoreWithCompletionBlock:(NSString*) word
|
||||
completionHandler: (void (^)(SWGScrabbleScoreResult* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/word.{format}/{word}/scrabbleScore", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"word", @"}"]] withString: [SWGApiClient escape:word]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
if(word == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary:requestUrl
|
||||
method:@"GET"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType:requestContentType
|
||||
responseContentType:responseContentType
|
||||
completionBlock:^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
SWGScrabbleScoreResult *result = nil;
|
||||
if (data) {
|
||||
result = [[SWGScrabbleScoreResult alloc]initWithValues: data];
|
||||
}
|
||||
completionBlock(result , nil);}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
@ -1,47 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
#import "SWGDate.h"
|
||||
|
||||
|
||||
@interface SWGWordList : SWGObject
|
||||
|
||||
@property(nonatomic) NSNumber* _id;
|
||||
|
||||
@property(nonatomic) NSString* permalink;
|
||||
|
||||
@property(nonatomic) NSString* name;
|
||||
|
||||
@property(nonatomic) SWGDate* createdAt;
|
||||
|
||||
@property(nonatomic) SWGDate* updatedAt;
|
||||
|
||||
@property(nonatomic) SWGDate* lastActivityAt;
|
||||
|
||||
@property(nonatomic) NSString* username;
|
||||
|
||||
@property(nonatomic) NSNumber* userId;
|
||||
|
||||
@property(nonatomic) NSString* description;
|
||||
|
||||
@property(nonatomic) NSNumber* numberWordsInList;
|
||||
|
||||
@property(nonatomic) NSString* type;
|
||||
|
||||
- (id) _id: (NSNumber*) _id
|
||||
permalink: (NSString*) permalink
|
||||
name: (NSString*) name
|
||||
createdAt: (SWGDate*) createdAt
|
||||
updatedAt: (SWGDate*) updatedAt
|
||||
lastActivityAt: (SWGDate*) lastActivityAt
|
||||
username: (NSString*) username
|
||||
userId: (NSNumber*) userId
|
||||
description: (NSString*) description
|
||||
numberWordsInList: (NSNumber*) numberWordsInList
|
||||
type: (NSString*) type;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,128 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGWordList.h"
|
||||
|
||||
@implementation SWGWordList
|
||||
|
||||
-(id)_id: (NSNumber*) _id
|
||||
permalink: (NSString*) permalink
|
||||
name: (NSString*) name
|
||||
createdAt: (SWGDate*) createdAt
|
||||
updatedAt: (SWGDate*) updatedAt
|
||||
lastActivityAt: (SWGDate*) lastActivityAt
|
||||
username: (NSString*) username
|
||||
userId: (NSNumber*) userId
|
||||
description: (NSString*) description
|
||||
numberWordsInList: (NSNumber*) numberWordsInList
|
||||
type: (NSString*) type
|
||||
{
|
||||
__id = _id;
|
||||
_permalink = permalink;
|
||||
_name = name;
|
||||
_createdAt = createdAt;
|
||||
_updatedAt = updatedAt;
|
||||
_lastActivityAt = lastActivityAt;
|
||||
_username = username;
|
||||
_userId = userId;
|
||||
_description = description;
|
||||
_numberWordsInList = numberWordsInList;
|
||||
_type = type;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
__id = dict[@"id"];
|
||||
_permalink = dict[@"permalink"];
|
||||
_name = dict[@"name"];
|
||||
id createdAt_dict = dict[@"createdAt"];
|
||||
if(createdAt_dict != nil)
|
||||
_createdAt = [[SWGDate alloc]initWithValues:createdAt_dict];
|
||||
id updatedAt_dict = dict[@"updatedAt"];
|
||||
if(updatedAt_dict != nil)
|
||||
_updatedAt = [[SWGDate alloc]initWithValues:updatedAt_dict];
|
||||
id lastActivityAt_dict = dict[@"lastActivityAt"];
|
||||
if(lastActivityAt_dict != nil)
|
||||
_lastActivityAt = [[SWGDate alloc]initWithValues:lastActivityAt_dict];
|
||||
_username = dict[@"username"];
|
||||
_userId = dict[@"userId"];
|
||||
_description = dict[@"description"];
|
||||
_numberWordsInList = dict[@"numberWordsInList"];
|
||||
_type = dict[@"type"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(__id != nil) dict[@"id"] = __id ;
|
||||
if(_permalink != nil) dict[@"permalink"] = _permalink ;
|
||||
if(_name != nil) dict[@"name"] = _name ;
|
||||
if(_createdAt != nil){
|
||||
if([_createdAt isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGDate *createdAt in (NSArray*)_createdAt) {
|
||||
[array addObject:[(SWGObject*)createdAt asDictionary]];
|
||||
}
|
||||
dict[@"createdAt"] = array;
|
||||
}
|
||||
else if(_createdAt && [_createdAt isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_createdAt toString];
|
||||
if(dateString){
|
||||
dict[@"createdAt"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_createdAt != nil) dict[@"createdAt"] = [(SWGObject*)_createdAt asDictionary];
|
||||
}
|
||||
}
|
||||
if(_updatedAt != nil){
|
||||
if([_updatedAt isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGDate *updatedAt in (NSArray*)_updatedAt) {
|
||||
[array addObject:[(SWGObject*)updatedAt asDictionary]];
|
||||
}
|
||||
dict[@"updatedAt"] = array;
|
||||
}
|
||||
else if(_updatedAt && [_updatedAt isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_updatedAt toString];
|
||||
if(dateString){
|
||||
dict[@"updatedAt"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_updatedAt != nil) dict[@"updatedAt"] = [(SWGObject*)_updatedAt asDictionary];
|
||||
}
|
||||
}
|
||||
if(_lastActivityAt != nil){
|
||||
if([_lastActivityAt isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGDate *lastActivityAt in (NSArray*)_lastActivityAt) {
|
||||
[array addObject:[(SWGObject*)lastActivityAt asDictionary]];
|
||||
}
|
||||
dict[@"lastActivityAt"] = array;
|
||||
}
|
||||
else if(_lastActivityAt && [_lastActivityAt isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_lastActivityAt toString];
|
||||
if(dateString){
|
||||
dict[@"lastActivityAt"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_lastActivityAt != nil) dict[@"lastActivityAt"] = [(SWGObject*)_lastActivityAt asDictionary];
|
||||
}
|
||||
}
|
||||
if(_username != nil) dict[@"username"] = _username ;
|
||||
if(_userId != nil) dict[@"userId"] = _userId ;
|
||||
if(_description != nil) dict[@"description"] = _description ;
|
||||
if(_numberWordsInList != nil) dict[@"numberWordsInList"] = _numberWordsInList ;
|
||||
if(_type != nil) dict[@"type"] = _type ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,95 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGWordListWord.h"
|
||||
#import "SWGWordList.h"
|
||||
#import "SWGStringValue.h"
|
||||
|
||||
|
||||
|
||||
@interface SWGWordListApi: NSObject
|
||||
|
||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
|
||||
-(unsigned long) requestQueueSize;
|
||||
+(SWGWordListApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
||||
+(void) setBasePath:(NSString*)basePath;
|
||||
+(NSString*) getBasePath;
|
||||
/**
|
||||
|
||||
Updates an existing WordList
|
||||
|
||||
@param permalink permalink of WordList to update
|
||||
@param body Updated WordList
|
||||
@param auth_token The auth token of the logged-in user, obtained by calling /account.{format}/authenticate/{username} (described above)
|
||||
*/
|
||||
-(NSNumber*) updateWordListWithCompletionBlock :(NSString*) permalink
|
||||
body:(SWGWordList*) body
|
||||
auth_token:(NSString*) auth_token
|
||||
completionHandler: (void (^)(NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Deletes an existing WordList
|
||||
|
||||
@param permalink ID of WordList to delete
|
||||
@param auth_token The auth token of the logged-in user, obtained by calling /account.{format}/authenticate/{username} (described above)
|
||||
*/
|
||||
-(NSNumber*) deleteWordListWithCompletionBlock :(NSString*) permalink
|
||||
auth_token:(NSString*) auth_token
|
||||
completionHandler: (void (^)(NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Fetches a WordList by ID
|
||||
|
||||
@param permalink permalink of WordList to fetch
|
||||
@param auth_token The auth token of the logged-in user, obtained by calling /account.{format}/authenticate/{username} (described above)
|
||||
*/
|
||||
-(NSNumber*) getWordListByPermalinkWithCompletionBlock :(NSString*) permalink
|
||||
auth_token:(NSString*) auth_token
|
||||
completionHandler: (void (^)(SWGWordList* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Adds words to a WordList
|
||||
|
||||
@param permalink permalink of WordList to user
|
||||
@param body Array of words to add to WordList
|
||||
@param auth_token The auth token of the logged-in user, obtained by calling /account.{format}/authenticate/{username} (described above)
|
||||
*/
|
||||
-(NSNumber*) addWordsToWordListWithCompletionBlock :(NSString*) permalink
|
||||
body:(NSArray*) body
|
||||
auth_token:(NSString*) auth_token
|
||||
completionHandler: (void (^)(NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Fetches words in a WordList
|
||||
|
||||
@param permalink ID of WordList to use
|
||||
@param auth_token The auth token of the logged-in user, obtained by calling /account.{format}/authenticate/{username} (described above)
|
||||
@param sortBy Field to sort by
|
||||
@param sortOrder Direction to sort
|
||||
@param skip Results to skip
|
||||
@param limit Maximum number of results to return
|
||||
*/
|
||||
-(NSNumber*) getWordListWordsWithCompletionBlock :(NSString*) permalink
|
||||
auth_token:(NSString*) auth_token
|
||||
sortBy:(NSString*) sortBy
|
||||
sortOrder:(NSString*) sortOrder
|
||||
skip:(NSNumber*) skip
|
||||
limit:(NSNumber*) limit
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Removes words from a WordList
|
||||
|
||||
@param permalink permalink of WordList to use
|
||||
@param body Words to remove from WordList
|
||||
@param auth_token The auth token of the logged-in user, obtained by calling /account.{format}/authenticate/{username} (described above)
|
||||
*/
|
||||
-(NSNumber*) deleteWordsFromWordListWithCompletionBlock :(NSString*) permalink
|
||||
body:(NSArray*) body
|
||||
auth_token:(NSString*) auth_token
|
||||
completionHandler: (void (^)(NSError* error))completionBlock;
|
||||
|
||||
@end
|
@ -1,451 +0,0 @@
|
||||
#import "SWGWordListApi.h"
|
||||
#import "SWGFile.h"
|
||||
#import "SWGApiClient.h"
|
||||
#import "SWGWordListWord.h"
|
||||
#import "SWGWordList.h"
|
||||
#import "SWGStringValue.h"
|
||||
|
||||
|
||||
|
||||
|
||||
@implementation SWGWordListApi
|
||||
static NSString * basePath = @"http://api.wordnik.com/v4";
|
||||
|
||||
+(SWGWordListApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key {
|
||||
static SWGWordListApi* singletonAPI = nil;
|
||||
|
||||
if (singletonAPI == nil) {
|
||||
singletonAPI = [[SWGWordListApi alloc] init];
|
||||
[singletonAPI addHeader:headerValue forKey:key];
|
||||
}
|
||||
return singletonAPI;
|
||||
}
|
||||
|
||||
+(void) setBasePath:(NSString*)path {
|
||||
basePath = path;
|
||||
}
|
||||
|
||||
+(NSString*) getBasePath {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
-(SWGApiClient*) apiClient {
|
||||
return [SWGApiClient sharedClientFromPool:basePath];
|
||||
}
|
||||
|
||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
|
||||
[[self apiClient] setHeaderValue:value forKey:key];
|
||||
}
|
||||
|
||||
-(id) init {
|
||||
self = [super init];
|
||||
[self apiClient];
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void) setHeaderValue:(NSString*) value
|
||||
forKey:(NSString*)key {
|
||||
[[self apiClient] setHeaderValue:value forKey:key];
|
||||
}
|
||||
|
||||
-(unsigned long) requestQueueSize {
|
||||
return [SWGApiClient requestQueueSize];
|
||||
}
|
||||
|
||||
|
||||
-(NSNumber*) updateWordListWithCompletionBlock:(NSString*) permalink
|
||||
body:(SWGWordList*) body
|
||||
auth_token:(NSString*) auth_token
|
||||
completionHandler: (void (^)(NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/wordList.{format}/{permalink}", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"permalink", @"}"]] withString: [SWGApiClient escape:permalink]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
if(auth_token != nil)
|
||||
headerParams[@"auth_token"] = auth_token;
|
||||
id bodyDictionary = nil;
|
||||
if(body != nil && [body isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] init];
|
||||
for (id dict in (NSArray*)body) {
|
||||
if([dict respondsToSelector:@selector(asDictionary)]) {
|
||||
[objs addObject:[(SWGObject*)dict asDictionary]];
|
||||
}
|
||||
else{
|
||||
[objs addObject:dict];
|
||||
}
|
||||
}
|
||||
bodyDictionary = objs;
|
||||
}
|
||||
else if([body respondsToSelector:@selector(asDictionary)]) {
|
||||
bodyDictionary = [(SWGObject*)body asDictionary];
|
||||
}
|
||||
else if([body isKindOfClass:[NSString class]]) {
|
||||
// convert it to a dictionary
|
||||
NSError * error;
|
||||
NSString * str = (NSString*)body;
|
||||
NSDictionary *JSON =
|
||||
[NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding]
|
||||
options:NSJSONReadingMutableContainers
|
||||
error:&error];
|
||||
bodyDictionary = JSON;
|
||||
}
|
||||
else if([body isKindOfClass: [SWGFile class]]) {
|
||||
requestContentType = @"form-data";
|
||||
bodyDictionary = body;
|
||||
}
|
||||
else{
|
||||
NSLog(@"don't know what to do with %@", body);
|
||||
}
|
||||
|
||||
if(permalink == nil) {
|
||||
// error
|
||||
}
|
||||
if(auth_token == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client stringWithCompletionBlock:requestUrl
|
||||
method:@"PUT"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock:^(NSString *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(error);
|
||||
return;
|
||||
}
|
||||
completionBlock(nil);
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) deleteWordListWithCompletionBlock:(NSString*) permalink
|
||||
auth_token:(NSString*) auth_token
|
||||
completionHandler: (void (^)(NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/wordList.{format}/{permalink}", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"permalink", @"}"]] withString: [SWGApiClient escape:permalink]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
if(auth_token != nil)
|
||||
headerParams[@"auth_token"] = auth_token;
|
||||
id bodyDictionary = nil;
|
||||
if(permalink == nil) {
|
||||
// error
|
||||
}
|
||||
if(auth_token == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client stringWithCompletionBlock:requestUrl
|
||||
method:@"DELETE"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock:^(NSString *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(error);
|
||||
return;
|
||||
}
|
||||
completionBlock(nil);
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getWordListByPermalinkWithCompletionBlock:(NSString*) permalink
|
||||
auth_token:(NSString*) auth_token
|
||||
completionHandler: (void (^)(SWGWordList* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/wordList.{format}/{permalink}", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"permalink", @"}"]] withString: [SWGApiClient escape:permalink]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
if(auth_token != nil)
|
||||
headerParams[@"auth_token"] = auth_token;
|
||||
id bodyDictionary = nil;
|
||||
if(permalink == nil) {
|
||||
// error
|
||||
}
|
||||
if(auth_token == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary:requestUrl
|
||||
method:@"GET"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType:requestContentType
|
||||
responseContentType:responseContentType
|
||||
completionBlock:^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
SWGWordList *result = nil;
|
||||
if (data) {
|
||||
result = [[SWGWordList alloc]initWithValues: data];
|
||||
}
|
||||
completionBlock(result , nil);}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) addWordsToWordListWithCompletionBlock:(NSString*) permalink
|
||||
body:(NSArray*) body
|
||||
auth_token:(NSString*) auth_token
|
||||
completionHandler: (void (^)(NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/wordList.{format}/{permalink}/words", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"permalink", @"}"]] withString: [SWGApiClient escape:permalink]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
if(auth_token != nil)
|
||||
headerParams[@"auth_token"] = auth_token;
|
||||
id bodyDictionary = nil;
|
||||
if(body != nil && [body isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] init];
|
||||
for (id dict in (NSArray*)body) {
|
||||
if([dict respondsToSelector:@selector(asDictionary)]) {
|
||||
[objs addObject:[(SWGObject*)dict asDictionary]];
|
||||
}
|
||||
else{
|
||||
[objs addObject:dict];
|
||||
}
|
||||
}
|
||||
bodyDictionary = objs;
|
||||
}
|
||||
else if([body respondsToSelector:@selector(asDictionary)]) {
|
||||
bodyDictionary = [(SWGObject*)body asDictionary];
|
||||
}
|
||||
else if([body isKindOfClass:[NSString class]]) {
|
||||
// convert it to a dictionary
|
||||
NSError * error;
|
||||
NSString * str = (NSString*)body;
|
||||
NSDictionary *JSON =
|
||||
[NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding]
|
||||
options:NSJSONReadingMutableContainers
|
||||
error:&error];
|
||||
bodyDictionary = JSON;
|
||||
}
|
||||
else if([body isKindOfClass: [SWGFile class]]) {
|
||||
requestContentType = @"form-data";
|
||||
bodyDictionary = body;
|
||||
}
|
||||
else{
|
||||
NSLog(@"don't know what to do with %@", body);
|
||||
}
|
||||
|
||||
if(permalink == nil) {
|
||||
// error
|
||||
}
|
||||
if(auth_token == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client stringWithCompletionBlock:requestUrl
|
||||
method:@"POST"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock:^(NSString *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(error);
|
||||
return;
|
||||
}
|
||||
completionBlock(nil);
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getWordListWordsWithCompletionBlock:(NSString*) permalink
|
||||
auth_token:(NSString*) auth_token
|
||||
sortBy:(NSString*) sortBy
|
||||
sortOrder:(NSString*) sortOrder
|
||||
skip:(NSNumber*) skip
|
||||
limit:(NSNumber*) limit
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/wordList.{format}/{permalink}/words", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"permalink", @"}"]] withString: [SWGApiClient escape:permalink]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(sortBy != nil)
|
||||
queryParams[@"sortBy"] = sortBy;
|
||||
if(sortOrder != nil)
|
||||
queryParams[@"sortOrder"] = sortOrder;
|
||||
if(skip != nil)
|
||||
queryParams[@"skip"] = skip;
|
||||
if(limit != nil)
|
||||
queryParams[@"limit"] = limit;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
if(auth_token != nil)
|
||||
headerParams[@"auth_token"] = auth_token;
|
||||
id bodyDictionary = nil;
|
||||
if(permalink == nil) {
|
||||
// error
|
||||
}
|
||||
if(auth_token == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary: requestUrl
|
||||
method: @"GET"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
|
||||
if([data isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]];
|
||||
for (NSDictionary* dict in (NSArray*)data) {
|
||||
SWGWordListWord* d = [[SWGWordListWord alloc]initWithValues: dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
completionBlock(objs, nil);
|
||||
}
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) deleteWordsFromWordListWithCompletionBlock:(NSString*) permalink
|
||||
body:(NSArray*) body
|
||||
auth_token:(NSString*) auth_token
|
||||
completionHandler: (void (^)(NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/wordList.{format}/{permalink}/deleteWords", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"permalink", @"}"]] withString: [SWGApiClient escape:permalink]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
if(auth_token != nil)
|
||||
headerParams[@"auth_token"] = auth_token;
|
||||
id bodyDictionary = nil;
|
||||
if(body != nil && [body isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] init];
|
||||
for (id dict in (NSArray*)body) {
|
||||
if([dict respondsToSelector:@selector(asDictionary)]) {
|
||||
[objs addObject:[(SWGObject*)dict asDictionary]];
|
||||
}
|
||||
else{
|
||||
[objs addObject:dict];
|
||||
}
|
||||
}
|
||||
bodyDictionary = objs;
|
||||
}
|
||||
else if([body respondsToSelector:@selector(asDictionary)]) {
|
||||
bodyDictionary = [(SWGObject*)body asDictionary];
|
||||
}
|
||||
else if([body isKindOfClass:[NSString class]]) {
|
||||
// convert it to a dictionary
|
||||
NSError * error;
|
||||
NSString * str = (NSString*)body;
|
||||
NSDictionary *JSON =
|
||||
[NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding]
|
||||
options:NSJSONReadingMutableContainers
|
||||
error:&error];
|
||||
bodyDictionary = JSON;
|
||||
}
|
||||
else if([body isKindOfClass: [SWGFile class]]) {
|
||||
requestContentType = @"form-data";
|
||||
bodyDictionary = body;
|
||||
}
|
||||
else{
|
||||
NSLog(@"don't know what to do with %@", body);
|
||||
}
|
||||
|
||||
if(permalink == nil) {
|
||||
// error
|
||||
}
|
||||
if(auth_token == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client stringWithCompletionBlock:requestUrl
|
||||
method:@"POST"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock:^(NSString *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(error);
|
||||
return;
|
||||
}
|
||||
completionBlock(nil);
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
@ -1,35 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
#import "SWGDate.h"
|
||||
|
||||
|
||||
@interface SWGWordListWord : SWGObject
|
||||
|
||||
@property(nonatomic) NSNumber* _id;
|
||||
|
||||
@property(nonatomic) NSString* word;
|
||||
|
||||
@property(nonatomic) NSString* username;
|
||||
|
||||
@property(nonatomic) NSNumber* userId;
|
||||
|
||||
@property(nonatomic) SWGDate* createdAt;
|
||||
|
||||
@property(nonatomic) NSNumber* numberCommentsOnWord;
|
||||
|
||||
@property(nonatomic) NSNumber* numberLists;
|
||||
|
||||
- (id) _id: (NSNumber*) _id
|
||||
word: (NSString*) word
|
||||
username: (NSString*) username
|
||||
userId: (NSNumber*) userId
|
||||
createdAt: (SWGDate*) createdAt
|
||||
numberCommentsOnWord: (NSNumber*) numberCommentsOnWord
|
||||
numberLists: (NSNumber*) numberLists;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,74 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGWordListWord.h"
|
||||
|
||||
@implementation SWGWordListWord
|
||||
|
||||
-(id)_id: (NSNumber*) _id
|
||||
word: (NSString*) word
|
||||
username: (NSString*) username
|
||||
userId: (NSNumber*) userId
|
||||
createdAt: (SWGDate*) createdAt
|
||||
numberCommentsOnWord: (NSNumber*) numberCommentsOnWord
|
||||
numberLists: (NSNumber*) numberLists
|
||||
{
|
||||
__id = _id;
|
||||
_word = word;
|
||||
_username = username;
|
||||
_userId = userId;
|
||||
_createdAt = createdAt;
|
||||
_numberCommentsOnWord = numberCommentsOnWord;
|
||||
_numberLists = numberLists;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
__id = dict[@"id"];
|
||||
_word = dict[@"word"];
|
||||
_username = dict[@"username"];
|
||||
_userId = dict[@"userId"];
|
||||
id createdAt_dict = dict[@"createdAt"];
|
||||
if(createdAt_dict != nil)
|
||||
_createdAt = [[SWGDate alloc]initWithValues:createdAt_dict];
|
||||
_numberCommentsOnWord = dict[@"numberCommentsOnWord"];
|
||||
_numberLists = dict[@"numberLists"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(__id != nil) dict[@"id"] = __id ;
|
||||
if(_word != nil) dict[@"word"] = _word ;
|
||||
if(_username != nil) dict[@"username"] = _username ;
|
||||
if(_userId != nil) dict[@"userId"] = _userId ;
|
||||
if(_createdAt != nil){
|
||||
if([_createdAt isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGDate *createdAt in (NSArray*)_createdAt) {
|
||||
[array addObject:[(SWGObject*)createdAt asDictionary]];
|
||||
}
|
||||
dict[@"createdAt"] = array;
|
||||
}
|
||||
else if(_createdAt && [_createdAt isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_createdAt toString];
|
||||
if(dateString){
|
||||
dict[@"createdAt"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_createdAt != nil) dict[@"createdAt"] = [(SWGObject*)_createdAt asDictionary];
|
||||
}
|
||||
}
|
||||
if(_numberCommentsOnWord != nil) dict[@"numberCommentsOnWord"] = _numberCommentsOnWord ;
|
||||
if(_numberLists != nil) dict[@"numberLists"] = _numberLists ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,24 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGWordList.h"
|
||||
|
||||
|
||||
|
||||
@interface SWGWordListsApi: NSObject
|
||||
|
||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
|
||||
-(unsigned long) requestQueueSize;
|
||||
+(SWGWordListsApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
||||
+(void) setBasePath:(NSString*)basePath;
|
||||
+(NSString*) getBasePath;
|
||||
/**
|
||||
|
||||
Creates a WordList.
|
||||
|
||||
@param body WordList to create
|
||||
@param auth_token The auth token of the logged-in user, obtained by calling /account.{format}/authenticate/{username} (described above)
|
||||
*/
|
||||
-(NSNumber*) createWordListWithCompletionBlock :(SWGWordList*) body
|
||||
auth_token:(NSString*) auth_token
|
||||
completionHandler: (void (^)(SWGWordList* output, NSError* error))completionBlock;
|
||||
|
||||
@end
|
@ -1,132 +0,0 @@
|
||||
#import "SWGWordListsApi.h"
|
||||
#import "SWGFile.h"
|
||||
#import "SWGApiClient.h"
|
||||
#import "SWGWordList.h"
|
||||
|
||||
|
||||
|
||||
|
||||
@implementation SWGWordListsApi
|
||||
static NSString * basePath = @"http://api.wordnik.com/v4";
|
||||
|
||||
+(SWGWordListsApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key {
|
||||
static SWGWordListsApi* singletonAPI = nil;
|
||||
|
||||
if (singletonAPI == nil) {
|
||||
singletonAPI = [[SWGWordListsApi alloc] init];
|
||||
[singletonAPI addHeader:headerValue forKey:key];
|
||||
}
|
||||
return singletonAPI;
|
||||
}
|
||||
|
||||
+(void) setBasePath:(NSString*)path {
|
||||
basePath = path;
|
||||
}
|
||||
|
||||
+(NSString*) getBasePath {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
-(SWGApiClient*) apiClient {
|
||||
return [SWGApiClient sharedClientFromPool:basePath];
|
||||
}
|
||||
|
||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
|
||||
[[self apiClient] setHeaderValue:value forKey:key];
|
||||
}
|
||||
|
||||
-(id) init {
|
||||
self = [super init];
|
||||
[self apiClient];
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void) setHeaderValue:(NSString*) value
|
||||
forKey:(NSString*)key {
|
||||
[[self apiClient] setHeaderValue:value forKey:key];
|
||||
}
|
||||
|
||||
-(unsigned long) requestQueueSize {
|
||||
return [SWGApiClient requestQueueSize];
|
||||
}
|
||||
|
||||
|
||||
-(NSNumber*) createWordListWithCompletionBlock:(SWGWordList*) body
|
||||
auth_token:(NSString*) auth_token
|
||||
completionHandler: (void (^)(SWGWordList* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/wordLists.{format}", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
if(auth_token != nil)
|
||||
headerParams[@"auth_token"] = auth_token;
|
||||
id bodyDictionary = nil;
|
||||
if(body != nil && [body isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] init];
|
||||
for (id dict in (NSArray*)body) {
|
||||
if([dict respondsToSelector:@selector(asDictionary)]) {
|
||||
[objs addObject:[(SWGObject*)dict asDictionary]];
|
||||
}
|
||||
else{
|
||||
[objs addObject:dict];
|
||||
}
|
||||
}
|
||||
bodyDictionary = objs;
|
||||
}
|
||||
else if([body respondsToSelector:@selector(asDictionary)]) {
|
||||
bodyDictionary = [(SWGObject*)body asDictionary];
|
||||
}
|
||||
else if([body isKindOfClass:[NSString class]]) {
|
||||
// convert it to a dictionary
|
||||
NSError * error;
|
||||
NSString * str = (NSString*)body;
|
||||
NSDictionary *JSON =
|
||||
[NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding]
|
||||
options:NSJSONReadingMutableContainers
|
||||
error:&error];
|
||||
bodyDictionary = JSON;
|
||||
}
|
||||
else if([body isKindOfClass: [SWGFile class]]) {
|
||||
requestContentType = @"form-data";
|
||||
bodyDictionary = body;
|
||||
}
|
||||
else{
|
||||
NSLog(@"don't know what to do with %@", body);
|
||||
}
|
||||
|
||||
if(auth_token == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary:requestUrl
|
||||
method:@"POST"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType:requestContentType
|
||||
responseContentType:responseContentType
|
||||
completionBlock:^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
SWGWordList *result = nil;
|
||||
if (data) {
|
||||
result = [[SWGWordList alloc]initWithValues: data];
|
||||
}
|
||||
completionBlock(result , nil);}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
@ -1,31 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGWordObject : SWGObject
|
||||
|
||||
@property(nonatomic) NSNumber* _id;
|
||||
|
||||
@property(nonatomic) NSString* word;
|
||||
|
||||
@property(nonatomic) NSString* originalWord;
|
||||
|
||||
@property(nonatomic) NSArray* suggestions;
|
||||
|
||||
@property(nonatomic) NSString* canonicalForm;
|
||||
|
||||
@property(nonatomic) NSString* vulgar;
|
||||
|
||||
- (id) _id: (NSNumber*) _id
|
||||
word: (NSString*) word
|
||||
originalWord: (NSString*) originalWord
|
||||
suggestions: (NSArray*) suggestions
|
||||
canonicalForm: (NSString*) canonicalForm
|
||||
vulgar: (NSString*) vulgar;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,51 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGWordObject.h"
|
||||
|
||||
@implementation SWGWordObject
|
||||
|
||||
-(id)_id: (NSNumber*) _id
|
||||
word: (NSString*) word
|
||||
originalWord: (NSString*) originalWord
|
||||
suggestions: (NSArray*) suggestions
|
||||
canonicalForm: (NSString*) canonicalForm
|
||||
vulgar: (NSString*) vulgar
|
||||
{
|
||||
__id = _id;
|
||||
_word = word;
|
||||
_originalWord = originalWord;
|
||||
_suggestions = suggestions;
|
||||
_canonicalForm = canonicalForm;
|
||||
_vulgar = vulgar;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
__id = dict[@"id"];
|
||||
_word = dict[@"word"];
|
||||
_originalWord = dict[@"originalWord"];
|
||||
_suggestions = dict[@"suggestions"];
|
||||
_canonicalForm = dict[@"canonicalForm"];
|
||||
_vulgar = dict[@"vulgar"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(__id != nil) dict[@"id"] = __id ;
|
||||
if(_word != nil) dict[@"word"] = _word ;
|
||||
if(_originalWord != nil) dict[@"originalWord"] = _originalWord ;
|
||||
if(_suggestions != nil) dict[@"suggestions"] = _suggestions ;
|
||||
if(_canonicalForm != nil) dict[@"canonicalForm"] = _canonicalForm ;
|
||||
if(_vulgar != nil) dict[@"vulgar"] = _vulgar ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,53 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
#import "SWGDate.h"
|
||||
#import "SWGSimpleExample.h"
|
||||
#import "SWGSimpleDefinition.h"
|
||||
#import "SWGContentProvider.h"
|
||||
|
||||
|
||||
@interface SWGWordOfTheDay : SWGObject
|
||||
|
||||
@property(nonatomic) NSNumber* _id;
|
||||
|
||||
@property(nonatomic) NSString* parentId;
|
||||
|
||||
@property(nonatomic) NSString* category;
|
||||
|
||||
@property(nonatomic) NSString* createdBy;
|
||||
|
||||
@property(nonatomic) SWGDate* createdAt;
|
||||
|
||||
@property(nonatomic) SWGContentProvider* contentProvider;
|
||||
|
||||
@property(nonatomic) NSString* htmlExtra;
|
||||
|
||||
@property(nonatomic) NSString* word;
|
||||
|
||||
@property(nonatomic) NSArray* definitions;
|
||||
|
||||
@property(nonatomic) NSArray* examples;
|
||||
|
||||
@property(nonatomic) NSString* note;
|
||||
|
||||
@property(nonatomic) SWGDate* publishDate;
|
||||
|
||||
- (id) _id: (NSNumber*) _id
|
||||
parentId: (NSString*) parentId
|
||||
category: (NSString*) category
|
||||
createdBy: (NSString*) createdBy
|
||||
createdAt: (SWGDate*) createdAt
|
||||
contentProvider: (SWGContentProvider*) contentProvider
|
||||
htmlExtra: (NSString*) htmlExtra
|
||||
word: (NSString*) word
|
||||
definitions: (NSArray*) definitions
|
||||
examples: (NSArray*) examples
|
||||
note: (NSString*) note
|
||||
publishDate: (SWGDate*) publishDate;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,204 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGWordOfTheDay.h"
|
||||
|
||||
@implementation SWGWordOfTheDay
|
||||
|
||||
-(id)_id: (NSNumber*) _id
|
||||
parentId: (NSString*) parentId
|
||||
category: (NSString*) category
|
||||
createdBy: (NSString*) createdBy
|
||||
createdAt: (SWGDate*) createdAt
|
||||
contentProvider: (SWGContentProvider*) contentProvider
|
||||
htmlExtra: (NSString*) htmlExtra
|
||||
word: (NSString*) word
|
||||
definitions: (NSArray*) definitions
|
||||
examples: (NSArray*) examples
|
||||
note: (NSString*) note
|
||||
publishDate: (SWGDate*) publishDate
|
||||
{
|
||||
__id = _id;
|
||||
_parentId = parentId;
|
||||
_category = category;
|
||||
_createdBy = createdBy;
|
||||
_createdAt = createdAt;
|
||||
_contentProvider = contentProvider;
|
||||
_htmlExtra = htmlExtra;
|
||||
_word = word;
|
||||
_definitions = definitions;
|
||||
_examples = examples;
|
||||
_note = note;
|
||||
_publishDate = publishDate;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
__id = dict[@"id"];
|
||||
_parentId = dict[@"parentId"];
|
||||
_category = dict[@"category"];
|
||||
_createdBy = dict[@"createdBy"];
|
||||
id createdAt_dict = dict[@"createdAt"];
|
||||
if(createdAt_dict != nil)
|
||||
_createdAt = [[SWGDate alloc]initWithValues:createdAt_dict];
|
||||
id contentProvider_dict = dict[@"contentProvider"];
|
||||
if(contentProvider_dict != nil)
|
||||
_contentProvider = [[SWGContentProvider alloc]initWithValues:contentProvider_dict];
|
||||
_htmlExtra = dict[@"htmlExtra"];
|
||||
_word = dict[@"word"];
|
||||
id definitions_dict = dict[@"definitions"];
|
||||
if([definitions_dict isKindOfClass:[NSArray class]]) {
|
||||
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*)definitions_dict count]];
|
||||
|
||||
if([(NSArray*)definitions_dict count] > 0) {
|
||||
for (NSDictionary* dict in (NSArray*)definitions_dict) {
|
||||
SWGSimpleDefinition* d = [[SWGSimpleDefinition alloc] initWithValues:dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
|
||||
_definitions = [[NSArray alloc] initWithArray:objs];
|
||||
}
|
||||
else {
|
||||
_definitions = [[NSArray alloc] init];
|
||||
}
|
||||
}
|
||||
else {
|
||||
_definitions = [[NSArray alloc] init];
|
||||
}
|
||||
id examples_dict = dict[@"examples"];
|
||||
if([examples_dict isKindOfClass:[NSArray class]]) {
|
||||
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*)examples_dict count]];
|
||||
|
||||
if([(NSArray*)examples_dict count] > 0) {
|
||||
for (NSDictionary* dict in (NSArray*)examples_dict) {
|
||||
SWGSimpleExample* d = [[SWGSimpleExample alloc] initWithValues:dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
|
||||
_examples = [[NSArray alloc] initWithArray:objs];
|
||||
}
|
||||
else {
|
||||
_examples = [[NSArray alloc] init];
|
||||
}
|
||||
}
|
||||
else {
|
||||
_examples = [[NSArray alloc] init];
|
||||
}
|
||||
_note = dict[@"note"];
|
||||
id publishDate_dict = dict[@"publishDate"];
|
||||
if(publishDate_dict != nil)
|
||||
_publishDate = [[SWGDate alloc]initWithValues:publishDate_dict];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(__id != nil) dict[@"id"] = __id ;
|
||||
if(_parentId != nil) dict[@"parentId"] = _parentId ;
|
||||
if(_category != nil) dict[@"category"] = _category ;
|
||||
if(_createdBy != nil) dict[@"createdBy"] = _createdBy ;
|
||||
if(_createdAt != nil){
|
||||
if([_createdAt isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGDate *createdAt in (NSArray*)_createdAt) {
|
||||
[array addObject:[(SWGObject*)createdAt asDictionary]];
|
||||
}
|
||||
dict[@"createdAt"] = array;
|
||||
}
|
||||
else if(_createdAt && [_createdAt isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_createdAt toString];
|
||||
if(dateString){
|
||||
dict[@"createdAt"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_createdAt != nil) dict[@"createdAt"] = [(SWGObject*)_createdAt asDictionary];
|
||||
}
|
||||
}
|
||||
if(_contentProvider != nil){
|
||||
if([_contentProvider isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGContentProvider *contentProvider in (NSArray*)_contentProvider) {
|
||||
[array addObject:[(SWGObject*)contentProvider asDictionary]];
|
||||
}
|
||||
dict[@"contentProvider"] = array;
|
||||
}
|
||||
else if(_contentProvider && [_contentProvider isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_contentProvider toString];
|
||||
if(dateString){
|
||||
dict[@"contentProvider"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_contentProvider != nil) dict[@"contentProvider"] = [(SWGObject*)_contentProvider asDictionary];
|
||||
}
|
||||
}
|
||||
if(_htmlExtra != nil) dict[@"htmlExtra"] = _htmlExtra ;
|
||||
if(_word != nil) dict[@"word"] = _word ;
|
||||
if(_definitions != nil){
|
||||
if([_definitions isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGSimpleDefinition *definitions in (NSArray*)_definitions) {
|
||||
[array addObject:[(SWGObject*)definitions asDictionary]];
|
||||
}
|
||||
dict[@"definitions"] = array;
|
||||
}
|
||||
else if(_definitions && [_definitions isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_definitions toString];
|
||||
if(dateString){
|
||||
dict[@"definitions"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_definitions != nil) dict[@"definitions"] = [(SWGObject*)_definitions asDictionary];
|
||||
}
|
||||
}
|
||||
if(_examples != nil){
|
||||
if([_examples isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGSimpleExample *examples in (NSArray*)_examples) {
|
||||
[array addObject:[(SWGObject*)examples asDictionary]];
|
||||
}
|
||||
dict[@"examples"] = array;
|
||||
}
|
||||
else if(_examples && [_examples isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_examples toString];
|
||||
if(dateString){
|
||||
dict[@"examples"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_examples != nil) dict[@"examples"] = [(SWGObject*)_examples asDictionary];
|
||||
}
|
||||
}
|
||||
if(_note != nil) dict[@"note"] = _note ;
|
||||
if(_publishDate != nil){
|
||||
if([_publishDate isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGDate *publishDate in (NSArray*)_publishDate) {
|
||||
[array addObject:[(SWGObject*)publishDate asDictionary]];
|
||||
}
|
||||
dict[@"publishDate"] = array;
|
||||
}
|
||||
else if(_publishDate && [_publishDate isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_publishDate toString];
|
||||
if(dateString){
|
||||
dict[@"publishDate"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_publishDate != nil) dict[@"publishDate"] = [(SWGObject*)_publishDate asDictionary];
|
||||
}
|
||||
}
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,22 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
|
||||
|
||||
@interface SWGWordSearchResult : SWGObject
|
||||
|
||||
@property(nonatomic) NSNumber* count;
|
||||
|
||||
@property(nonatomic) NSNumber* lexicality;
|
||||
|
||||
@property(nonatomic) NSString* word;
|
||||
|
||||
- (id) count: (NSNumber*) count
|
||||
lexicality: (NSNumber*) lexicality
|
||||
word: (NSString*) word;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,39 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGWordSearchResult.h"
|
||||
|
||||
@implementation SWGWordSearchResult
|
||||
|
||||
-(id)count: (NSNumber*) count
|
||||
lexicality: (NSNumber*) lexicality
|
||||
word: (NSString*) word
|
||||
{
|
||||
_count = count;
|
||||
_lexicality = lexicality;
|
||||
_word = word;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_count = dict[@"count"];
|
||||
_lexicality = dict[@"lexicality"];
|
||||
_word = dict[@"word"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_count != nil) dict[@"count"] = _count ;
|
||||
if(_lexicality != nil) dict[@"lexicality"] = _lexicality ;
|
||||
if(_word != nil) dict[@"word"] = _word ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,20 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
#import "SWGWordSearchResult.h"
|
||||
|
||||
|
||||
@interface SWGWordSearchResults : SWGObject
|
||||
|
||||
@property(nonatomic) NSArray* searchResults;
|
||||
|
||||
@property(nonatomic) NSNumber* totalResults;
|
||||
|
||||
- (id) searchResults: (NSArray*) searchResults
|
||||
totalResults: (NSNumber*) totalResults;
|
||||
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
- (NSDictionary*) asDictionary;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -1,71 +0,0 @@
|
||||
#import "SWGDate.h"
|
||||
#import "SWGWordSearchResults.h"
|
||||
|
||||
@implementation SWGWordSearchResults
|
||||
|
||||
-(id)searchResults: (NSArray*) searchResults
|
||||
totalResults: (NSNumber*) totalResults
|
||||
{
|
||||
_searchResults = searchResults;
|
||||
_totalResults = totalResults;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id) initWithValues:(NSDictionary*)dict
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
id searchResults_dict = dict[@"searchResults"];
|
||||
if([searchResults_dict isKindOfClass:[NSArray class]]) {
|
||||
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*)searchResults_dict count]];
|
||||
|
||||
if([(NSArray*)searchResults_dict count] > 0) {
|
||||
for (NSDictionary* dict in (NSArray*)searchResults_dict) {
|
||||
SWGWordSearchResult* d = [[SWGWordSearchResult alloc] initWithValues:dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
|
||||
_searchResults = [[NSArray alloc] initWithArray:objs];
|
||||
}
|
||||
else {
|
||||
_searchResults = [[NSArray alloc] init];
|
||||
}
|
||||
}
|
||||
else {
|
||||
_searchResults = [[NSArray alloc] init];
|
||||
}
|
||||
_totalResults = dict[@"totalResults"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
if(_searchResults != nil){
|
||||
if([_searchResults isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( SWGWordSearchResult *searchResults in (NSArray*)_searchResults) {
|
||||
[array addObject:[(SWGObject*)searchResults asDictionary]];
|
||||
}
|
||||
dict[@"searchResults"] = array;
|
||||
}
|
||||
else if(_searchResults && [_searchResults isKindOfClass:[SWGDate class]]) {
|
||||
NSString * dateString = [(SWGDate*)_searchResults toString];
|
||||
if(dateString){
|
||||
dict[@"searchResults"] = dateString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_searchResults != nil) dict[@"searchResults"] = [(SWGObject*)_searchResults asDictionary];
|
||||
}
|
||||
}
|
||||
if(_totalResults != nil) dict[@"totalResults"] = _totalResults ;
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,151 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGDefinitionSearchResults.h"
|
||||
#import "SWGWordObject.h"
|
||||
#import "SWGWordOfTheDay.h"
|
||||
#import "SWGWordSearchResults.h"
|
||||
|
||||
|
||||
|
||||
@interface SWGWordsApi: NSObject
|
||||
|
||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
|
||||
-(unsigned long) requestQueueSize;
|
||||
+(SWGWordsApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
||||
+(void) setBasePath:(NSString*)basePath;
|
||||
+(NSString*) getBasePath;
|
||||
/**
|
||||
|
||||
Searches words
|
||||
|
||||
@param query Search query
|
||||
@param includePartOfSpeech Only include these comma-delimited parts of speech
|
||||
@param excludePartOfSpeech Exclude these comma-delimited parts of speech
|
||||
@param caseSensitive Search case sensitive
|
||||
@param minCorpusCount Minimum corpus frequency for terms
|
||||
@param maxCorpusCount Maximum corpus frequency for terms
|
||||
@param minDictionaryCount Minimum number of dictionary entries for words returned
|
||||
@param maxDictionaryCount Maximum dictionary definition count
|
||||
@param minLength Minimum word length
|
||||
@param maxLength Maximum word length
|
||||
@param skip Results to skip
|
||||
@param limit Maximum number of results to return
|
||||
*/
|
||||
-(NSNumber*) searchWordsWithCompletionBlock :(NSString*) query
|
||||
includePartOfSpeech:(NSString*) includePartOfSpeech
|
||||
excludePartOfSpeech:(NSString*) excludePartOfSpeech
|
||||
caseSensitive:(NSString*) caseSensitive
|
||||
minCorpusCount:(NSNumber*) minCorpusCount
|
||||
maxCorpusCount:(NSNumber*) maxCorpusCount
|
||||
minDictionaryCount:(NSNumber*) minDictionaryCount
|
||||
maxDictionaryCount:(NSNumber*) maxDictionaryCount
|
||||
minLength:(NSNumber*) minLength
|
||||
maxLength:(NSNumber*) maxLength
|
||||
skip:(NSNumber*) skip
|
||||
limit:(NSNumber*) limit
|
||||
completionHandler: (void (^)(SWGWordSearchResults* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Returns a specific WordOfTheDay
|
||||
|
||||
@param date Fetches by date in yyyy-MM-dd
|
||||
*/
|
||||
-(NSNumber*) getWordOfTheDayWithCompletionBlock :(NSString*) date
|
||||
completionHandler: (void (^)(SWGWordOfTheDay* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Reverse dictionary search
|
||||
|
||||
@param query Search term
|
||||
@param findSenseForWord Restricts words and finds closest sense
|
||||
@param includeSourceDictionaries Only include these comma-delimited source dictionaries
|
||||
@param excludeSourceDictionaries Exclude these comma-delimited source dictionaries
|
||||
@param includePartOfSpeech Only include these comma-delimited parts of speech
|
||||
@param excludePartOfSpeech Exclude these comma-delimited parts of speech
|
||||
@param expandTerms Expand terms
|
||||
@param sortBy Attribute to sort by
|
||||
@param sortOrder Sort direction
|
||||
@param minCorpusCount Minimum corpus frequency for terms
|
||||
@param maxCorpusCount Maximum corpus frequency for terms
|
||||
@param minLength Minimum word length
|
||||
@param maxLength Maximum word length
|
||||
@param includeTags Return a closed set of XML tags in response
|
||||
@param skip Results to skip
|
||||
@param limit Maximum number of results to return
|
||||
*/
|
||||
-(NSNumber*) reverseDictionaryWithCompletionBlock :(NSString*) query
|
||||
findSenseForWord:(NSString*) findSenseForWord
|
||||
includeSourceDictionaries:(NSString*) includeSourceDictionaries
|
||||
excludeSourceDictionaries:(NSString*) excludeSourceDictionaries
|
||||
includePartOfSpeech:(NSString*) includePartOfSpeech
|
||||
excludePartOfSpeech:(NSString*) excludePartOfSpeech
|
||||
expandTerms:(NSString*) expandTerms
|
||||
sortBy:(NSString*) sortBy
|
||||
sortOrder:(NSString*) sortOrder
|
||||
minCorpusCount:(NSNumber*) minCorpusCount
|
||||
maxCorpusCount:(NSNumber*) maxCorpusCount
|
||||
minLength:(NSNumber*) minLength
|
||||
maxLength:(NSNumber*) maxLength
|
||||
includeTags:(NSString*) includeTags
|
||||
skip:(NSString*) skip
|
||||
limit:(NSNumber*) limit
|
||||
completionHandler: (void (^)(SWGDefinitionSearchResults* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Returns an array of random WordObjects
|
||||
|
||||
@param includePartOfSpeech CSV part-of-speech values to include
|
||||
@param excludePartOfSpeech CSV part-of-speech values to exclude
|
||||
@param sortBy Attribute to sort by
|
||||
@param sortOrder Sort direction
|
||||
@param hasDictionaryDef Only return words with dictionary definitions
|
||||
@param minCorpusCount Minimum corpus frequency for terms
|
||||
@param maxCorpusCount Maximum corpus frequency for terms
|
||||
@param minDictionaryCount Minimum dictionary count
|
||||
@param maxDictionaryCount Maximum dictionary count
|
||||
@param minLength Minimum word length
|
||||
@param maxLength Maximum word length
|
||||
@param limit Maximum number of results to return
|
||||
*/
|
||||
-(NSNumber*) getRandomWordsWithCompletionBlock :(NSString*) includePartOfSpeech
|
||||
excludePartOfSpeech:(NSString*) excludePartOfSpeech
|
||||
sortBy:(NSString*) sortBy
|
||||
sortOrder:(NSString*) sortOrder
|
||||
hasDictionaryDef:(NSString*) hasDictionaryDef
|
||||
minCorpusCount:(NSNumber*) minCorpusCount
|
||||
maxCorpusCount:(NSNumber*) maxCorpusCount
|
||||
minDictionaryCount:(NSNumber*) minDictionaryCount
|
||||
maxDictionaryCount:(NSNumber*) maxDictionaryCount
|
||||
minLength:(NSNumber*) minLength
|
||||
maxLength:(NSNumber*) maxLength
|
||||
limit:(NSNumber*) limit
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock;
|
||||
|
||||
/**
|
||||
|
||||
Returns a single random WordObject
|
||||
|
||||
@param includePartOfSpeech CSV part-of-speech values to include
|
||||
@param excludePartOfSpeech CSV part-of-speech values to exclude
|
||||
@param hasDictionaryDef Only return words with dictionary definitions
|
||||
@param minCorpusCount Minimum corpus frequency for terms
|
||||
@param maxCorpusCount Maximum corpus frequency for terms
|
||||
@param minDictionaryCount Minimum dictionary count
|
||||
@param maxDictionaryCount Maximum dictionary count
|
||||
@param minLength Minimum word length
|
||||
@param maxLength Maximum word length
|
||||
*/
|
||||
-(NSNumber*) getRandomWordWithCompletionBlock :(NSString*) includePartOfSpeech
|
||||
excludePartOfSpeech:(NSString*) excludePartOfSpeech
|
||||
hasDictionaryDef:(NSString*) hasDictionaryDef
|
||||
minCorpusCount:(NSNumber*) minCorpusCount
|
||||
maxCorpusCount:(NSNumber*) maxCorpusCount
|
||||
minDictionaryCount:(NSNumber*) minDictionaryCount
|
||||
maxDictionaryCount:(NSNumber*) maxDictionaryCount
|
||||
minLength:(NSNumber*) minLength
|
||||
maxLength:(NSNumber*) maxLength
|
||||
completionHandler: (void (^)(SWGWordObject* output, NSError* error))completionBlock;
|
||||
|
||||
@end
|
@ -1,399 +0,0 @@
|
||||
#import "SWGWordsApi.h"
|
||||
#import "SWGFile.h"
|
||||
#import "SWGApiClient.h"
|
||||
#import "SWGDefinitionSearchResults.h"
|
||||
#import "SWGWordObject.h"
|
||||
#import "SWGWordOfTheDay.h"
|
||||
#import "SWGWordSearchResults.h"
|
||||
|
||||
|
||||
|
||||
|
||||
@implementation SWGWordsApi
|
||||
static NSString * basePath = @"http://api.wordnik.com/v4";
|
||||
|
||||
+(SWGWordsApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key {
|
||||
static SWGWordsApi* singletonAPI = nil;
|
||||
|
||||
if (singletonAPI == nil) {
|
||||
singletonAPI = [[SWGWordsApi alloc] init];
|
||||
[singletonAPI addHeader:headerValue forKey:key];
|
||||
}
|
||||
return singletonAPI;
|
||||
}
|
||||
|
||||
+(void) setBasePath:(NSString*)path {
|
||||
basePath = path;
|
||||
}
|
||||
|
||||
+(NSString*) getBasePath {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
-(SWGApiClient*) apiClient {
|
||||
return [SWGApiClient sharedClientFromPool:basePath];
|
||||
}
|
||||
|
||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
|
||||
[[self apiClient] setHeaderValue:value forKey:key];
|
||||
}
|
||||
|
||||
-(id) init {
|
||||
self = [super init];
|
||||
[self apiClient];
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void) setHeaderValue:(NSString*) value
|
||||
forKey:(NSString*)key {
|
||||
[[self apiClient] setHeaderValue:value forKey:key];
|
||||
}
|
||||
|
||||
-(unsigned long) requestQueueSize {
|
||||
return [SWGApiClient requestQueueSize];
|
||||
}
|
||||
|
||||
|
||||
-(NSNumber*) searchWordsWithCompletionBlock:(NSString*) query
|
||||
includePartOfSpeech:(NSString*) includePartOfSpeech
|
||||
excludePartOfSpeech:(NSString*) excludePartOfSpeech
|
||||
caseSensitive:(NSString*) caseSensitive
|
||||
minCorpusCount:(NSNumber*) minCorpusCount
|
||||
maxCorpusCount:(NSNumber*) maxCorpusCount
|
||||
minDictionaryCount:(NSNumber*) minDictionaryCount
|
||||
maxDictionaryCount:(NSNumber*) maxDictionaryCount
|
||||
minLength:(NSNumber*) minLength
|
||||
maxLength:(NSNumber*) maxLength
|
||||
skip:(NSNumber*) skip
|
||||
limit:(NSNumber*) limit
|
||||
completionHandler: (void (^)(SWGWordSearchResults* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/words.{format}/search/{query}", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"query", @"}"]] withString: [SWGApiClient escape:query]];
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(caseSensitive != nil)
|
||||
queryParams[@"caseSensitive"] = caseSensitive;
|
||||
if(includePartOfSpeech != nil)
|
||||
queryParams[@"includePartOfSpeech"] = includePartOfSpeech;
|
||||
if(excludePartOfSpeech != nil)
|
||||
queryParams[@"excludePartOfSpeech"] = excludePartOfSpeech;
|
||||
if(minCorpusCount != nil)
|
||||
queryParams[@"minCorpusCount"] = minCorpusCount;
|
||||
if(maxCorpusCount != nil)
|
||||
queryParams[@"maxCorpusCount"] = maxCorpusCount;
|
||||
if(minDictionaryCount != nil)
|
||||
queryParams[@"minDictionaryCount"] = minDictionaryCount;
|
||||
if(maxDictionaryCount != nil)
|
||||
queryParams[@"maxDictionaryCount"] = maxDictionaryCount;
|
||||
if(minLength != nil)
|
||||
queryParams[@"minLength"] = minLength;
|
||||
if(maxLength != nil)
|
||||
queryParams[@"maxLength"] = maxLength;
|
||||
if(skip != nil)
|
||||
queryParams[@"skip"] = skip;
|
||||
if(limit != nil)
|
||||
queryParams[@"limit"] = limit;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
if(query == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary:requestUrl
|
||||
method:@"GET"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType:requestContentType
|
||||
responseContentType:responseContentType
|
||||
completionBlock:^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
SWGWordSearchResults *result = nil;
|
||||
if (data) {
|
||||
result = [[SWGWordSearchResults alloc]initWithValues: data];
|
||||
}
|
||||
completionBlock(result , nil);}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getWordOfTheDayWithCompletionBlock:(NSString*) date
|
||||
completionHandler: (void (^)(SWGWordOfTheDay* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/words.{format}/wordOfTheDay", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(date != nil)
|
||||
queryParams[@"date"] = date;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary:requestUrl
|
||||
method:@"GET"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType:requestContentType
|
||||
responseContentType:responseContentType
|
||||
completionBlock:^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
SWGWordOfTheDay *result = nil;
|
||||
if (data) {
|
||||
result = [[SWGWordOfTheDay alloc]initWithValues: data];
|
||||
}
|
||||
completionBlock(result , nil);}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) reverseDictionaryWithCompletionBlock:(NSString*) query
|
||||
findSenseForWord:(NSString*) findSenseForWord
|
||||
includeSourceDictionaries:(NSString*) includeSourceDictionaries
|
||||
excludeSourceDictionaries:(NSString*) excludeSourceDictionaries
|
||||
includePartOfSpeech:(NSString*) includePartOfSpeech
|
||||
excludePartOfSpeech:(NSString*) excludePartOfSpeech
|
||||
expandTerms:(NSString*) expandTerms
|
||||
sortBy:(NSString*) sortBy
|
||||
sortOrder:(NSString*) sortOrder
|
||||
minCorpusCount:(NSNumber*) minCorpusCount
|
||||
maxCorpusCount:(NSNumber*) maxCorpusCount
|
||||
minLength:(NSNumber*) minLength
|
||||
maxLength:(NSNumber*) maxLength
|
||||
includeTags:(NSString*) includeTags
|
||||
skip:(NSString*) skip
|
||||
limit:(NSNumber*) limit
|
||||
completionHandler: (void (^)(SWGDefinitionSearchResults* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/words.{format}/reverseDictionary", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(query != nil)
|
||||
queryParams[@"query"] = query;
|
||||
if(findSenseForWord != nil)
|
||||
queryParams[@"findSenseForWord"] = findSenseForWord;
|
||||
if(includeSourceDictionaries != nil)
|
||||
queryParams[@"includeSourceDictionaries"] = includeSourceDictionaries;
|
||||
if(excludeSourceDictionaries != nil)
|
||||
queryParams[@"excludeSourceDictionaries"] = excludeSourceDictionaries;
|
||||
if(includePartOfSpeech != nil)
|
||||
queryParams[@"includePartOfSpeech"] = includePartOfSpeech;
|
||||
if(excludePartOfSpeech != nil)
|
||||
queryParams[@"excludePartOfSpeech"] = excludePartOfSpeech;
|
||||
if(minCorpusCount != nil)
|
||||
queryParams[@"minCorpusCount"] = minCorpusCount;
|
||||
if(maxCorpusCount != nil)
|
||||
queryParams[@"maxCorpusCount"] = maxCorpusCount;
|
||||
if(minLength != nil)
|
||||
queryParams[@"minLength"] = minLength;
|
||||
if(maxLength != nil)
|
||||
queryParams[@"maxLength"] = maxLength;
|
||||
if(expandTerms != nil)
|
||||
queryParams[@"expandTerms"] = expandTerms;
|
||||
if(includeTags != nil)
|
||||
queryParams[@"includeTags"] = includeTags;
|
||||
if(sortBy != nil)
|
||||
queryParams[@"sortBy"] = sortBy;
|
||||
if(sortOrder != nil)
|
||||
queryParams[@"sortOrder"] = sortOrder;
|
||||
if(skip != nil)
|
||||
queryParams[@"skip"] = skip;
|
||||
if(limit != nil)
|
||||
queryParams[@"limit"] = limit;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
if(query == nil) {
|
||||
// error
|
||||
}
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary:requestUrl
|
||||
method:@"GET"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType:requestContentType
|
||||
responseContentType:responseContentType
|
||||
completionBlock:^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
SWGDefinitionSearchResults *result = nil;
|
||||
if (data) {
|
||||
result = [[SWGDefinitionSearchResults alloc]initWithValues: data];
|
||||
}
|
||||
completionBlock(result , nil);}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getRandomWordsWithCompletionBlock:(NSString*) includePartOfSpeech
|
||||
excludePartOfSpeech:(NSString*) excludePartOfSpeech
|
||||
sortBy:(NSString*) sortBy
|
||||
sortOrder:(NSString*) sortOrder
|
||||
hasDictionaryDef:(NSString*) hasDictionaryDef
|
||||
minCorpusCount:(NSNumber*) minCorpusCount
|
||||
maxCorpusCount:(NSNumber*) maxCorpusCount
|
||||
minDictionaryCount:(NSNumber*) minDictionaryCount
|
||||
maxDictionaryCount:(NSNumber*) maxDictionaryCount
|
||||
minLength:(NSNumber*) minLength
|
||||
maxLength:(NSNumber*) maxLength
|
||||
limit:(NSNumber*) limit
|
||||
completionHandler: (void (^)(NSArray* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/words.{format}/randomWords", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(hasDictionaryDef != nil)
|
||||
queryParams[@"hasDictionaryDef"] = hasDictionaryDef;
|
||||
if(includePartOfSpeech != nil)
|
||||
queryParams[@"includePartOfSpeech"] = includePartOfSpeech;
|
||||
if(excludePartOfSpeech != nil)
|
||||
queryParams[@"excludePartOfSpeech"] = excludePartOfSpeech;
|
||||
if(minCorpusCount != nil)
|
||||
queryParams[@"minCorpusCount"] = minCorpusCount;
|
||||
if(maxCorpusCount != nil)
|
||||
queryParams[@"maxCorpusCount"] = maxCorpusCount;
|
||||
if(minDictionaryCount != nil)
|
||||
queryParams[@"minDictionaryCount"] = minDictionaryCount;
|
||||
if(maxDictionaryCount != nil)
|
||||
queryParams[@"maxDictionaryCount"] = maxDictionaryCount;
|
||||
if(minLength != nil)
|
||||
queryParams[@"minLength"] = minLength;
|
||||
if(maxLength != nil)
|
||||
queryParams[@"maxLength"] = maxLength;
|
||||
if(sortBy != nil)
|
||||
queryParams[@"sortBy"] = sortBy;
|
||||
if(sortOrder != nil)
|
||||
queryParams[@"sortOrder"] = sortOrder;
|
||||
if(limit != nil)
|
||||
queryParams[@"limit"] = limit;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary: requestUrl
|
||||
method: @"GET"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
|
||||
if([data isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]];
|
||||
for (NSDictionary* dict in (NSArray*)data) {
|
||||
SWGWordObject* d = [[SWGWordObject alloc]initWithValues: dict];
|
||||
[objs addObject:d];
|
||||
}
|
||||
completionBlock(objs, nil);
|
||||
}
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(NSNumber*) getRandomWordWithCompletionBlock:(NSString*) includePartOfSpeech
|
||||
excludePartOfSpeech:(NSString*) excludePartOfSpeech
|
||||
hasDictionaryDef:(NSString*) hasDictionaryDef
|
||||
minCorpusCount:(NSNumber*) minCorpusCount
|
||||
maxCorpusCount:(NSNumber*) maxCorpusCount
|
||||
minDictionaryCount:(NSNumber*) minDictionaryCount
|
||||
maxDictionaryCount:(NSNumber*) maxDictionaryCount
|
||||
minLength:(NSNumber*) minLength
|
||||
maxLength:(NSNumber*) maxLength
|
||||
completionHandler: (void (^)(SWGWordObject* output, NSError* error))completionBlock{
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/words.{format}/randomWord", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
if(hasDictionaryDef != nil)
|
||||
queryParams[@"hasDictionaryDef"] = hasDictionaryDef;
|
||||
if(includePartOfSpeech != nil)
|
||||
queryParams[@"includePartOfSpeech"] = includePartOfSpeech;
|
||||
if(excludePartOfSpeech != nil)
|
||||
queryParams[@"excludePartOfSpeech"] = excludePartOfSpeech;
|
||||
if(minCorpusCount != nil)
|
||||
queryParams[@"minCorpusCount"] = minCorpusCount;
|
||||
if(maxCorpusCount != nil)
|
||||
queryParams[@"maxCorpusCount"] = maxCorpusCount;
|
||||
if(minDictionaryCount != nil)
|
||||
queryParams[@"minDictionaryCount"] = minDictionaryCount;
|
||||
if(maxDictionaryCount != nil)
|
||||
queryParams[@"maxDictionaryCount"] = maxDictionaryCount;
|
||||
if(minLength != nil)
|
||||
queryParams[@"minLength"] = minLength;
|
||||
if(maxLength != nil)
|
||||
queryParams[@"maxLength"] = maxLength;
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
id bodyDictionary = nil;
|
||||
SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];
|
||||
|
||||
return [client dictionary:requestUrl
|
||||
method:@"GET"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType:requestContentType
|
||||
responseContentType:responseContentType
|
||||
completionBlock:^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);return;
|
||||
}
|
||||
SWGWordObject *result = nil;
|
||||
if (data) {
|
||||
result = [[SWGWordObject alloc]initWithValues: data];
|
||||
}
|
||||
completionBlock(result , nil);}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
@ -1,27 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.File
|
||||
|
||||
object PHPWordnikApiCodegen extends BasicPHPGenerator {
|
||||
def main(args: Array[String]) = generateClient(args)
|
||||
|
||||
override def supportingFiles = List(
|
||||
("Swagger.mustache", destinationDir + File.separator + apiPackage.get, "Swagger.php")
|
||||
)
|
||||
|
||||
override def destinationDir = "samples/client/wordnik-api/php/wordnik"
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
# PHP client for Wordnik.com API
|
||||
|
||||
## Overview
|
||||
|
||||
This is a PHP client for the Wordnik.com v4 API. For more information, see http://developer.wordnik.com/ .
|
||||
|
||||
## Generation
|
||||
|
||||
This client was generated using the provided script:
|
||||
|
||||
```
|
||||
/bin/php-wordnik-api.sh
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
These tests require PHPUnit. If you require PHPUnit to be installed, first get PEAR:
|
||||
|
||||
```sh
|
||||
wget http://pear.php.net/go-pear.phar
|
||||
php -d detect_unicode=0 go-pear.phar
|
||||
```
|
||||
|
||||
Then install PHPUnit:
|
||||
|
||||
```sh
|
||||
pear config-set auto_discover 1
|
||||
pear install pear.phpunit.de/PHPUnit
|
||||
```
|
||||
|
||||
The tests require you to set three environment varibales:
|
||||
|
||||
```sh
|
||||
export API_KEY=your api key
|
||||
export USER_NAME=some wordnik.com username
|
||||
export PASSWORD=the user's password
|
||||
```
|
||||
|
||||
The tests can be run as follows:
|
||||
|
||||
```sh
|
||||
phpunit tests/AccountApiTest.php
|
||||
phpunit tests/WordApiTest.php
|
||||
phpunit tests/WordsApiTest.php
|
||||
phpunit tests/WordListApiTest.php
|
||||
phpunit tests/WordListsApiTest.php
|
||||
```
|
@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
// Unit tests for PHP Wordnik API client.
|
||||
//
|
||||
// Requires you to set three environment varibales:
|
||||
// API_KEY your API key
|
||||
// USER_NAME the username of a user
|
||||
// PASSWORD the user's password
|
||||
|
||||
// Run all tests:
|
||||
//
|
||||
// phpunit tests/AccountApiTest.php
|
||||
// phpunit tests/WordApiTest.php
|
||||
// phpunit tests/WordsApiTest.php
|
||||
// phpunit tests/WordListApiTest.php
|
||||
// phpunit tests/WordListsApiTest.php
|
||||
|
||||
// If you require PHPUnit to be installed, first get PEAR:
|
||||
//
|
||||
// $ wget http://pear.php.net/go-pear.phar
|
||||
// $ php -d detect_unicode=0 go-pear.phar
|
||||
//
|
||||
// Then install PHPUnit:
|
||||
//
|
||||
// $ pear config-set auto_discover
|
||||
// $ pear install pear.phpunit.de/PHPUnit
|
||||
|
||||
|
||||
require_once 'wordnik/Swagger.php';
|
||||
// This used to be required, but now gives an error:
|
||||
// Cannot redeclare phpunit_autoload()
|
||||
// require_once '/usr/lib/php/PHPUnit/Autoload.php';
|
||||
|
||||
class BaseApiTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function setUp() {
|
||||
$this->apiUrl = 'https://api.wordnik.com/v4';
|
||||
$this->apiKey = getenv('API_KEY');
|
||||
$this->username = getenv('USER_NAME');
|
||||
$this->password = getenv('PASSWORD');
|
||||
$this->client = new APIClient($this->apiKey, $this->apiUrl);
|
||||
$this->accountApi = new AccountApi($this->client);
|
||||
$this->wordApi = new WordApi($this->client);
|
||||
$this->wordListApi = new WordListApi($this->client);
|
||||
$this->wordListsApi = new WordListsApi($this->client);
|
||||
$this->wordsApi = new WordsApi($this->client);
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
unset($this->client);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
@ -1,250 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 SmartBear Software
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
|
||||
*/
|
||||
class AccountApi {
|
||||
|
||||
function __construct($apiClient) {
|
||||
$this->apiClient = $apiClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* authenticate
|
||||
* Authenticates a User
|
||||
* username, string: A confirmed Wordnik username (required)
|
||||
|
||||
* password, string: The user's password (required)
|
||||
|
||||
* @return AuthenticationToken
|
||||
*/
|
||||
|
||||
public function authenticate($username, $password) {
|
||||
|
||||
//parse inputs
|
||||
$resourcePath = "/account.{format}/authenticate/{username}";
|
||||
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||
$method = "GET";
|
||||
$queryParams = array();
|
||||
$headerParams = array();
|
||||
$headerParams['Accept'] = 'application/json';
|
||||
$headerParams['Content-Type'] = 'application/json';
|
||||
|
||||
if($password != null) {
|
||||
$queryParams['password'] = $this->apiClient->toQueryValue($password);
|
||||
}
|
||||
if($username != null) {
|
||||
$resourcePath = str_replace("{" . "username" . "}",
|
||||
$this->apiClient->toPathValue($username), $resourcePath);
|
||||
}
|
||||
//make the API Call
|
||||
if (! isset($body)) {
|
||||
$body = null;
|
||||
}
|
||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||
$queryParams, $body,
|
||||
$headerParams);
|
||||
|
||||
|
||||
if(! $response){
|
||||
return null;
|
||||
}
|
||||
|
||||
$responseObject = $this->apiClient->deserialize($response,
|
||||
'AuthenticationToken');
|
||||
return $responseObject;
|
||||
|
||||
}
|
||||
/**
|
||||
* authenticatePost
|
||||
* Authenticates a user
|
||||
* username, string: A confirmed Wordnik username (required)
|
||||
|
||||
* body, string: The user's password (required)
|
||||
|
||||
* @return AuthenticationToken
|
||||
*/
|
||||
|
||||
public function authenticatePost($username, $body) {
|
||||
|
||||
//parse inputs
|
||||
$resourcePath = "/account.{format}/authenticate/{username}";
|
||||
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||
$method = "POST";
|
||||
$queryParams = array();
|
||||
$headerParams = array();
|
||||
$headerParams['Accept'] = 'application/json';
|
||||
$headerParams['Content-Type'] = 'application/json';
|
||||
|
||||
if($username != null) {
|
||||
$resourcePath = str_replace("{" . "username" . "}",
|
||||
$this->apiClient->toPathValue($username), $resourcePath);
|
||||
}
|
||||
//make the API Call
|
||||
if (! isset($body)) {
|
||||
$body = null;
|
||||
}
|
||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||
$queryParams, $body,
|
||||
$headerParams);
|
||||
|
||||
|
||||
if(! $response){
|
||||
return null;
|
||||
}
|
||||
|
||||
$responseObject = $this->apiClient->deserialize($response,
|
||||
'AuthenticationToken');
|
||||
return $responseObject;
|
||||
|
||||
}
|
||||
/**
|
||||
* getWordListsForLoggedInUser
|
||||
* Fetches WordList objects for the logged-in user.
|
||||
* auth_token, string: auth_token of logged-in user (required)
|
||||
|
||||
* skip, int: Results to skip (optional)
|
||||
|
||||
* limit, int: Maximum number of results to return (optional)
|
||||
|
||||
* @return array[WordList]
|
||||
*/
|
||||
|
||||
public function getWordListsForLoggedInUser($auth_token, $skip=null, $limit=null) {
|
||||
|
||||
//parse inputs
|
||||
$resourcePath = "/account.{format}/wordLists";
|
||||
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||
$method = "GET";
|
||||
$queryParams = array();
|
||||
$headerParams = array();
|
||||
$headerParams['Accept'] = 'application/json';
|
||||
$headerParams['Content-Type'] = 'application/json';
|
||||
|
||||
if($skip != null) {
|
||||
$queryParams['skip'] = $this->apiClient->toQueryValue($skip);
|
||||
}
|
||||
if($limit != null) {
|
||||
$queryParams['limit'] = $this->apiClient->toQueryValue($limit);
|
||||
}
|
||||
if($auth_token != null) {
|
||||
$headerParams['auth_token'] = $this->apiClient->toHeaderValue($auth_token);
|
||||
}
|
||||
//make the API Call
|
||||
if (! isset($body)) {
|
||||
$body = null;
|
||||
}
|
||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||
$queryParams, $body,
|
||||
$headerParams);
|
||||
|
||||
|
||||
if(! $response){
|
||||
return null;
|
||||
}
|
||||
|
||||
$responseObject = $this->apiClient->deserialize($response,
|
||||
'array[WordList]');
|
||||
return $responseObject;
|
||||
|
||||
}
|
||||
/**
|
||||
* getApiTokenStatus
|
||||
* Returns usage statistics for the API account.
|
||||
* api_key, string: Wordnik authentication token (optional)
|
||||
|
||||
* @return ApiTokenStatus
|
||||
*/
|
||||
|
||||
public function getApiTokenStatus($api_key=null) {
|
||||
|
||||
//parse inputs
|
||||
$resourcePath = "/account.{format}/apiTokenStatus";
|
||||
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||
$method = "GET";
|
||||
$queryParams = array();
|
||||
$headerParams = array();
|
||||
$headerParams['Accept'] = 'application/json';
|
||||
$headerParams['Content-Type'] = 'application/json';
|
||||
|
||||
if($api_key != null) {
|
||||
$headerParams['api_key'] = $this->apiClient->toHeaderValue($api_key);
|
||||
}
|
||||
//make the API Call
|
||||
if (! isset($body)) {
|
||||
$body = null;
|
||||
}
|
||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||
$queryParams, $body,
|
||||
$headerParams);
|
||||
|
||||
|
||||
if(! $response){
|
||||
return null;
|
||||
}
|
||||
|
||||
$responseObject = $this->apiClient->deserialize($response,
|
||||
'ApiTokenStatus');
|
||||
return $responseObject;
|
||||
|
||||
}
|
||||
/**
|
||||
* getLoggedInUser
|
||||
* Returns the logged-in User
|
||||
* auth_token, string: The auth token of the logged-in user, obtained by calling /account.{format}/authenticate/{username} (described above) (required)
|
||||
|
||||
* @return User
|
||||
*/
|
||||
|
||||
public function getLoggedInUser($auth_token) {
|
||||
|
||||
//parse inputs
|
||||
$resourcePath = "/account.{format}/user";
|
||||
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||
$method = "GET";
|
||||
$queryParams = array();
|
||||
$headerParams = array();
|
||||
$headerParams['Accept'] = 'application/json';
|
||||
$headerParams['Content-Type'] = 'application/json';
|
||||
|
||||
if($auth_token != null) {
|
||||
$headerParams['auth_token'] = $this->apiClient->toHeaderValue($auth_token);
|
||||
}
|
||||
//make the API Call
|
||||
if (! isset($body)) {
|
||||
$body = null;
|
||||
}
|
||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||
$queryParams, $body,
|
||||
$headerParams);
|
||||
|
||||
|
||||
if(! $response){
|
||||
return null;
|
||||
}
|
||||
|
||||
$responseObject = $this->apiClient->deserialize($response,
|
||||
'User');
|
||||
return $responseObject;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,65 +0,0 @@
|
||||
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class AccountApiTest extends FlatSpec with Matchers with BaseApiTest {
|
||||
behavior of "AccountApi"
|
||||
val api = new AccountApi
|
||||
|
||||
api.addHeader("api_key", API_KEY)
|
||||
|
||||
val auth = api.authenticate(USER_NAME, PASSWORD).get
|
||||
|
||||
it should "authenticate" in {
|
||||
api.authenticate(USER_NAME, PASSWORD) match {
|
||||
case Some(key) => {
|
||||
key.token should not be (null)
|
||||
key.userId should not be (0)
|
||||
key.userSignature should not be null
|
||||
}
|
||||
case None => fail("couldn't authenticate")
|
||||
}
|
||||
}
|
||||
|
||||
it should "authenticate with post" in {
|
||||
api.authenticatePost(USER_NAME, PASSWORD) match {
|
||||
case Some(key) => {
|
||||
key.token should not be (null)
|
||||
key.userId should not be (0)
|
||||
key.userSignature should not be null
|
||||
}
|
||||
case None => fail("couldn't authenticate")
|
||||
}
|
||||
}
|
||||
|
||||
it should "fetch word lists for the current user" in {
|
||||
api.getWordListsForLoggedInUser(auth.token, 0, 15) match {
|
||||
case Some(lists) => {
|
||||
lists.size should not be (0)
|
||||
}
|
||||
case None => fail("didn't fetch lists for user")
|
||||
}
|
||||
}
|
||||
|
||||
it should "fetch api token status" in {
|
||||
api.getApiTokenStatus(API_KEY) match {
|
||||
case Some(status) => {
|
||||
status.valid should be(true)
|
||||
status.token should not be (null)
|
||||
status.remainingCalls should not be (0)
|
||||
}
|
||||
case None => fail("ooops")
|
||||
}
|
||||
}
|
||||
|
||||
it should "get the logged in user" in {
|
||||
api.getLoggedInUser(auth.token) match {
|
||||
case Some(user) => {
|
||||
user.id should not be (0)
|
||||
user.username should be(USER_NAME)
|
||||
user.status should be(0)
|
||||
user.email should not be (null)
|
||||
}
|
||||
case None => fail("didn't get user")
|
||||
}
|
||||
}
|
||||
}
|
@ -1,131 +0,0 @@
|
||||
import scala.io.Source
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class WordApiTest extends FlatSpec with Matchers with BaseApiTest {
|
||||
behavior of "WordApi"
|
||||
val api = new WordApi
|
||||
|
||||
api.addHeader("api_key", API_KEY)
|
||||
|
||||
it should "verify the word apis" in {
|
||||
val json = Source.fromURL("http://api.wordnik.com/v4/word.json").mkString
|
||||
val doc = JsonUtil.getJsonMapper.readValue(json, classOf[Documentation])
|
||||
assert(doc.getApis.size === 12)
|
||||
}
|
||||
|
||||
it should "fetch a word" in {
|
||||
api.getWord("cat") match {
|
||||
case Some(word) => {
|
||||
word.word should be("cat")
|
||||
word should not be (null)
|
||||
}
|
||||
case None => fail("didn't find word cat")
|
||||
}
|
||||
}
|
||||
|
||||
it should "fetch a word with suggestions" in {
|
||||
api.getWord("cAt", "false", "true") match {
|
||||
case Some(word) => {
|
||||
word.word should be("cAt")
|
||||
word.suggestions.size should be(1)
|
||||
word.suggestions(0) should be("cat")
|
||||
word should not be (null)
|
||||
}
|
||||
case None => fail("didn't find word cAt")
|
||||
}
|
||||
}
|
||||
|
||||
it should "fetch a word with canonical form" in {
|
||||
api.getWord("cAt", "true") match {
|
||||
case Some(word) => {
|
||||
word.word should be("cat")
|
||||
word should not be (null)
|
||||
}
|
||||
case None => fail("didn't find word cat")
|
||||
}
|
||||
}
|
||||
|
||||
it should "fetch definitions for a word" in {
|
||||
api.getDefinitions("cat", null, null, 10) match {
|
||||
case Some(definitions) => {
|
||||
definitions.size should be(10)
|
||||
}
|
||||
case None => fail("didn't find definitions for cat")
|
||||
}
|
||||
}
|
||||
|
||||
it should "fetch examples for a word" in {
|
||||
api.getExamples("cat", "false", "false", 0, 5) match {
|
||||
case Some(examples) => {
|
||||
examples.examples.size should be(5)
|
||||
}
|
||||
case None => fail("didn't find examples for cat")
|
||||
}
|
||||
}
|
||||
|
||||
it should "fetch a top example for a word" in {
|
||||
api.getTopExample("cat") match {
|
||||
case Some(example) => {
|
||||
example.word should be("cat")
|
||||
}
|
||||
case None => fail("didn't find examples for cat")
|
||||
}
|
||||
}
|
||||
|
||||
it should "get text pronunciations for a word" in {
|
||||
api.getTextPronunciations("cat", null, null, null, 2) match {
|
||||
case Some(prons) => {
|
||||
prons.size should be(2)
|
||||
}
|
||||
case None => fail("didn't find prons for cat")
|
||||
}
|
||||
}
|
||||
|
||||
it should "get hyphenation for a word" in {
|
||||
api.getHyphenation("catalog", null, null) match {
|
||||
case Some(hyphenation) => {
|
||||
hyphenation.size should be(3)
|
||||
}
|
||||
case None => fail("didn't find hyphenation for catalog")
|
||||
}
|
||||
}
|
||||
|
||||
it should "get word frequency for a word" in {
|
||||
api.getWordFrequency("cat") match {
|
||||
case Some(frequency) => {
|
||||
frequency.totalCount should not be (0)
|
||||
}
|
||||
case None => fail("didn't find frequency for cat")
|
||||
}
|
||||
}
|
||||
|
||||
it should "get word phrases for a word" in {
|
||||
api.getPhrases("money", 10, 0) match {
|
||||
case Some(phrases) => {
|
||||
phrases.size should not be (0)
|
||||
}
|
||||
case None => fail("didn't find phrases for money")
|
||||
}
|
||||
}
|
||||
|
||||
it should "get related words" in {
|
||||
api.getRelatedWords("cat", null, null) match {
|
||||
case Some(relateds) => {
|
||||
var count = 0
|
||||
relateds.foreach(related => {
|
||||
related.words.size should (be <= 10)
|
||||
})
|
||||
}
|
||||
case None => fail("didn't find related words")
|
||||
}
|
||||
}
|
||||
|
||||
it should "get audio for a word" in {
|
||||
api.getAudio("cat", "true", 2) match {
|
||||
case Some(audio) => {
|
||||
audio.size should be(2)
|
||||
}
|
||||
case None => fail("didn't find audio")
|
||||
}
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class WordListApiTest extends FlatSpec with Matchers with BaseApiTest {
|
||||
behavior of "WordListApi"
|
||||
val api = new WordListApi
|
||||
|
||||
api.addHeader("api_key", API_KEY)
|
||||
|
||||
val accountApi = new AccountApi
|
||||
val auth = accountApi.authenticate(USER_NAME, PASSWORD).get
|
||||
val existingList = accountApi.getWordListsForLoggedInUser(auth.token, 0, 1).get.head
|
||||
|
||||
val wordListsApi = new WordListsApi
|
||||
|
||||
val wordList = WordList(
|
||||
0, // id
|
||||
null, // permalink
|
||||
"my test list", // name
|
||||
new java.util.Date, //created at
|
||||
null, // updated at
|
||||
null, // lastActivityAt
|
||||
null, // username
|
||||
0, // user id
|
||||
"some words I want to play with", // description
|
||||
0, // words in list
|
||||
"PUBLIC") // type
|
||||
|
||||
var sampleList = wordListsApi.createWordList(wordList, auth.token) match {
|
||||
case Some(wl) => wl
|
||||
case None => throw new Exception("can't create test list to run tests with")
|
||||
}
|
||||
|
||||
it should "get a word list by permalink" in {
|
||||
api.getWordListByPermalink(existingList.permalink, auth.token) match {
|
||||
case Some(list) => {
|
||||
list should not be (null)
|
||||
}
|
||||
case None => fail("didn't get existing word list")
|
||||
}
|
||||
}
|
||||
|
||||
it should "update a word list" in {
|
||||
val description = "list updated at " + new java.util.Date
|
||||
|
||||
val updatedList = existingList.copy(description = description)
|
||||
api.updateWordList(updatedList.permalink, updatedList, auth.token)
|
||||
|
||||
api.getWordListByPermalink(updatedList.permalink, auth.token) match {
|
||||
case Some(list) => list.description should be(description)
|
||||
case None => fail("didn't update word list")
|
||||
}
|
||||
}
|
||||
|
||||
it should "add words to a list" in {
|
||||
val wordsToAdd = List(
|
||||
StringValue("delicious"),
|
||||
StringValue("tasty"),
|
||||
StringValue("scrumptious")
|
||||
)
|
||||
|
||||
api.addWordsToWordList(sampleList.permalink, wordsToAdd, auth.token)
|
||||
}
|
||||
|
||||
it should "get word list words" in {
|
||||
api.getWordListWords(sampleList.permalink, auth.token) match {
|
||||
case Some(words) => {
|
||||
((words.map(w => w.word)).toSet & Set("delicious", "tasty", "scrumptious")).size should be(3)
|
||||
}
|
||||
case None => fail("didn't get word list")
|
||||
}
|
||||
}
|
||||
|
||||
it should "remove words from a list" in {
|
||||
val wordsToRemove = List(
|
||||
StringValue("delicious"),
|
||||
StringValue("tasty")
|
||||
)
|
||||
|
||||
api.deleteWordsFromWordList(sampleList.permalink, wordsToRemove, auth.token)
|
||||
api.getWordListWords(sampleList.permalink, auth.token).get.size should be(1)
|
||||
}
|
||||
|
||||
it should "delete a word list" in {
|
||||
api.deleteWordList(sampleList.permalink, auth.token)
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class WordsApiTest extends FlatSpec with Matchers with BaseApiTest {
|
||||
behavior of "WordsApi"
|
||||
val api = new WordsApi
|
||||
|
||||
api.addHeader("api_key", API_KEY)
|
||||
|
||||
it should "search words by path" in {
|
||||
api.searchWords("ca", null, null) match {
|
||||
case Some(words) => {
|
||||
words should not be (null)
|
||||
words.searchResults(0).word should be("ca")
|
||||
words.searchResults.size should be(11)
|
||||
words.totalResults should not be (0)
|
||||
}
|
||||
case None => fail("didn't find word cat")
|
||||
}
|
||||
}
|
||||
|
||||
it should "get word of the day" in {
|
||||
api.getWordOfTheDay(null) match {
|
||||
case Some(wotd) => {
|
||||
wotd.word should not be (null)
|
||||
}
|
||||
case None => fail("didn't get wotd")
|
||||
}
|
||||
}
|
||||
|
||||
it should "call the reverse dictionary" in {
|
||||
api.reverseDictionary("hairy", null, null, null, null, null, null, null, null) match {
|
||||
case Some(search) => {
|
||||
search.totalResults should not be (0)
|
||||
search.results.size should not be (0)
|
||||
}
|
||||
case None => fail("failed to get words")
|
||||
}
|
||||
}
|
||||
|
||||
it should "get 10 random words" in {
|
||||
api.getRandomWords(null, null, null, null) match {
|
||||
case Some(words) => {
|
||||
words.size should be(10)
|
||||
}
|
||||
case None => fail("didn't get random words")
|
||||
}
|
||||
}
|
||||
|
||||
it should "get one random words" in {
|
||||
api.getRandomWord(null, null) match {
|
||||
case Some(word) => {
|
||||
word should not be (null)
|
||||
}
|
||||
case None => fail("didn't get random word")
|
||||
}
|
||||
}
|
||||
}
|
@ -1,230 +0,0 @@
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.wordnik</groupId>
|
||||
<artifactId>swagger-client</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>swagger-client</name>
|
||||
<version>1.0.0</version>
|
||||
<prerequisites>
|
||||
<maven>2.2.0</maven>
|
||||
</prerequisites>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>maven-mongodb-plugin-repo</id>
|
||||
<name>maven mongodb plugin repository</name>
|
||||
<url>http://maven-mongodb-plugin.googlecode.com/svn/maven/repo</url>
|
||||
<layout>default</layout>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12</version>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>loggerPath</name>
|
||||
<value>conf/log4j.properties</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
<argLine>-Xms512m -Xmx1500m</argLine>
|
||||
<parallel>methods</parallel>
|
||||
<forkMode>pertest</forkMode>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- attach test jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add_sources</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>
|
||||
src/main/java
|
||||
</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>add_test_sources</id>
|
||||
<phase>generate-test-sources</phase>
|
||||
<goals>
|
||||
<goal>add-test-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>
|
||||
src/test/java
|
||||
</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>
|
||||
1.6
|
||||
</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>net.alchim31.maven</groupId>
|
||||
<artifactId>scala-maven-plugin</artifactId>
|
||||
<version>${scala-maven-plugin-version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>scala-compile-first</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>scala-test-compile</id>
|
||||
<phase>process-test-resources</phase>
|
||||
<goals>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<args>
|
||||
<arg>-feature</arg>
|
||||
</args>
|
||||
<jvmArgs>
|
||||
<jvmArg>-Xms128m</jvmArg>
|
||||
<jvmArg>-Xmx1500m</jvmArg>
|
||||
</jvmArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.scala-tools</groupId>
|
||||
<artifactId>maven-scala-plugin</artifactId>
|
||||
<configuration>
|
||||
<scalaVersion>${scala-version}</scalaVersion>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.scala-lang</groupId>
|
||||
<artifactId>scala-library</artifactId>
|
||||
<version>${scala-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.wordnik</groupId>
|
||||
<artifactId>swagger-core</artifactId>
|
||||
<version>${swagger-core-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.scalatest</groupId>
|
||||
<artifactId>scalatest_2.10</artifactId>
|
||||
<version>${scala-test-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${joda-time-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.joda</groupId>
|
||||
<artifactId>joda-convert</artifactId>
|
||||
<version>${joda-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.typesafe</groupId>
|
||||
<artifactId>config</artifactId>
|
||||
<version>1.2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.typesafe.akka</groupId>
|
||||
<artifactId>akka-actor_2.10</artifactId>
|
||||
<version>${akka-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.spray</groupId>
|
||||
<artifactId>spray-client</artifactId>
|
||||
<version>${spray-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json4s</groupId>
|
||||
<artifactId>json4s-jackson_2.10</artifactId>
|
||||
<version>${json4s-jackson-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<scala-version>2.10.4</scala-version>
|
||||
<json4s-jackson-version>3.2.11</json4s-jackson-version>
|
||||
<json4s-ext-version>3.2.11</json4s-ext-version>
|
||||
<spray-version>1.3.1</spray-version>
|
||||
<akka-version>2.3.9</akka-version>
|
||||
<joda-version>1.2</joda-version>
|
||||
<joda-time-version>2.2</joda-time-version>
|
||||
<swagger-core-version>1.5.0-M1</swagger-core-version>
|
||||
<maven-plugin.version>1.0.0</maven-plugin.version>
|
||||
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<scala-maven-plugin-version>3.1.5</scala-maven-plugin-version>
|
||||
<scala-test-version>2.1.3</scala-test-version>
|
||||
</properties>
|
||||
</project>
|
@ -1,24 +0,0 @@
|
||||
io.swagger.client {
|
||||
|
||||
apiRequest {
|
||||
|
||||
compression {
|
||||
enabled: false
|
||||
size-threshold: 0
|
||||
}
|
||||
|
||||
trust-certificates: true
|
||||
|
||||
connection-timeout: 5000ms
|
||||
|
||||
default-headers {
|
||||
"userAgent": "swagger-client_1.0.0"
|
||||
}
|
||||
|
||||
// let you define custom http status code, as in :
|
||||
// { code: 601, reason: "some custom http status code", success: false }
|
||||
custom-codes: []
|
||||
}
|
||||
}
|
||||
|
||||
spray.can.host-connector.max-redirects = 10
|
@ -1,100 +0,0 @@
|
||||
package io.swagger.client.api
|
||||
|
||||
object AccountApi {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : ApiTokenStatus (Usage statistics for the supplied API key)
|
||||
* code 400 : (No token supplied.)
|
||||
* code 404 : (No API account with supplied token.)
|
||||
*
|
||||
* @param apiKey Wordnik authentication token
|
||||
*/
|
||||
def getApiTokenStatus(apiKey: Option[String] = None): ApiRequest[ApiTokenStatus] =
|
||||
ApiRequest[ApiTokenStatus](ApiMethods.GET, "https://api.wordnik.com/v4", "/account.json/apiTokenStatus", "application/json")
|
||||
.withHeaderParam("api_key", apiKey)
|
||||
.withSuccessResponse[ApiTokenStatus](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
.withErrorResponse[Unit](404)
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : AuthenticationToken (A valid authentication token)
|
||||
* code 403 : (Account not available.)
|
||||
* code 404 : (User not found.)
|
||||
*
|
||||
* @param username A confirmed Wordnik username
|
||||
* @param password The user's password
|
||||
*/
|
||||
def authenticate(username: String, password: String): ApiRequest[AuthenticationToken] =
|
||||
ApiRequest[AuthenticationToken](ApiMethods.GET, "https://api.wordnik.com/v4", "/account.json/authenticate/{username}", "application/json")
|
||||
.withQueryParam("password", password)
|
||||
.withPathParam("username", username)
|
||||
.withSuccessResponse[AuthenticationToken](200)
|
||||
.withErrorResponse[Unit](403)
|
||||
.withErrorResponse[Unit](404)
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : AuthenticationToken (A valid authentication token)
|
||||
* code 403 : (Account not available.)
|
||||
* code 404 : (User not found.)
|
||||
*
|
||||
* @param username A confirmed Wordnik username
|
||||
* @param body The user's password
|
||||
*/
|
||||
def authenticatePost(username: String, body: String): ApiRequest[AuthenticationToken] =
|
||||
ApiRequest[AuthenticationToken](ApiMethods.POST, "https://api.wordnik.com/v4", "/account.json/authenticate/{username}", "application/json")
|
||||
.withBody(body)
|
||||
.withPathParam("username", username)
|
||||
.withSuccessResponse[AuthenticationToken](200)
|
||||
.withErrorResponse[Unit](403)
|
||||
.withErrorResponse[Unit](404)
|
||||
|
||||
/**
|
||||
* Requires a valid auth_token to be set.
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : User (The logged-in user)
|
||||
* code 403 : (Not logged in.)
|
||||
* code 404 : (User not found.)
|
||||
*
|
||||
* @param authToken The auth token of the logged-in user, obtained by calling /account.json/authenticate/{username} (described above)
|
||||
*/
|
||||
def getLoggedInUser(authToken: String): ApiRequest[User] =
|
||||
ApiRequest[User](ApiMethods.GET, "https://api.wordnik.com/v4", "/account.json/user", "application/json")
|
||||
.withHeaderParam("auth_token", authToken)
|
||||
.withSuccessResponse[User](200)
|
||||
.withErrorResponse[Unit](403)
|
||||
.withErrorResponse[Unit](404)
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : Seq[WordList] (success)
|
||||
* code 403 : (Not authenticated.)
|
||||
* code 404 : (User account not found.)
|
||||
*
|
||||
* @param authToken auth_token of logged-in user
|
||||
* @param skip Results to skip
|
||||
* @param limit Maximum number of results to return
|
||||
*/
|
||||
def getWordListsForLoggedInUser(authToken: String, skip: Option[Int] = None, limit: Option[Int] = None): ApiRequest[Seq[WordList]] =
|
||||
ApiRequest[Seq[WordList]](ApiMethods.GET, "https://api.wordnik.com/v4", "/account.json/wordLists", "application/json")
|
||||
.withQueryParam("skip", skip)
|
||||
.withQueryParam("limit", limit)
|
||||
.withHeaderParam("auth_token", authToken)
|
||||
.withSuccessResponse[Seq[WordList]](200)
|
||||
.withErrorResponse[Unit](403)
|
||||
.withErrorResponse[Unit](404)
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,37 +0,0 @@
|
||||
package io.swagger.client.api
|
||||
|
||||
import scala.reflect.ClassTag
|
||||
|
||||
object EnumsSerializers {
|
||||
|
||||
def all = Seq[Serializer[_]]()
|
||||
|
||||
|
||||
private class EnumNameSerializer[E <: Enumeration : ClassTag](enum: E)
|
||||
extends Serializer[E#Value] {
|
||||
|
||||
val EnumerationClass = classOf[E#Value]
|
||||
|
||||
def deserialize(implicit format: Formats):
|
||||
PartialFunction[(TypeInfo, JValue), E#Value] = {
|
||||
case (t@TypeInfo(EnumerationClass, _), json) if isValid(json) => {
|
||||
json match {
|
||||
case JString(value) =>
|
||||
enum.withName(value)
|
||||
case value =>
|
||||
throw new MappingException(s"Can't convert $value to $EnumerationClass")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private[this] def isValid(json: JValue) = json match {
|
||||
case JString(value) if enum.values.exists(_.toString == value) => true
|
||||
case _ => false
|
||||
}
|
||||
|
||||
def serialize(implicit format: Formats): PartialFunction[Any, JValue] = {
|
||||
case i: E#Value => i.toString
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,242 +0,0 @@
|
||||
package io.swagger.client.api
|
||||
|
||||
object WordApi {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : WordObject (success)
|
||||
* code 400 : (Invalid word supplied.)
|
||||
*
|
||||
* @param word String value of WordObject to return
|
||||
* @param useCanonical If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
* @param includeSuggestions Return suggestions (for correct spelling, case variants, etc.)
|
||||
*/
|
||||
def getWord(word: String, useCanonical: Option[String] = None, includeSuggestions: Option[String] = None): ApiRequest[WordObject] =
|
||||
ApiRequest[WordObject](ApiMethods.GET, "https://api.wordnik.com/v4", "/word.json/{word}", "application/json")
|
||||
.withQueryParam("useCanonical", useCanonical)
|
||||
.withQueryParam("includeSuggestions", includeSuggestions)
|
||||
.withPathParam("word", word)
|
||||
.withSuccessResponse[WordObject](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
|
||||
/**
|
||||
* The metadata includes a time-expiring fileUrl which allows reading the audio file directly from the API. Currently only audio pronunciations from the American Heritage Dictionary in mp3 format are supported.
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : Seq[AudioFile] (success)
|
||||
* code 400 : (Invalid word supplied.)
|
||||
*
|
||||
* @param word Word to get audio for.
|
||||
* @param useCanonical Use the canonical form of the word
|
||||
* @param limit Maximum number of results to return
|
||||
*/
|
||||
def getAudio(word: String, useCanonical: Option[String] = None, limit: Option[Int] = None): ApiRequest[Seq[AudioFile]] =
|
||||
ApiRequest[Seq[AudioFile]](ApiMethods.GET, "https://api.wordnik.com/v4", "/word.json/{word}/audio", "application/json")
|
||||
.withQueryParam("useCanonical", useCanonical)
|
||||
.withQueryParam("limit", limit)
|
||||
.withPathParam("word", word)
|
||||
.withSuccessResponse[Seq[AudioFile]](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : Seq[Definition] (success)
|
||||
* code 400 : (Invalid word supplied.)
|
||||
* code 404 : (No definitions found.)
|
||||
*
|
||||
* @param word Word to return definitions for
|
||||
* @param limit Maximum number of results to return
|
||||
* @param partOfSpeech CSV list of part-of-speech types
|
||||
* @param includeRelated Return related words with definitions
|
||||
* @param sourceDictionaries Source dictionary to return definitions from. If 'all' is received, results are returned from all sources. If multiple values are received (e.g. 'century,wiktionary'), results are returned from the first specified dictionary that has definitions. If left blank, results are returned from the first dictionary that has definitions. By default, dictionaries are searched in this order: ahd, wiktionary, webster, century, wordnet
|
||||
* @param useCanonical If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
* @param includeTags Return a closed set of XML tags in response
|
||||
*/
|
||||
def getDefinitions(word: String, limit: Option[Int] = None, partOfSpeech: Option[String] = None, includeRelated: Option[String] = None, sourceDictionaries: Seq[String], useCanonical: Option[String] = None, includeTags: Option[String] = None): ApiRequest[Seq[Definition]] =
|
||||
ApiRequest[Seq[Definition]](ApiMethods.GET, "https://api.wordnik.com/v4", "/word.json/{word}/definitions", "application/json")
|
||||
.withQueryParam("limit", limit)
|
||||
.withQueryParam("partOfSpeech", partOfSpeech)
|
||||
.withQueryParam("includeRelated", includeRelated)
|
||||
.withQueryParam("sourceDictionaries", ArrayValues(sourceDictionaries, CSV))
|
||||
.withQueryParam("useCanonical", useCanonical)
|
||||
.withQueryParam("includeTags", includeTags)
|
||||
.withPathParam("word", word)
|
||||
.withSuccessResponse[Seq[Definition]](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
.withErrorResponse[Unit](404)
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : Seq[String] (success)
|
||||
* code 400 : (Invalid word supplied.)
|
||||
* code 404 : (No definitions found.)
|
||||
*
|
||||
* @param word Word to return
|
||||
* @param useCanonical If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
*/
|
||||
def getEtymologies(word: String, useCanonical: Option[String] = None): ApiRequest[Seq[String]] =
|
||||
ApiRequest[Seq[String]](ApiMethods.GET, "https://api.wordnik.com/v4", "/word.json/{word}/etymologies", "application/json")
|
||||
.withQueryParam("useCanonical", useCanonical)
|
||||
.withPathParam("word", word)
|
||||
.withSuccessResponse[Seq[String]](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
.withErrorResponse[Unit](404)
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : (success)
|
||||
* code 400 : (Invalid word supplied.)
|
||||
*
|
||||
* @param word Word to return examples for
|
||||
* @param includeDuplicates Show duplicate examples from different sources
|
||||
* @param useCanonical If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
* @param skip Results to skip
|
||||
* @param limit Maximum number of results to return
|
||||
*/
|
||||
def getExamples(word: String, includeDuplicates: Option[String] = None, useCanonical: Option[String] = None, skip: Option[Int] = None, limit: Option[Int] = None): ApiRequest[Unit] =
|
||||
ApiRequest[Unit](ApiMethods.GET, "https://api.wordnik.com/v4", "/word.json/{word}/examples", "application/json")
|
||||
.withQueryParam("includeDuplicates", includeDuplicates)
|
||||
.withQueryParam("useCanonical", useCanonical)
|
||||
.withQueryParam("skip", skip)
|
||||
.withQueryParam("limit", limit)
|
||||
.withPathParam("word", word)
|
||||
.withSuccessResponse[Unit](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : FrequencySummary (success)
|
||||
* code 400 : (Invalid word supplied.)
|
||||
* code 404 : (No results.)
|
||||
*
|
||||
* @param word Word to return
|
||||
* @param useCanonical If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
* @param startYear Starting Year
|
||||
* @param endYear Ending Year
|
||||
*/
|
||||
def getWordFrequency(word: String, useCanonical: Option[String] = None, startYear: Option[Int] = None, endYear: Option[Int] = None): ApiRequest[FrequencySummary] =
|
||||
ApiRequest[FrequencySummary](ApiMethods.GET, "https://api.wordnik.com/v4", "/word.json/{word}/frequency", "application/json")
|
||||
.withQueryParam("useCanonical", useCanonical)
|
||||
.withQueryParam("startYear", startYear)
|
||||
.withQueryParam("endYear", endYear)
|
||||
.withPathParam("word", word)
|
||||
.withSuccessResponse[FrequencySummary](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
.withErrorResponse[Unit](404)
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : (success)
|
||||
* code 400 : (Invalid word supplied.)
|
||||
*
|
||||
* @param word Word to get syllables for
|
||||
* @param useCanonical If true will try to return a correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
* @param sourceDictionary Get from a single dictionary. Valid options: ahd, century, wiktionary, webster, and wordnet.
|
||||
* @param limit Maximum number of results to return
|
||||
*/
|
||||
def getHyphenation(word: String, useCanonical: Option[String] = None, sourceDictionary: Option[String] = None, limit: Option[Int] = None): ApiRequest[Unit] =
|
||||
ApiRequest[Unit](ApiMethods.GET, "https://api.wordnik.com/v4", "/word.json/{word}/hyphenation", "application/json")
|
||||
.withQueryParam("useCanonical", useCanonical)
|
||||
.withQueryParam("sourceDictionary", sourceDictionary)
|
||||
.withQueryParam("limit", limit)
|
||||
.withPathParam("word", word)
|
||||
.withSuccessResponse[Unit](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : Seq[Bigram] (success)
|
||||
* code 400 : (Invalid word supplied.)
|
||||
*
|
||||
* @param word Word to fetch phrases for
|
||||
* @param limit Maximum number of results to return
|
||||
* @param wlmi Minimum WLMI for the phrase
|
||||
* @param useCanonical If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
*/
|
||||
def getPhrases(word: String, limit: Option[Int] = None, wlmi: Option[Int] = None, useCanonical: Option[String] = None): ApiRequest[Seq[Bigram]] =
|
||||
ApiRequest[Seq[Bigram]](ApiMethods.GET, "https://api.wordnik.com/v4", "/word.json/{word}/phrases", "application/json")
|
||||
.withQueryParam("limit", limit)
|
||||
.withQueryParam("wlmi", wlmi)
|
||||
.withQueryParam("useCanonical", useCanonical)
|
||||
.withPathParam("word", word)
|
||||
.withSuccessResponse[Seq[Bigram]](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : (success)
|
||||
* code 400 : (Invalid word supplied.)
|
||||
*
|
||||
* @param word Word to get pronunciations for
|
||||
* @param useCanonical If true will try to return a correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
* @param sourceDictionary Get from a single dictionary
|
||||
* @param typeFormat Text pronunciation type
|
||||
* @param limit Maximum number of results to return
|
||||
*/
|
||||
def getTextPronunciations(word: String, useCanonical: Option[String] = None, sourceDictionary: Option[String] = None, typeFormat: Option[String] = None, limit: Option[Int] = None): ApiRequest[Unit] =
|
||||
ApiRequest[Unit](ApiMethods.GET, "https://api.wordnik.com/v4", "/word.json/{word}/pronunciations", "application/json")
|
||||
.withQueryParam("useCanonical", useCanonical)
|
||||
.withQueryParam("sourceDictionary", sourceDictionary)
|
||||
.withQueryParam("typeFormat", typeFormat)
|
||||
.withQueryParam("limit", limit)
|
||||
.withPathParam("word", word)
|
||||
.withSuccessResponse[Unit](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : (success)
|
||||
* code 400 : (Invalid word supplied.)
|
||||
*
|
||||
* @param word Word to fetch relationships for
|
||||
* @param useCanonical If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
* @param relationshipTypes Limits the total results per type of relationship type
|
||||
* @param limitPerRelationshipType Restrict to the supplied relationship types
|
||||
*/
|
||||
def getRelatedWords(word: String, useCanonical: Option[String] = None, relationshipTypes: Option[String] = None, limitPerRelationshipType: Option[Int] = None): ApiRequest[Unit] =
|
||||
ApiRequest[Unit](ApiMethods.GET, "https://api.wordnik.com/v4", "/word.json/{word}/relatedWords", "application/json")
|
||||
.withQueryParam("useCanonical", useCanonical)
|
||||
.withQueryParam("relationshipTypes", relationshipTypes)
|
||||
.withQueryParam("limitPerRelationshipType", limitPerRelationshipType)
|
||||
.withPathParam("word", word)
|
||||
.withSuccessResponse[Unit](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : Example (success)
|
||||
* code 400 : (Invalid word supplied.)
|
||||
*
|
||||
* @param word Word to fetch examples for
|
||||
* @param useCanonical If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.
|
||||
*/
|
||||
def getTopExample(word: String, useCanonical: Option[String] = None): ApiRequest[Example] =
|
||||
ApiRequest[Example](ApiMethods.GET, "https://api.wordnik.com/v4", "/word.json/{word}/topExample", "application/json")
|
||||
.withQueryParam("useCanonical", useCanonical)
|
||||
.withPathParam("word", word)
|
||||
.withSuccessResponse[Example](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,147 +0,0 @@
|
||||
package io.swagger.client.api
|
||||
|
||||
object WordListApi {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : WordList (success)
|
||||
* code 400 : (Invalid ID supplied)
|
||||
* code 403 : (Not Authorized to access WordList)
|
||||
* code 404 : (WordList not found)
|
||||
*
|
||||
* @param permalink permalink of WordList to fetch
|
||||
* @param authToken The auth token of the logged-in user, obtained by calling /account.json/authenticate/{username} (described above)
|
||||
*/
|
||||
def getWordListByPermalink(permalink: String, authToken: String): ApiRequest[WordList] =
|
||||
ApiRequest[WordList](ApiMethods.GET, "https://api.wordnik.com/v4", "/wordList.json/{permalink}", "application/json")
|
||||
.withPathParam("permalink", permalink)
|
||||
.withHeaderParam("auth_token", authToken)
|
||||
.withSuccessResponse[WordList](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
.withErrorResponse[Unit](403)
|
||||
.withErrorResponse[Unit](404)
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : (success)
|
||||
* code 400 : (Invalid ID supplied)
|
||||
* code 403 : (Not Authorized to update WordList)
|
||||
* code 404 : (WordList not found)
|
||||
*
|
||||
* @param permalink permalink of WordList to update
|
||||
* @param body Updated WordList
|
||||
* @param authToken The auth token of the logged-in user, obtained by calling /account.json/authenticate/{username} (described above)
|
||||
*/
|
||||
def updateWordList(permalink: String, body: Option[WordList] = None, authToken: String): ApiRequest[Unit] =
|
||||
ApiRequest[Unit](ApiMethods.PUT, "https://api.wordnik.com/v4", "/wordList.json/{permalink}", "application/json")
|
||||
.withBody(body)
|
||||
.withPathParam("permalink", permalink)
|
||||
.withHeaderParam("auth_token", authToken)
|
||||
.withSuccessResponse[Unit](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
.withErrorResponse[Unit](403)
|
||||
.withErrorResponse[Unit](404)
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : (success)
|
||||
* code 400 : (Invalid ID supplied)
|
||||
* code 403 : (Not Authorized to delete WordList)
|
||||
* code 404 : (WordList not found)
|
||||
*
|
||||
* @param permalink ID of WordList to delete
|
||||
* @param authToken The auth token of the logged-in user, obtained by calling /account.json/authenticate/{username} (described above)
|
||||
*/
|
||||
def deleteWordList(permalink: String, authToken: String): ApiRequest[Unit] =
|
||||
ApiRequest[Unit](ApiMethods.DELETE, "https://api.wordnik.com/v4", "/wordList.json/{permalink}", "application/json")
|
||||
.withPathParam("permalink", permalink)
|
||||
.withHeaderParam("auth_token", authToken)
|
||||
.withSuccessResponse[Unit](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
.withErrorResponse[Unit](403)
|
||||
.withErrorResponse[Unit](404)
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : (success)
|
||||
* code 400 : (Invalid permalink supplied)
|
||||
* code 403 : (Not Authorized to modify WordList)
|
||||
* code 404 : (WordList not found)
|
||||
*
|
||||
* @param permalink permalink of WordList to use
|
||||
* @param body Words to remove from WordList
|
||||
* @param authToken The auth token of the logged-in user, obtained by calling /account.json/authenticate/{username} (described above)
|
||||
*/
|
||||
def deleteWordsFromWordList(permalink: String, body: Seq[StringValue], authToken: String): ApiRequest[Unit] =
|
||||
ApiRequest[Unit](ApiMethods.POST, "https://api.wordnik.com/v4", "/wordList.json/{permalink}/deleteWords", "application/json")
|
||||
.withBody(body)
|
||||
.withPathParam("permalink", permalink)
|
||||
.withHeaderParam("auth_token", authToken)
|
||||
.withSuccessResponse[Unit](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
.withErrorResponse[Unit](403)
|
||||
.withErrorResponse[Unit](404)
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : (success)
|
||||
* code 400 : (Invalid ID supplied)
|
||||
* code 403 : (Not Authorized to access WordList)
|
||||
* code 404 : (WordList not found)
|
||||
*
|
||||
* @param permalink ID of WordList to use
|
||||
* @param sortBy Field to sort by
|
||||
* @param sortOrder Direction to sort
|
||||
* @param skip Results to skip
|
||||
* @param limit Maximum number of results to return
|
||||
* @param authToken The auth token of the logged-in user, obtained by calling /account.json/authenticate/{username} (described above)
|
||||
*/
|
||||
def getWordListWords(permalink: String, sortBy: Option[String] = None, sortOrder: Option[String] = None, skip: Option[Int] = None, limit: Option[Int] = None, authToken: String): ApiRequest[Unit] =
|
||||
ApiRequest[Unit](ApiMethods.GET, "https://api.wordnik.com/v4", "/wordList.json/{permalink}/words", "application/json")
|
||||
.withQueryParam("sortBy", sortBy)
|
||||
.withQueryParam("sortOrder", sortOrder)
|
||||
.withQueryParam("skip", skip)
|
||||
.withQueryParam("limit", limit)
|
||||
.withPathParam("permalink", permalink)
|
||||
.withHeaderParam("auth_token", authToken)
|
||||
.withSuccessResponse[Unit](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
.withErrorResponse[Unit](403)
|
||||
.withErrorResponse[Unit](404)
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : (success)
|
||||
* code 400 : (Invalid permalink supplied)
|
||||
* code 403 : (Not Authorized to access WordList)
|
||||
* code 404 : (WordList not found)
|
||||
*
|
||||
* @param permalink permalink of WordList to user
|
||||
* @param body Array of words to add to WordList
|
||||
* @param authToken The auth token of the logged-in user, obtained by calling /account.json/authenticate/{username} (described above)
|
||||
*/
|
||||
def addWordsToWordList(permalink: String, body: Seq[StringValue], authToken: String): ApiRequest[Unit] =
|
||||
ApiRequest[Unit](ApiMethods.POST, "https://api.wordnik.com/v4", "/wordList.json/{permalink}/words", "application/json")
|
||||
.withBody(body)
|
||||
.withPathParam("permalink", permalink)
|
||||
.withHeaderParam("auth_token", authToken)
|
||||
.withSuccessResponse[Unit](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
.withErrorResponse[Unit](403)
|
||||
.withErrorResponse[Unit](404)
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,28 +0,0 @@
|
||||
package io.swagger.client.api
|
||||
|
||||
object WordListsApi {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Expected answers:
|
||||
* code 200 : WordList (success)
|
||||
* code 400 : (Invalid WordList supplied or mandatory fields are missing)
|
||||
* code 403 : (Not authenticated)
|
||||
* code 404 : (WordList owner not found)
|
||||
*
|
||||
* @param body WordList to create
|
||||
* @param authToken The auth token of the logged-in user, obtained by calling /account.json/authenticate/{username} (described above)
|
||||
*/
|
||||
def createWordList(body: Option[WordList] = None, authToken: String): ApiRequest[WordList] =
|
||||
ApiRequest[WordList](ApiMethods.POST, "https://api.wordnik.com/v4", "/wordLists.json", "application/json")
|
||||
.withBody(body)
|
||||
.withHeaderParam("auth_token", authToken)
|
||||
.withSuccessResponse[WordList](200)
|
||||
.withErrorResponse[Unit](400)
|
||||
.withErrorResponse[Unit](403)
|
||||
.withErrorResponse[Unit](404)
|
||||
|
||||
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user