Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added readme, sample

  • Loading branch information...
commit f5fae2df48a4d8b56243c51b7278021e157c974c 1 parent adbadfe
@fehguy fehguy authored
View
32 samples/client/wordnik-api/objc/README.md
@@ -0,0 +1,32 @@
+# Wordnik Objective-C client library
+
+## Overview
+This is a full client library for the Wordnik API. It requires that you have a valid Wordnik API Key--you
+can get one for free at http://developer.wordnik.com.
+
+This library is built using the Wordnik [Swagger](http://swagger.wordnik.com) client library generator. You
+can re-generate this library by running ./bin/objc-wordnik-api.sh from the swagger-codegen project
+
+## Usage
+There is a simple hello world example here: (WordnikApiClient/main.m)
+
+It is recommended that you review the OCUnit tests to see how to use the library. They live under the
+[Tests](tests) directory and require that you enter your API_KEY, as well as a username
+and password to authenticate with. To do this:
+
+* Choose "Product/Manage Schemes"
+
+* Highlight "WordnikApiTests", click "Edit"
+
+* Select "Test" on the left panel and add (or update the placeholder) environment variable for API_KEY, USER_NAME, PASSWORD
+
+* Dismiss and run the tests
+
+
+## Requirements
+You need a valid Wordnik API key to access the API--to get one, go to [Wordnik Developer](http://developer.wordnik.com) to sign up. It costs nothing!
+
+This project was built with the following minimum requirements:
+
+* iOS 5 or greater
+* ARC enabled compiler
View
BIN  ....xcodeproj/project.xcworkspace/xcuserdata/tony.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown
View
83 samples/client/wordnik-api/objc/WordnikApiClient/WordnikApiClient/main.m
@@ -1,75 +1,36 @@
#import <Foundation/Foundation.h>
#import "NIKWordApi.h"
-int main(int argc, const char * argv[])
-{
+int main(int argc, const char * argv[]) {
+ static bool done = false;
@autoreleasepool {
- static bool done = false;
-
NIKWordApi * api = [[NIKWordApi alloc] init];
- [api addHeader:@"a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5" forKey:@"api_key"];
-
- static NIKWordObject* word = nil;
- static NSError * gError = nil;
- [api getWordWithCompletionBlock:@"cat" useCanonical:@"true" includeSuggestions:@"true" completionHandler:^(NIKWordObject *output, NSError *error) {
- if(error) {
- gError = error;
+ [api addHeader:@"YOUR_API_KEY" forKey:@"api_key"];
+ [api getDefinitionsWithCompletionBlock:@"Hello World"
+ partOfSpeech:nil
+ sourceDictionaries:nil
+ limit:nil
+ includeRelated:nil
+ useCanonical:nil
+ includeTags:nil
+ completionHandler:^(NSArray * definitions, NSError * error) {
+ if(error){
+ done = true;
+ NSLog(@"failed to get results, did you forget to update the api_key?");
}
- if(output == nil){
- NSLog(@"failed to fetch pet");
+ else if(!definitions) {
+ done = true;
+ NSLog(@"no results! Did you put in an invalid word?");
}
else {
- word = [[NIKWordObject alloc] initWithValues:[output asDictionary]];
+ for(NIKDefinition * def in definitions ){
+ NSLog(@"%@", [def asDictionary]);
+ }
+ done = true;
}
}];
- NSDate * loopUntil = [NSDate dateWithTimeIntervalSinceNow:10];
- while(!done && [loopUntil timeIntervalSinceNow] > 0){
- if(gError){
- NSLog(@"got error %@", gError);
- done = true;
- }
- if(word){
- NSLog(@"word: %@", [word asDictionary]);
- done = true;
- }
- }
+ while(!done){}
}
-
return 0;
}
-
-void etys() {
- static bool done = false;
-
- NIKWordApi * api = [[NIKWordApi alloc] init];
- [api addHeader:@"a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5" forKey:@"api_key"];
-
- static NSArray* etys = nil;
- static NSError * gError = nil;
-
- [api getEtymologiesWithCompletionBlock:@"catalog" useCanonical:@"false" completionHandler:^(NSArray *output, NSError *error) {
- if(error) {
- gError = error;
- }
- if(output == nil){
- NSLog(@"failed to fetch pet");
- }
- else {
- etys = [[NSArray alloc] initWithArray:output];
- }
- }];
-
- NSDate * loopUntil = [NSDate dateWithTimeIntervalSinceNow:10];
- while(!done && [loopUntil timeIntervalSinceNow] > 0){
- if(gError){
- NSLog(@"got error %@", gError);
- done = true;
- }
- if(etys){
- NSLog(@"etys: %@", etys);
- done = true;
- }
- }
-}
-
Please sign in to comment.
Something went wrong with that request. Please try again.