0

I'm making a swift app in Xcode that makes use of a cocapod called HNKWordLookup (originally written in objective c). This pod uses the WordNik API to return a random word. My only issue is that a lot of the words that are returned are quite obscure.

I figured that I could go to the http://developer.wordnik.com/docs page and set parameters there, and then be given a Request URL that caters to these parameters . I assume I need to put this into my code somewhere in place of another URL that is present within the pre written pod, but I have no clue where to put the request URL. At first I put it in place in the following line of code which was located in the pod's .m file ("HNKLookup.m:):

 static NSString *const kHNKLookupBaseUrl = @"http://api.wordnik.com:80/v4";

changing it to

static NSString *const kHNKLookupBaseUrl = @"http://api.wordnik.com:80/v4/words.json/randomWord?hasDictionaryDef=true&excludePartOfSpeech=definite-article&minCorpusCount=1&maxCorpusCount=-1&minDictionaryCount=30&maxDictionaryCount=-1&minLength=1&maxLength=-1&api_key=a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5";

but this broke my code. Is there a certain phrase or area that I should be looking out for within the pod where I can put my new request URL in and thus run my program with my desired parameters? As you can tell I'm pretty new to programming.

ekad
  • 14,436
  • 26
  • 44
  • 46
mBlot
  • 1
  • 1
  • Can you post the error? Possibly because the 1st one directs to an html page 2nd url gives a dictionary which the system might not be expecting. – Anup G Prasad Feb 24 '18 at 07:47
  • Sure thing, but its not going the whole thing due to character limitations. I'll upload a screenshot of the full error to imgur.Thanks `UserInfo={NSLocalizedDescription=Request failed: unauthorized (401), NSErrorFailingURLKey=[the request URL i pasted in]` https://imgur.com/a/OmCvE – mBlot Feb 24 '18 at 10:02

1 Answers1

2

You should not change kHNKLookupBaseUrl in pod. kHNKLookupBaseUrl is used to connect to the service. Use this to get a random word:

    [[HNKLookup sharedInstance] randomWordWithCompletion:^(NSString *randomWord, NSError *error) {
    if (error) {
        NSLog(@"ERROR: %@", error);
    } else {
        NSLog(@"%@", randomWord);
    }
}];

You have the parameters initialised in HNKHttpSessionManager.m

+ (NSUInteger)randomWordWithCompletion:(void (^)(NSURLSessionDataTask *, id,
                                                 NSError *))completion
{
  return
      [self startRequestWithPath:kHNKPathRandomWord
                      parameters:@{
                        @"hasDictionaryDef" :
                            @(kHNKRandomWordShouldHaveDictionaryDefinition),
                        @"minCorpusCount" : @(kHNKRandomWordMinimumCorpusCount),
                        @"maxCorpusCount" : @(kHNKRandomWordMaximumCorpusCount),
                        @"minDictionaryCount" :
                            @(kHNKRandomWordMinimumDictionaryCount),
                        @"maxDictionaryCount" :
                            @(kHNKRandomWordMaximumDictionaryCount),
                        @"minLength" : @(kHNKRandomWordMinimumLength),
                        @"maxLength" : @(kHNKRandomWordMaximumLength)
                      }
                      completion:completion];
}

You can tweak this to get desired result.

Anup G Prasad
  • 246
  • 2
  • 4
  • 14
  • wow thanks so much. I was hoping someone like you would come along and point me towards the HNKHttpSessionManager.m file where I could change the parameters. All i needed to do was change the minCorpusCount and minDictionaryCount so it was just a matter of tweaking those two. Again, thank you so much haha – mBlot Feb 24 '18 at 13:03