wordnik 1.0.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 50

wordnik

Wordnik API for Dart

All object models and API calls have been implemented, but with minimal testing. API signatures are likely to change until fully tested.

Basic usage

import 'package:wordnik/wordnik.dart';

void main() async {

  Wordnik wordnik = Wordnik('YOUR_API_KEY');

  WordObject randomWord = await wordnik.getRandomWord(
    includePartOfSpeech: 'verb',
    minLength: 6,
    maxLength: 10
  );

  print(randomWord.word);

}

v1.0.0 - 2018-08-08

  • Updated to fully support Dart 2
  • Upgraded json_seralizable and updated object models to use the new default of generated ToJson methods instead of Mixins
  • Removed an unused class and added a missing internal class
  • Added a missing API call (getScrabbleScore)
  • Updated the example and documentation

v0.4.0 - 2018-07-25

  • Completed documentation for API calls
  • API calls that used CSV strings were changed to use List<String>
  • Multiple other API call parameters have been modified to work in a more sensible way
  • Renamed ApiTokenStatus to ApiKeyStatus
  • Added enums for use in the API calls that require them

v0.3.3 - 2018-07-15

  • Added an ApiException which is now thrown when the API returns an error
  • Modified deleteWordsFromWordList() and addWordsToWordList() to take List<String> instead of List<StringValue>
  • StringValue is no longer exposed as it is now only used internally
  • Completed documentation for account, wordList, and wordLists APIs
  • Added more tests
  • Added dependency for http_status for internal use
  • Major internal refactoring and reorganization for readability/maintainability (doesn't affect public-facing API)

v0.3.2 - 2018-07-14

v0.3.1 - 2018-07-11

  • Fixed return type for getEtymologies()
  • Fixed some parameter encoding issues
  • Completed examples for all API calls
  • Documentation work continues

v0.3.0 - 2018-07-10

  • Implemented the remaining word API calls
  • Added example package (incomplete)
  • Minor internal API adjustments

v0.2.0 - 2018-07-10

  • Implemented all wordList API calls
  • Implemented getDefinitions from word API
  • Tweaked JSON serialization options for less cluttered output
  • Removed default values, for now
  • Cleaned up internal API structure

v0.1.0 - 2018-07-06

  • Initial Pub release
  • Implemented all account, wordLists, and words API calls
  • Converted all models to use json_serializable

v0.0.1 - 2018-07-03

  • Initial commit.

example/lib/example.dart

// These aren't necessary for standard operation of the API;
// they are only required for the API key import and some of the example code
import 'dart:math';
import 'package:credentials_helper/credentials_helper.dart';

// Required imports
import 'package:wordnik/wordnik.dart';

void main() async {
  Random random = Random();

  // This isn't required, but you'll need to provide the API key in some way
  Credentials credentials = Credentials.fromFile('credentials.json');

  Wordnik wordnik = Wordnik(credentials.apiKey);

  AuthenticationToken authToken = await wordnik.authenticate(credentials.username, credentials.password);
  print('Authenticated and received token "${authToken.token}".\n');

  User user = await wordnik.getLoggedInUser(authToken.token);
  print('Welcome, ${user.displayName}!\n');

  ApiKeyStatus keyStatus = await wordnik.getApiKeyStatus();
  print('You have made ${keyStatus.totalRequests} requests and have ${keyStatus.remainingCalls} remaining.');
  print('Counter will reset in ${keyStatus.resetsIn.inMinutes} minutes.\n');

  WordObject exampleWord = await wordnik.getWord('example');
  int score = await wordnik.getScrabbleScore(exampleWord.word);
  print('Got word "${exampleWord.word}".');
  print('It has a Scrabble score of $score.\n');

  List<AudioFile> audioFiles = await wordnik.getAudio(exampleWord.word);
  print('${audioFiles.length} audio results found.');
  print('The first one is: "${audioFiles.first.fileUrl}"\n');

  List<Definition> definitions = await wordnik.getDefinitions(exampleWord.word);
  print('${definitions.length} definitions found.');
  print('The first one is: "${definitions.first.text}"\n');

  List<String> etymologies = await wordnik.getEtymologies(exampleWord.word);
  print('${etymologies.length} etymologies found.');
  print('The first one is: "${etymologies.first}"\n');

  ExampleSearchResults examples = await wordnik.getExamples(exampleWord.word);
  print('${examples.examples.length} examples found.');
  print('The first one is: "${examples.examples.first.text}"\n');

  FrequencySummary frequencySummary = await wordnik.getWordFrequency(exampleWord.word);
  Frequency frequency = frequencySummary.frequency[random.nextInt(frequencySummary.frequency.length)];
  print('${frequency.count} occurances from the year ${frequency.year}\n');

  List<Syllable> syllables = await wordnik.getHyphenation(exampleWord.word);
  print('This word has ${syllables.length} syllables: ${syllables.map((s) => s.text).join('-')}\n');

  List<Bigram> bigrams = await wordnik.getPhrases(
    exampleWord.word,
    limit: 10
  );
  Bigram bigram = bigrams[random.nextInt(bigrams.length)];
  print('You might say "${bigram.gram1} ${bigram.gram2}".\n');

  List<TextPron> textProns = await wordnik.getTextPronunciations(exampleWord.word);
  TextPron textPron = textProns.first;
  print('It is pronounced "${textPron.raw}".\n');

  List<Related> relatedWords = await wordnik.getRelatedWords(
    exampleWord.word,
    relationshipTypes: ['synonym', 'rhyme']
  );
  Related synonyms = relatedWords.firstWhere((word) => word.relationshipType == 'synonym');
  Related rhymes = relatedWords.firstWhere((word) => word.relationshipType == 'rhyme');
  print('${synonyms.words.length} synonyms found, including "${synonyms.words[random.nextInt(synonyms.words.length)]}".\n');
  print('${rhymes.words.length} rhymes found, including "${rhymes.words[random.nextInt(rhymes.words.length)]}".\n');

  Example example = await wordnik.getTopExample(exampleWord.word);
  print('The top example is: "${example.text}" from ${example.title}.\n');

  WordOfTheDay wordOfTheDay = await wordnik.getWordOfTheDay();
  WordOfTheDay previousWordOfTheDay = await wordnik.getWordOfTheDay(date: DateTime.now().subtract(Duration(days: 1)));
  print('The word of the day is "${wordOfTheDay.word}".\n');
  print('Yesterday\'s word of the day was "${previousWordOfTheDay.word}".\n');

  DefinitionSearchResults reverseDictionaryResults = await wordnik.reverseDictionary('eating utensil with prongs');
  Definition reverseDictionary = reverseDictionaryResults.results.first;
  print('A word that means "eating utensil with prongs" might be "${reverseDictionary.word}".\n');

  WordSearchResults searchResults = await wordnik.searchWords(
    '.+?rong.+?',
    isRegex: true,
    skip: 1,
    limit: 1
  );
  WordSearchResult searchResult = searchResults.searchResults.first;
  print('${searchResults.totalResults} words found that contain the sequence "rong", including "${searchResult.word}".\n');

  WordObject randomNoun = await wordnik.getRandomWord(
    partsOfSpeech: PartOfSpeechOptions(noun: true, nounPlural: false, nounPosessive: false, properNoun: false, properNounPlural: false, properNounPosessive: false, givenName: false, familyName: false),
    minLength: 5,
    maxLength: 7
  );
  print('Got random noun "${randomNoun.word}".\n');

  List<WordObject> randomAdjectives = await wordnik.getRandomWords(
    partsOfSpeech: PartOfSpeechOptions(adjective: true),
    minLength: 5,
    maxLength: 7,
    limit: 3
  );
  print('Got random adjectives: ${randomAdjectives.map((adjective) => adjective.word).join(', ')}\n');

  WordList newWordList = WordList(
    'Temporary Example List',
    'PRIVATE',
    description: 'Created by the Wordnik API for Dart.'
  );
  WordList createdWordList = await wordnik.createWordList(
    authToken.token,
    newWordList
  );
  print('New word list "${createdWordList.name}" created with permalink "${createdWordList.permalink}".\n');

  List<String> wordsToAdd = List<String>()
    ..add(exampleWord.word)
    ..add(randomNoun.word)
    ..addAll(randomAdjectives.map((word) => word.word));
  await wordnik.addWordsToWordList(
    authToken.token,
    createdWordList.permalink,
    wordsToAdd
  );
  print('Added ${wordsToAdd.length} words to "${createdWordList.name}".\n');

  List<String> wordsToDelete = List<String>()
    ..add(exampleWord.word)
    ..add(randomAdjectives[random.nextInt(randomAdjectives.length)].word);
  await wordnik.deleteWordsFromWordList(
    authToken.token,
    createdWordList.permalink,
    wordsToDelete
  );
  print('Deleted ${wordsToDelete.length} words from "${createdWordList.name}".\n');

  WordList modifiedWordList = createdWordList
    ..description = 'I feel like a ${randomAdjectives[random.nextInt(randomAdjectives.length)].word} ${randomNoun.word} ${exampleWord.word}.';
  await wordnik.updateWordList(
    authToken.token,
    modifiedWordList.permalink,
    modifiedWordList
  );
  print('Updated description for "${modifiedWordList.name}".\n');

  List<WordList> userWordLists = await wordnik.getWordListsForLoggedInUser(authToken.token);
  print('Found ${userWordLists.length} word lists. The first one is titled "${userWordLists.first.name}".\n');

  WordList ourWordList = await wordnik.getWordListByPermalink(
    authToken.token,
    createdWordList.permalink
  );
  print('"${ourWordList.name}" now contains ${ourWordList.numberWordsInList} words and the description is "${ourWordList.description}".\n');

  List<WordListWord> wordListWords = await wordnik.getWordListWords(
    authToken.token,
    ourWordList.permalink
  );
  print('The words on the list are: ${wordListWords.map((word) => word.word).join(', ')}.\n');

  await wordnik.deleteWordList(
    authToken.token,
    ourWordList.permalink
  );
  print('Deleted "${ourWordList.name}".\n');
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  wordnik: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:wordnik/wordnik.dart';
  
Version Uploaded Documentation Archive
1.0.0 Aug 9, 2018 Go to the documentation of wordnik 1.0.0 Download wordnik 1.0.0 archive
0.4.0 Jul 26, 2018 Go to the documentation of wordnik 0.4.0 Download wordnik 0.4.0 archive
0.3.3 Jul 15, 2018 Go to the documentation of wordnik 0.3.3 Download wordnik 0.3.3 archive
0.3.2 Jul 14, 2018 Go to the documentation of wordnik 0.3.2 Download wordnik 0.3.2 archive
0.3.1 Jul 12, 2018 Go to the documentation of wordnik 0.3.1 Download wordnik 0.3.1 archive
0.3.0 Jul 11, 2018 Go to the documentation of wordnik 0.3.0 Download wordnik 0.3.0 archive
0.2.0 Jul 10, 2018 Go to the documentation of wordnik 0.2.0 Download wordnik 0.2.0 archive
0.1.0 Jul 7, 2018 Go to the documentation of wordnik 0.1.0 Download wordnik 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Sep 18, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.3

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:wordnik/wordnik.dart.

Suggestions

Format lib/src/api_client.dart.

Run dartfmt to format lib/src/api_client.dart.

Format lib/src/apis/account_apis.dart.

Run dartfmt to format lib/src/apis/account_apis.dart.

Format lib/src/apis/word_apis.dart.

Run dartfmt to format lib/src/apis/word_apis.dart.

Fix additional 42 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/apis/word_list_apis.dart (Run dartfmt to format lib/src/apis/word_list_apis.dart.)
  • lib/src/apis/word_lists_apis.dart (Run dartfmt to format lib/src/apis/word_lists_apis.dart.)
  • lib/src/apis/words_apis.dart (Run dartfmt to format lib/src/apis/words_apis.dart.)
  • lib/src/enums.dart (Run dartfmt to format lib/src/enums.dart.)
  • lib/src/models/api_exception.dart (Run dartfmt to format lib/src/models/api_exception.dart.)
  • lib/src/models/api_key_status.dart (Run dartfmt to format lib/src/models/api_key_status.dart.)
  • lib/src/models/audio_file.dart (Run dartfmt to format lib/src/models/audio_file.dart.)
  • lib/src/models/authentication_token.dart (Run dartfmt to format lib/src/models/authentication_token.dart.)
  • lib/src/models/bigram.dart (Run dartfmt to format lib/src/models/bigram.dart.)
  • lib/src/models/category.dart (Run dartfmt to format lib/src/models/category.dart.)
  • lib/src/models/citation.dart (Run dartfmt to format lib/src/models/citation.dart.)
  • lib/src/models/content_provider.dart (Run dartfmt to format lib/src/models/content_provider.dart.)
  • lib/src/models/definition.dart (Run dartfmt to format lib/src/models/definition.dart.)
  • lib/src/models/definition_search_results.dart (Run dartfmt to format lib/src/models/definition_search_results.dart.)
  • lib/src/models/example.dart (Run dartfmt to format lib/src/models/example.dart.)
  • lib/src/models/example_search_results.dart (Run dartfmt to format lib/src/models/example_search_results.dart.)
  • lib/src/models/example_usage.dart (Run dartfmt to format lib/src/models/example_usage.dart.)
  • lib/src/models/facet.dart (Run dartfmt to format lib/src/models/facet.dart.)
  • lib/src/models/facet_value.dart (Run dartfmt to format lib/src/models/facet_value.dart.)
  • lib/src/models/frequency.dart (Run dartfmt to format lib/src/models/frequency.dart.)
  • lib/src/models/frequency_summary.dart (Run dartfmt to format lib/src/models/frequency_summary.dart.)
  • lib/src/models/label.dart (Run dartfmt to format lib/src/models/label.dart.)
  • lib/src/models/long.dart (Run dartfmt to format lib/src/models/long.dart.)
  • lib/src/models/note.dart (Run dartfmt to format lib/src/models/note.dart.)
  • lib/src/models/part_of_speech.dart (Run dartfmt to format lib/src/models/part_of_speech.dart.)
  • lib/src/models/part_of_speech_options.dart (Run dartfmt to format lib/src/models/part_of_speech_options.dart.)
  • lib/src/models/related.dart (Run dartfmt to format lib/src/models/related.dart.)
  • lib/src/models/root.dart (Run dartfmt to format lib/src/models/root.dart.)
  • lib/src/models/scored_word.dart (Run dartfmt to format lib/src/models/scored_word.dart.)
  • lib/src/models/sentence.dart (Run dartfmt to format lib/src/models/sentence.dart.)
  • lib/src/models/simple_definition.dart (Run dartfmt to format lib/src/models/simple_definition.dart.)
  • lib/src/models/simple_example.dart (Run dartfmt to format lib/src/models/simple_example.dart.)
  • lib/src/models/string_value.dart (Run dartfmt to format lib/src/models/string_value.dart.)
  • lib/src/models/syllable.dart (Run dartfmt to format lib/src/models/syllable.dart.)
  • lib/src/models/text_pron.dart (Run dartfmt to format lib/src/models/text_pron.dart.)
  • lib/src/models/user.dart (Run dartfmt to format lib/src/models/user.dart.)
  • lib/src/models/word_list.dart (Run dartfmt to format lib/src/models/word_list.dart.)
  • lib/src/models/word_list_word.dart (Run dartfmt to format lib/src/models/word_list_word.dart.)
  • lib/src/models/word_object.dart (Run dartfmt to format lib/src/models/word_object.dart.)
  • lib/src/models/word_of_the_day.dart (Run dartfmt to format lib/src/models/word_of_the_day.dart.)
  • lib/src/models/word_search_result.dart (Run dartfmt to format lib/src/models/word_search_result.dart.)
  • lib/src/models/word_search_results.dart (Run dartfmt to format lib/src/models/word_search_results.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
http ^0.11.3 0.11.3+17
intl ^0.15.7 0.15.7
json_annotation ^1.0.0 1.1.0
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
http_parser 3.1.3
meta 1.1.6
path 1.6.2
source_span 1.4.1
string_scanner 1.0.4
typed_data 1.1.6
Dev dependencies
build_runner ^0.9.2
credentials_helper ^1.0.3
json_serializable ^1.0.0
test ^1.3.0