wordnik 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,22 +1,3 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
22
- .api-key
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in wordnik.gemspec
4
+ gemspec
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ wordnik (0.3.0)
5
+ activemodel (= 3.0.3)
6
+ addressable (= 2.2.4)
7
+ htmlentities (= 4.2.4)
8
+ json (= 1.4.6)
9
+ nokogiri (= 1.4.4)
10
+ typhoeus (= 0.2.1)
11
+
12
+ GEM
13
+ remote: http://rubygems.org/
14
+ specs:
15
+ activemodel (3.0.3)
16
+ activesupport (= 3.0.3)
17
+ builder (~> 2.1.2)
18
+ i18n (~> 0.4)
19
+ activesupport (3.0.3)
20
+ addressable (2.2.4)
21
+ builder (2.1.2)
22
+ crack (0.1.8)
23
+ diff-lcs (1.1.2)
24
+ htmlentities (4.2.4)
25
+ i18n (0.5.0)
26
+ json (1.4.6)
27
+ mime-types (1.16)
28
+ nokogiri (1.4.4)
29
+ rspec (2.4.0)
30
+ rspec-core (~> 2.4.0)
31
+ rspec-expectations (~> 2.4.0)
32
+ rspec-mocks (~> 2.4.0)
33
+ rspec-core (2.4.0)
34
+ rspec-expectations (2.4.0)
35
+ diff-lcs (~> 1.1.2)
36
+ rspec-mocks (2.4.0)
37
+ typhoeus (0.2.1)
38
+ mime-types
39
+ vcr (1.5.1)
40
+ webmock (1.6.2)
41
+ addressable (>= 2.2.2)
42
+ crack (>= 0.1.7)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ rspec (= 2.4.0)
49
+ vcr (= 1.5.1)
50
+ webmock (= 1.6.2)
51
+ wordnik!
@@ -0,0 +1,82 @@
1
+ wordnik rubygem
2
+ ===============
3
+
4
+ This is the official Wordnik rubygem. It fully wraps Wordnik's v4 API. Refer to
5
+ [developer.wordnik.com/docs](http://developer.wordnik.com/docs) to play around
6
+ in the live API sandbox. All the methods you see there are implemented in this
7
+ ruby gem.
8
+
9
+ Installation.
10
+ ------------
11
+
12
+ ### Rails 3.x
13
+
14
+ Add the wordnik gem to your Gemfile.rb:
15
+
16
+ gem 'wordnik'
17
+
18
+ Then from your project's RAILS_ROOT, run:
19
+
20
+ bundle install
21
+
22
+ Create config/initializers/wordnik.rb and drop this in:
23
+
24
+ Wordnik.configure do |config|
25
+ config.api_key = '12345abcde'
26
+ config.response_format = :json # defaults to json, but xml is also supported
27
+ end
28
+
29
+ ### Rails 2.x
30
+
31
+ Add the wordnik gem to your app. In config/environment.rb:
32
+
33
+ config.gem 'hoptoad_notifier'
34
+
35
+ Then from your project's RAILS_ROOT, run:
36
+
37
+ rake gems:install
38
+ rake gems:unpack GEM=wordnik
39
+
40
+ Create config/initializers/wordnik.rb and drop this in:
41
+
42
+ Wordnik.configure do |config|
43
+ config.api_key = '12345abcde'
44
+ config.response_format = :json # defaults to json, but xml is also supported
45
+ end
46
+
47
+ ### Sinatra/Padrino/Other
48
+
49
+ gem install wordnik
50
+
51
+ Put this somewhere in your app's initialization process:
52
+
53
+ Wordnik.configure do |config|
54
+ config.api_key = '12345abcde'
55
+ config.response_format = :json # defaults to json, but xml is also supported
56
+ end
57
+
58
+ Specs
59
+ -----
60
+
61
+ The wordnik gem uses rspec 2. To run the test suite, you have to pass in your API
62
+ key as an environment variable, like so:
63
+
64
+ KEY=12345 rake spec
65
+
66
+ Contributing
67
+ ------------
68
+
69
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
70
+ * Check out the [issue tracker](http://github.com/wordnik/wordnik-ruby/issues) to make sure someone already hasn't requested it and/or contributed it
71
+ * Fork the project
72
+ * Start a feature/bugfix branch
73
+ * Commit and push until you are happy with your contribution
74
+ * Make sure to add tests for the feature/bugfix. This is important so we don't break it in a future version unintentionally.
75
+
76
+ Props
77
+ -----
78
+
79
+ * Thanks to [Jason Adams](http://twitter.com/#!/ealdent) for graciously turning
80
+ over the [wordnik gem name](https://rubygems.org/gems/wordnik).
81
+ * HTTP requests are made using [Typhoeus](https://github.com/dbalatero/typhoeus),
82
+ a modern code version of the mythical beast with 100 serpent heads.
data/Rakefile CHANGED
@@ -1,54 +1,30 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
3
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "wordnik"
8
- gem.summary = %Q{Ruby interface to the Wordnik API}
9
- gem.description = %Q{Ruby interface to the Wordnik API. Details at http://docs.wordnik.com/api/methods.}
10
- gem.email = "jasonmadams@gmail.com"
11
- gem.homepage = "http://github.com/ealdent/wordnik"
12
- gem.authors = ["Jason Adams"]
13
- gem.add_dependency "httparty", ">= 0.4.5"
14
- gem.add_development_dependency "shoulda", ">= 0"
15
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
- end
17
- Jeweler::GemcutterTasks.new
18
- rescue LoadError
19
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
- end
4
+ require 'rspec/core/rake_task'
5
+ require 'wordnik'
21
6
 
22
- require 'rake/testtask'
23
- Rake::TestTask.new(:test) do |test|
24
- test.libs << 'lib' << 'test'
25
- test.pattern = 'test/**/test_*.rb'
26
- test.verbose = true
27
- end
7
+ RSpec::Core::RakeTask.new('spec')
28
8
 
29
- begin
30
- require 'rcov/rcovtask'
31
- Rcov::RcovTask.new do |test|
32
- test.libs << 'test'
33
- test.pattern = 'test/**/test_*.rb'
34
- test.verbose = true
35
- end
36
- rescue LoadError
37
- task :rcov do
38
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
- end
40
- end
9
+ # If you want to make this the default task
10
+ task :default => :spec
41
11
 
42
- task :test => :check_dependencies
43
12
 
44
- task :default => :test
13
+ desc 'Download the API docs to disk'
14
+ task :fetch_api_docs do
15
+
16
+ Wordnik.configure
17
+
18
+ Wordnik.resource_names.each do |resource_name|
45
19
 
46
- require 'rake/rdoctask'
47
- Rake::RDocTask.new do |rdoc|
48
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
20
+ # Roll in API key
21
+ headers = {}
22
+ # headers[:api_key] = params[:api_key] if params[:api_key].present?
49
23
 
50
- rdoc.rdoc_dir = 'rdoc'
51
- rdoc.title = "wordnik #{version}"
52
- rdoc.rdoc_files.include('README*')
53
- rdoc.rdoc_files.include('lib/**/*.rb')
54
- end
24
+ request = Wordnik::Request.new(:get, "#{resource_name}.json", :headers => headers)
25
+ filename = "api_docs/#{resource_name}.json"
26
+ File.open(filename, 'w') {|f| f.write(request.response.raw.body) }
27
+ puts filename
28
+ end
29
+
30
+ end
@@ -0,0 +1 @@
1
+ {"endPoints":[{"path":"/account.{format}/authenticate/{username}","description":"","operations":[{"parameters":[{"name":"username","description":"A confirmed Wordnik username","required":true,"paramType":"path"},{"name":"password","description":"The user's password","required":true,"paramType":"query"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"AuthenticationToken","errorResponses":[{"reason":"Account not available.","code":403},{"reason":"User not found.","code":404}],"occurs":"1","condition":"any"}],"summary":"Authenticates a User","open":false,"httpMethod":"GET"}]},{"path":"/account.{format}/apiTokenStatus","description":"","operations":[{"parameters":[{"name":"api_key","description":"Wordnik authentication token","required":true,"paramType":"header"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"ApiTokenStatus","errorResponses":[{"reason":"No token supplied.","code":400},{"reason":"No API account with supplied token.","code":404}],"occurs":"1","condition":"any"}],"summary":"Returns usage statistics for the API account.","open":true,"httpMethod":"GET"}]},{"path":"/account.{format}/authenticate/{username}","description":"","operations":[{"parameters":[{"name":"username","description":"A confirmed Wordnik username","required":true,"paramType":"path"},{"description":"The user's password","required":true,"paramType":"body"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"AuthenticationToken","errorResponses":[{"reason":"Account not available.","code":403},{"reason":"User not found.","code":404}],"occurs":"1","condition":"any"}],"summary":"Authenticates a user","open":false,"httpMethod":"POST"}]},{"path":"/account.{format}/user","description":"","operations":[{"parameters":[{"name":"auth_token","description":"The auth token of the logged-in user, obtained by calling /account.{format}/authenticate/{username} (described above)","required":true,"paramType":"header"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"User","errorResponses":[{"reason":"Not logged in.","code":403},{"reason":"User not found.","code":404}],"occurs":"1","condition":"any"}],"summary":"Returns the logged-in User","open":false,"notes":"Requires a valid auth_token to be set.","httpMethod":"GET"}]},{"path":"/account.{format}/wordLists","description":"","operations":[{"parameters":[{"name":"auth_token","description":"auth_token of logged-in user","required":true,"paramType":"header"},{"name":"skip","description":"Results to skip","required":false,"paramType":"query"},{"name":"limit","description":"Maximum number of results to return","required":false,"paramType":"query"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"WordList[]","errorResponses":[{"reason":"Not authenticated.","code":403},{"reason":"User account not found.","code":404}],"occurs":"1","condition":"any"}],"summary":"Fetches WordList objects for the logged-in user.","open":false,"httpMethod":"GET"}]}]}
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1 @@
1
+ {"endPoints":[{"path":"/word.{format}/{word}","description":"","operations":[{"parameters":[{"name":"word","description":"String value of WordObject to return","required":true,"paramType":"path"},{"name":"useCanonical","description":"If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.","required":false,"paramType":"query"},{"name":"includeSuggestions","description":"Return suggestions (for correct spelling, case variants, etc.)","required":false,"paramType":"query"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"Word","errorResponses":[{"reason":"Invalid word supplied.","code":400}],"occurs":"1","condition":"any"}],"summary":"Given a word as a string, returns the WordObject that represents it","open":false,"httpMethod":"GET"}]},{"path":"/word.{format}/{word}/examples","description":"","operations":[{"parameters":[{"name":"word","description":"Word to return examples for","required":true,"paramType":"path"},{"name":"limit","description":"Maximum number of results to return","required":false,"paramType":"query"},{"name":"includeDuplicates","description":"Show duplicate examples from different sources","required":false,"paramType":"query"},{"name":"contentProvider","description":"Return results from a specific ContentProvider","required":false,"paramType":"query"},{"name":"useCanonical","description":"If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.","required":false,"paramType":"query"},{"name":"skip","description":"Results to skip","required":false,"paramType":"query"},{"name":"limit","description":"Maximum number of results to return","required":false,"paramType":"query"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"ExampleSearchResults","errorResponses":[{"reason":"Invalid word supplied.","code":400}],"occurs":"1","condition":"any"}],"summary":"Returns examples for a word","open":false,"httpMethod":"GET"}]},{"path":"/word.{format}/{word}/definitions","description":"","operations":[{"parameters":[{"name":"word","description":"Word to return definitions for","required":true,"paramType":"path"},{"name":"limit","description":"Maximum number of results to return","required":false,"paramType":"query"},{"name":"partOfSpeech","description":"CSV list of part-of-speech types","required":false,"paramType":"query"},{"name":"includeRelated","description":"Return related words with definitions","required":false,"paramType":"query"},{"name":"sourceDictionaries","description":"Gets from dictionaries in the supplied order of precedence","required":false,"allowableValues":"ahd, century, wiktionary, webster, wordnet","paramType":"query"},{"name":"useCanonical","description":"If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.","required":false,"paramType":"query"},{"name":"includeTags","description":"Return a closed set of XML tags in response","required":false,"paramType":"query"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"Definition[]","errorResponses":[{"reason":"Invalid word supplied.","code":400},{"reason":"No definitions found.","code":404}],"occurs":"1","condition":"any"}],"summary":"Return definitions for a word","open":false,"httpMethod":"GET"}]},{"path":"/word.{format}/{word}/frequency","description":"","operations":[{"parameters":[{"name":"word","description":"Word to return","required":true,"paramType":"path"},{"name":"useCanonical","description":"If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.","required":false,"paramType":"query"},{"name":"startYear","description":"Starting Year","required":false,"paramType":"query"},{"name":"endYear","description":"Ending Year","required":false,"paramType":"query"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"FrequencySummary","errorResponses":[{"reason":"Invalid word supplied.","code":400},{"reason":"No results.","code":404}],"occurs":"1","condition":"any"},{"valueType":"FrequencySummaryWithErrorBars","errorResponses":[{"reason":"Invalid word supplied.","code":400},{"reason":"No results.","code":404}],"occurs":"1","condition":"errorBars=true"}],"summary":"Returns word usage over time","open":false,"httpMethod":"GET"}]},{"path":"/word.{format}/{word}/topExample","description":"","operations":[{"parameters":[{"name":"word","description":"Word to fetch examples for","required":true,"paramType":"path"},{"name":"contentProvider","description":"Return results from a specific ContentProvider","required":false,"paramType":"query"},{"name":"useCanonical","description":"If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.","required":false,"paramType":"query"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"Example","errorResponses":[{"reason":"Invalid word supplied.","code":400}],"occurs":"1","condition":"any"}],"summary":"Returns a top example for a word","open":false,"httpMethod":"GET"}]},{"path":"/word.{format}/{word}/related","description":"","operations":[{"parameters":[{"name":"word","description":"Word for which to return related words","required":true,"paramType":"path"},{"name":"partOfSpeech","description":"CSV list of part-of-speech types","required":false,"paramType":"query"},{"name":"sourceDictionary","description":"Get data from a single dictionary. Valid options are ahd, century, wiktionary, webster, and wordnet.","required":false,"paramType":"query"},{"name":"limit","description":"Maximum number of results to return","required":false,"paramType":"query"},{"name":"useCanonical","description":"If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.","required":false,"paramType":"query"},{"name":"type","description":"Relationship type","required":false,"paramType":"query"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"Related[]","errorResponses":[{"reason":"Invalid word supplied.","code":400},{"reason":"No definitions found.","code":404}],"occurs":"1","condition":"any"}],"summary":"Return related words (thesaurus data) for a word","open":false,"httpMethod":"GET"}]},{"path":"/word.{format}/{word}/phrases","description":"","operations":[{"parameters":[{"name":"word","description":"Word to fetch phrases for","required":true,"paramType":"path"},{"name":"limit","description":"Maximum number of results to return","required":false,"paramType":"query"},{"name":"wlmi","description":"Minimum WLMI for the phrase","required":false,"paramType":"query"},{"name":"useCanonical","description":"If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested.","required":false,"paramType":"query"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"Bigram[]","errorResponses":[{"reason":"Invalid word supplied.","code":400}],"occurs":"1","condition":"any"}],"summary":"Fetches bi-gram phrases for a word","open":false,"httpMethod":"GET"}]},{"path":"/word.{format}/{word}/hyphenation","description":"","operations":[{"parameters":[{"name":"word","description":"Word to get syllables for","required":true,"paramType":"path"},{"name":"useCanonical","description":"If true will try to return a correct word root ('cats' -> 'cat'). If false returns exactly what was requested.","required":false,"paramType":"query"},{"name":"sourceDictionary","description":"Get from a single dictionary. Valid options: ahd, century, wiktionary, webster, and wordnet.","required":false,"paramType":"query"},{"name":"limit","description":"Maximum number of results to return","required":false,"paramType":"query"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"Syllable[]","errorResponses":[{"reason":"Invalid word supplied.","code":400}],"occurs":"1","condition":"any"}],"summary":"Returns syllable information for a word","open":false,"httpMethod":"GET"}]},{"path":"/word.{format}/{word}/pronunciations","description":"","operations":[{"parameters":[{"name":"word","description":"Word to get pronunciations for","required":true,"paramType":"path"},{"name":"useCanonical","description":"If true will try to return a correct word root ('cats' -> 'cat'). If false returns exactly what was requested.","required":false,"paramType":"query"},{"name":"sourceDictionary","description":"Get from a single dictionary. Valid options: ahd, century, wiktionary, webster, and wordnet.","required":false,"paramType":"query"},{"name":"typeFormat","description":"Text pronunciation type","required":false,"paramType":"query"},{"name":"limit","description":"Maximum number of results to return","required":false,"paramType":"query"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"TextPron[]","errorResponses":[{"reason":"Invalid word supplied.","code":400}],"occurs":"1","condition":"any"}],"summary":"Returns text pronunciations for a given word","open":false,"httpMethod":"GET"}]},{"path":"/word.{format}/{word}/audio","description":"","operations":[{"parameters":[{"name":"word","description":"Word to get audio for.","required":true,"paramType":"path"},{"name":"useCanonical","description":"Use the canonical form of the word.","required":false,"paramType":"query"},{"name":"limit","description":"Maximum number of results to return","required":false,"paramType":"query"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"AudioPron[]","errorResponses":[{"reason":"Invalid word supplied.","code":400}],"occurs":"1","condition":"any"}],"summary":"Fetches audio metadata for a word.","open":false,"notes":"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.","httpMethod":"GET"}]}]}
@@ -0,0 +1 @@
1
+ {"endPoints":[{"path":"/wordList.{format}/{wordListId}","description":"","operations":[{"parameters":[{"name":"wordListId","description":"ID of WordList to fetch","required":true,"paramType":"path"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"WordList","errorResponses":[{"reason":"Invalid ID supplied","code":400},{"reason":"Not Authorized to access WordList","code":403},{"reason":"WordList not found","code":404}],"occurs":"1","condition":"any"}],"summary":"Fetches a WordList by ID","open":false,"httpMethod":"GET"}]},{"path":"/wordList.{format}/{wordListId}/deleteWords","description":"","operations":[{"parameters":[{"name":"wordListId","description":"ID of WordList to use","required":true,"paramType":"path"},{"description":"Words to remove from WordList","required":false,"paramType":"body"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"void","errorResponses":[{"reason":"Invalid ID supplied","code":400},{"reason":"Not Authorized to modify WordList","code":403},{"reason":"WordList not found","code":404}],"occurs":"1","condition":"any"}],"summary":"Removes words from a WordList","open":false,"httpMethod":"POST"}]},{"path":"/wordList.{format}/{wordListId}/words","description":"","operations":[{"parameters":[{"name":"wordListId","description":"ID of WordList to use","required":true,"paramType":"path"},{"name":"sortBy","description":"Field to sort by","required":false,"allowableValues":"createDate,alpha","paramType":"query"},{"name":"sortOrder","description":"Direction to sort","required":false,"allowableValues":"asc,desc","paramType":"query"},{"name":"skip","description":"Results to skip","required":false,"paramType":"query"},{"name":"limit","description":"Maximum number of results to return","required":false,"paramType":"query"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"WordListWord[]","errorResponses":[{"reason":"Invalid ID supplied","code":400},{"reason":"Not Authorized to access WordList","code":403},{"reason":"WordList not found","code":404}],"occurs":"1","condition":"any"}],"summary":"Fetches words in a WordList","open":false,"httpMethod":"GET"}]},{"path":"/wordList.{format}/{wordListId}/words","description":"","operations":[{"parameters":[{"name":"wordListId","description":"ID of WordList to user","required":true,"paramType":"path"},{"description":"Words to add to WordList","required":false,"paramType":"body"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"void","errorResponses":[{"reason":"Invalid ID supplied","code":400},{"reason":"Not Authorized to access WordList","code":403},{"reason":"WordList not found","code":404}],"occurs":"1","condition":"any"}],"summary":"Adds words to a WordList","open":false,"httpMethod":"POST"}]},{"path":"/wordList.{format}/{wordListId}","description":"","operations":[{"parameters":[{"name":"wordListId","description":"ID of WordList to update","required":true,"paramType":"path"},{"description":"Updated WordList","required":false,"paramType":"body"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"void","errorResponses":[{"reason":"Invalid ID supplied","code":400},{"reason":"Not Authorized to update WordList","code":403},{"reason":"WordList not found","code":404}],"occurs":"1","condition":"any"}],"summary":"Updates an existing WordList","open":false,"httpMethod":"PUT"}]},{"path":"/wordList.{format}/{wordListId}","description":"","operations":[{"parameters":[{"name":"wordListId","description":"ID of WordList to delete","required":true,"paramType":"path"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"void","errorResponses":[{"reason":"Invalid ID supplied","code":400},{"reason":"Not Authorized to delete WordList","code":403},{"reason":"WordList not found","code":404}],"occurs":"1","condition":"any"}],"summary":"Deletes an existing WordList","open":false,"httpMethod":"DELETE"}]}]}
@@ -0,0 +1 @@
1
+ {"endPoints":[{"path":"/wordLists","description":"","operations":[{"parameters":[{"description":"WordList to create","required":false,"paramType":"body"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"WordList","errorResponses":[{"reason":"Invalid WordList supplied or mandatory fields are missing.","code":400},{"reason":"Not authenticated.","code":403},{"reason":"WordList owner not found.","code":404}],"occurs":"1","condition":"any"}],"summary":"Creates a WordList.","open":false,"httpMethod":"POST"}]},{"path":"/wordLists","description":"","operations":[{"parameters":[{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"Documentation","errorResponses":[{"reason":"No data available","code":404}],"occurs":"1","condition":"any"}],"summary":"Returns information about API parameters","open":true,"httpMethod":"GET"}]}]}
@@ -0,0 +1 @@
1
+ {"message": "invalid resource", "type": "error"}
@@ -0,0 +1 @@
1
+ {"endPoints":[{"path":"/words.{format}/randomWord","description":"","operations":[{"parameters":[{"name":"hasDictionaryDef","defaultValue":"true","description":"Only return words with dictionary definitions","required":false,"paramType":"query"},{"name":"includePartOfSpeech","description":"CSV part-of-speech values to include","required":false,"paramType":"query"},{"name":"excludePartOfSpeech","description":"CSV part-of-speech values to exclude","required":false,"paramType":"query"},{"name":"minCorpusCount","description":"Minimum corpus frequency for terms","required":false,"paramType":"query"},{"name":"maxCorpusCount","description":"Maximum corpus frequency for terms","required":false,"paramType":"query"},{"name":"minDictionaryCount","description":"Minimum dictionary count","required":false,"paramType":"query"},{"name":"maxDictionaryCount","description":"Maximum dictionary count","required":false,"paramType":"query"},{"name":"minLength","description":"Minimum word length","required":false,"paramType":"query"},{"name":"maxLength","description":"Maximum word length","required":false,"paramType":"query"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"Word","errorResponses":[{"reason":"No word found.","code":404}],"occurs":"1","condition":"any"}],"summary":"Returns a single random WordObject, in the format specified by the URL","open":false,"httpMethod":"GET"}]},{"path":"/words.{format}/randomWords","description":"","operations":[{"parameters":[{"name":"hasDictionaryDef","description":"Only return words with dictionary definitions","required":false,"paramType":"query"},{"name":"includePartOfSpeech","description":"CSV part-of-speech values to include","required":false,"paramType":"query"},{"name":"excludePartOfSpeech","description":"CSV part-of-speech values to exclude","required":false,"paramType":"query"},{"name":"minCorpusCount","description":"Minimum corpus frequency for terms (integer)","required":false,"paramType":"query"},{"name":"maxCorpusCount","description":"Maximum corpus frequency for terms (integer)","required":false,"paramType":"query"},{"name":"minDictionaryCount","description":"Minimum dictionary count (integer)","required":false,"paramType":"query"},{"name":"maxDictionaryCount","description":"Maximum dictionary count (integer)","required":false,"paramType":"query"},{"name":"minLength","description":"Minimum word length (characters)","required":false,"paramType":"query"},{"name":"maxLength","description":"Maximum word length (characters)","required":false,"paramType":"query"},{"name":"sortBy","description":"Attribute to sort by","required":false,"allowableValues":"alpha,count","paramType":"query"},{"name":"sortOrder","description":"Sort direction","required":false,"allowableValues":"asc,desc","paramType":"query"},{"name":"skip","description":"Results to skip (integer)","required":false,"paramType":"query"},{"name":"limit","description":"Maximum number of results to return (integer)","required":false,"paramType":"query"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"WordFrequency[]","errorResponses":[{"reason":"Invalid term supplied.","code":400},{"reason":"No results.","code":404}],"occurs":"1","condition":"any"}],"summary":"Returns an array of random WordObjects, in the format specified by the URL","open":false,"httpMethod":"GET"}]},{"path":"/words.{format}/search","description":"","operations":[{"parameters":[{"name":"query","description":"Search term","required":true,"paramType":"query"},{"name":"caseSensitive","defaultValue":"true","description":"Search case sensitive","required":false,"allowableValues":"true | false","paramType":"query"},{"name":"includePartOfSpeech","description":"Only include these comma-delimited parts of speech","required":false,"paramType":"query"},{"name":"excludePartOfSpeech","description":"Exclude these comma-delimited parts of speech","required":false,"paramType":"query"},{"name":"minCorpusCount","defaultValue":"5","description":"Minimum corpus frequency for terms","required":false,"allowableValues":"non-negative integer","paramType":"query"},{"name":"maxCorpusCount","description":"Maximum corpus frequency for terms","required":false,"allowableValues":"non-negative integer","paramType":"query"},{"name":"minDictionaryCount","defaultValue":"1","description":"Minimum number of dictionary entries","required":false,"allowableValues":"non-negative integer","paramType":"query"},{"name":"maxDictionaryCount","description":"Maximum dictionary count","required":false,"allowableValues":"non-negative integer","paramType":"query"},{"name":"minLength","defaultValue":"1","description":"Minimum word length","required":false,"allowableValues":"0 to 1024","paramType":"query"},{"name":"maxLength","description":"Maximum word length","required":false,"allowableValues":"0 to 1024","paramType":"query"},{"name":"skip","defaultValue":"0","description":"Results to skip","required":false,"allowableValues":"0 to 1000","paramType":"query"},{"name":"limit","defaultValue":"10","description":"Maximum number of results to return","required":false,"allowableValues":"1 to 1000","paramType":"query"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"WordFrequency[]","errorResponses":[{"reason":"Invalid term supplied.","code":400},{"reason":"No results.","code":404}],"occurs":"1","condition":"any"}],"summary":"Searches words.","open":false,"httpMethod":"GET"}]},{"path":"/words.{format}/wordOfTheDay","description":"","operations":[{"parameters":[{"name":"date","description":"Fetches by date in yyyy-MM-dd","required":false,"paramType":"query"},{"name":"category","description":"Filters response by category","required":false,"paramType":"query"},{"name":"creator","description":"Filters response by username","required":false,"paramType":"query"},{"name":"format","defaultValue":"json","description":"API response format","required":true,"allowableValues":"json,xml","paramType":"path"}],"response":[{"valueType":"WordOfTheDay","errorResponses":[{"reason":"No data available","code":404}],"occurs":"1","condition":"any"}],"summary":"Returns a specific WordOfTheDay","open":true,"httpMethod":"GET"}]}]}
@@ -1,90 +1,63 @@
1
- require 'httparty'
2
-
3
- class Wordnik
4
- include HTTParty
5
-
6
- PARTS_OF_SPEECH = [:noun, :verb, :adjective, :adverb, :idiom, :article, :abbreviation,
7
- :preposition, :prefix, :interjection, :suffix, :"verb-transitive", :"verb-intransitive"]
8
-
9
- attr_reader :api_key
10
-
11
- base_uri 'http://api.wordnik.com/api'
12
-
13
- def initialize(api_key = nil)
14
- @api_key = (api_key || File.read('.api-key').strip || '').dup
15
- unless @api_key.blank?
16
- self.class.default_params :api_key => @api_key
1
+ require 'wordnik/monkey_patches'
2
+ require 'wordnik/endpoint'
3
+ require 'wordnik/operation'
4
+ require 'wordnik/operation_parameter'
5
+ require 'wordnik/request'
6
+ require 'wordnik/resource'
7
+ require 'wordnik/response'
8
+ require 'wordnik/configuration'
9
+
10
+ module Wordnik
11
+
12
+ API_VERSION = "4.01.61"
13
+
14
+ class << self
15
+
16
+ # A Wordnik configuration object. Must act like a hash and return sensible
17
+ # values for all Wordnik configuration options. See Wordnik::Configuration.
18
+ attr_accessor :configuration
19
+
20
+ attr_accessor :resources
21
+
22
+ # Call this method to modify defaults in your initializers.
23
+ #
24
+ # @example
25
+ # Wordnik.configure do |config|
26
+ # config.api_key = '1234567890abcdef'
27
+ # config.response_format = :json
28
+ # end
29
+ def configure
30
+ self.configuration ||= Configuration.new
31
+ yield(configuration) if block_given?
32
+ self.build_resources
17
33
  end
18
- end
19
-
20
- def api_key=(api_key)
21
- @api_key = api_key.to_s.dup
22
- self.class.default_params :api_key => @api_key
23
- @api_key
24
- end
25
34
 
26
- def lookup(word)
27
- do_request("word.json/#{word.downcase}")
28
- end
29
-
30
- def define(word, *args)
31
- options = args.last.is_a?(Hash) ? args.pop : {}
32
- unless options.key?(:count)
33
- options[:count] = args.any? ? args.first.to_i : 100
35
+ # Iterate over each disk-cached JSON resource documentation file
36
+ #
37
+ def build_resources
38
+ self.resources = {}
39
+ self.resource_names.map do |resource_name|
40
+ name = resource_name.underscore.to_sym # 'fooBar' => :foo_bar
41
+ filename = "api_docs/#{resource_name}.json"
42
+ resource = Resource.new(
43
+ :name => name,
44
+ :raw_data => JSON.parse(File.read(filename))
45
+ )
46
+ self.resources[name] = resource
47
+ end
34
48
  end
35
- do_request("word.json/#{word.downcase}/definitions", options)
36
- end
37
-
38
- def frequency(word)
39
- do_request("word.json/#{word.downcase}/frequency")
40
- end
41
-
42
- def examples(word)
43
- do_request("word.json/#{word.downcase}/examples")
44
- end
45
-
46
- def autocomplete(word_fragment, count = 100)
47
- do_request("suggest.json/#{word_fragment.downcase}", :count => count)
48
- end
49
-
50
- def word_of_the_day
51
- do_request("wordoftheday.json")
52
- end
53
-
54
- def random(has_definition = true)
55
- do_request("words.json/randomWord", :hasDictionaryDef => has_definition)
56
- end
57
-
58
- def punctuation(word)
59
- do_request("word.json/#{word.downcase}/punctuationFactor")
60
- end
61
-
62
- protected
63
-
64
- def do_request(request, options = {})
65
- handle_result(self.class.get("/#{request}", sanitize_options(options)))
66
- end
67
-
68
- def handle_result(result)
69
- if result.is_a?(String)
70
- raise 'Error in result.'
71
- elsif result.is_a?(Hash) && result.key?('type') && result['type'] == 'error'
72
- raise "Error in result: #{result['message']}"
73
- else
74
- result
49
+
50
+ # The names of all the resources.
51
+ # This is used by Wordnik.build_resources and the rake task that fetches remote API docs
52
+ #
53
+ def resource_names
54
+ %w(account corpus document partners system tag user users word words wordList wordLists wordoftheday)
75
55
  end
76
- end
77
-
78
- def sanitize_options(opts)
79
- options = {}
80
-
81
- options[:count] = opts[:count].to_i if opts.key?(:count)
82
- options[:hasDictionaryDef] = !!opts[:hasDictionaryDef] if opts.key?(:hasDictionaryDef)
83
-
84
- if opts.key?(:partOfSpeech)
85
- options[:partOfSpeech] = opts[:partOfSpeech].to_a.reject { |pos| !PARTS_OF_SPEECH.include?(pos.to_sym) }.join(',')
56
+
57
+ def word
58
+ Wordnik.resources[:word]
86
59
  end
87
-
88
- { :query => options }
60
+
89
61
  end
90
- end
62
+
63
+ end
@@ -0,0 +1,24 @@
1
+ module Wordnik
2
+
3
+ class Configuration
4
+
5
+ # Wordnik API key
6
+ attr_accessor :api_key
7
+
8
+ # TODO: Steal all the auth stuff from the old gem!
9
+ # attr_accessor :auth_token
10
+
11
+ # Response format can be :json (default) or :xml
12
+ attr_accessor :response_format
13
+
14
+ # The URL of the API server
15
+ attr_accessor :base_uri
16
+
17
+ def initialize
18
+ @response_format = :json
19
+ @base_uri = 'api.wordnik.com/v4'
20
+ end
21
+
22
+ end
23
+
24
+ end