wordnik 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore CHANGED
@@ -1,3 +1,22 @@
1
- pkg/*
2
- *.gem
3
- .bundle
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
@@ -0,0 +1,2 @@
1
+ 0.1.0:
2
+ * First release
data/LICENSE ADDED
@@ -0,0 +1,12 @@
1
+ Copyright (c) 2009, Jason M. Adams
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+
10
+ - Neither the name of Jason M. Adams nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,23 @@
1
+ = Wordnik
2
+
3
+ Wordnik wants to be a place for all the words, and everything known about them. They have provided a RESTful API accessible after applying for a key. Visit http://docs.wordnik.com/api for more information and to apply for a key.
4
+
5
+ == Installation
6
+
7
+ Install gem via gemcutter.
8
+
9
+ gem install wordnik
10
+
11
+ == Note on Patches/Pull Requests
12
+
13
+ * Fork the project.
14
+ * Make your feature addition or bug fix.
15
+ * Add tests for it. This is important so I don't break it in a
16
+ future version unintentionally.
17
+ * Commit, do not mess with rakefile, version, or history.
18
+ If you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull
19
+ * Send me a pull request. Bonus points for topic branches.
20
+
21
+ == Copyright
22
+
23
+ Copyright (c) 2009 Jason Adams under the BSD license. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,9 +1,54 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
1
+ require 'rubygems'
2
+ require 'rake'
3
3
 
4
- require 'rspec/core/rake_task'
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 "thoughtbot-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
5
21
 
6
- RSpec::Core::RakeTask.new('spec')
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
28
 
8
- # If you want to make this the default task
9
- task :default => :spec
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
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
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
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -1,33 +1,4 @@
1
- require 'wordnik/endpoint'
2
- require 'wordnik/operation'
3
- require 'wordnik/operation_parameter'
4
- require 'wordnik/request'
5
- require 'wordnik/resource'
6
- require 'wordnik/response'
7
- require 'wordnik/configuration'
8
-
9
- module Wordnik
10
-
11
- API_VERSION = "4.01.61"
12
-
13
- class << self
14
-
15
- # A Wordnik configuration object. Must act like a hash and return sensible
16
- # values for all Wordnik configuration options. See Wordnik::Configuration.
17
- attr_accessor :configuration
18
-
19
- # Call this method to modify defaults in your initializers.
20
- #
21
- # @example
22
- # Wordnik.configure do |config|
23
- # config.api_key = '1234567890abcdef'
24
- # config.response_format = :json
25
- # end
26
- def configure
27
- self.configuration ||= Configuration.new
28
- yield(configuration) if block_given?
29
- end
30
-
31
- end
32
-
33
- end
1
+ require 'httparty'
2
+ require 'singleton'
3
+ require 'wordnik/wordnik'
4
+ require 'wordnik/word'
@@ -0,0 +1,35 @@
1
+ module Wordnik
2
+ class Word
3
+ attr_reader :word
4
+
5
+ def initialize(word, eager = false)
6
+ @word = word.dup.freeze
7
+ load_all if eager
8
+ end
9
+
10
+ def wordnik_id
11
+ @wordnik_id ||= Wordnik.instance.lookup(word)['id']
12
+ end
13
+
14
+ def definitions
15
+ @definitions ||= Wordnik.instance.define(word)
16
+ end
17
+
18
+ def frequencies
19
+ @frequencies ||= Wordnik.instance.frequency(word)
20
+ end
21
+
22
+ def examples
23
+ @examples ||= Wordnik.instance.examples(word)
24
+ end
25
+
26
+ private
27
+
28
+ def load_all
29
+ wordnik_id
30
+ definitions
31
+ frequencies
32
+ examples
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,61 @@
1
+ module Wordnik
2
+ class Wordnik
3
+ include Singleton
4
+ include HTTParty
5
+
6
+ attr_reader :api_key
7
+
8
+ base_uri 'http://api.wordnik.com/api'
9
+
10
+ def initialize(api_key = nil)
11
+ @api_key = (api_key || File.read('.api-key').strip || '').dup
12
+ self.class.default_params :api_key => @api_key
13
+ end
14
+
15
+ def api_key=(api_key)
16
+ @api_key = api_key.dup
17
+ end
18
+
19
+ def lookup(word)
20
+ do_request("word.json/#{word.downcase}")
21
+ end
22
+
23
+ def define(word, count = 100)
24
+ do_request("word.json/#{word.downcase}/definitions", :count => count)
25
+ end
26
+
27
+ def frequency(word)
28
+ do_request("word.json/#{word.downcase}/frequency")
29
+ end
30
+
31
+ def examples(word)
32
+ do_request("word.json/#{word.downcase}/examples")
33
+ end
34
+
35
+ def autocomplete(word_fragment, count = 100)
36
+ do_request("suggest.json/#{word_fragment.downcase}", :count => count)
37
+ end
38
+
39
+ def word_of_the_day
40
+ do_request("wordoftheday.json")
41
+ end
42
+
43
+ def random(has_definition = true)
44
+ do_request("words.json/randomWord", :hasDictionaryDef => has_definition)
45
+ end
46
+
47
+ protected
48
+
49
+ def do_request(request, options = {})
50
+ handle_result(self.class.get("/#{request}", options))
51
+ end
52
+
53
+ def handle_result(result)
54
+ if result.is_a?(String)
55
+ raise 'Error in result.'
56
+ else
57
+ result
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'wordnik'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestWordnik < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -1,32 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
1
4
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "wordnik/version"
4
5
 
5
6
  Gem::Specification.new do |s|
6
- s.name = "wordnik"
7
- s.version = Wordnik::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Zeke Sikelianos", "John McGrath"]
10
- s.email = ["zeke@wordnik.com", "john@wordnik.com"]
11
- s.homepage = "http://developer.wordnik.com"
12
- s.summary = %q{A ruby wrapper for the Wordnik API}
13
- s.description = %q{This gem provides a simple interface to the entire Wordnik API. Its methods are defined by the documentation that comes from the API itself, so it's guaranteed to be up to date.}
7
+ s.name = %q{wordnik}
8
+ s.version = "0.1.0"
14
9
 
15
- s.rubyforge_project = "wordnik"
16
-
17
- s.add_dependency 'typhoeus', '0.2.1'
18
- s.add_dependency 'htmlentities', '4.2.4'
19
- s.add_dependency 'addressable', '2.2.4'
20
- s.add_dependency 'nokogiri', '1.4.4'
21
- s.add_dependency 'activemodel', '3.0.3'
22
- s.add_dependency 'json', '1.4.6'
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jason Adams"]
12
+ s.date = %q{2009-11-07}
13
+ s.description = %q{Ruby interface to the Wordnik API. Details at http://docs.wordnik.com/api/methods.}
14
+ s.email = %q{jasonmadams@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/wordnik.rb",
27
+ "lib/wordnik/word.rb",
28
+ "lib/wordnik/wordnik.rb",
29
+ "test/helper.rb",
30
+ "test/test_wordnik.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/ealdent/wordnik}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.5}
36
+ s.summary = %q{Ruby interface to the Wordnik API}
37
+ s.test_files = [
38
+ "test/helper.rb",
39
+ "test/test_wordnik.rb"
40
+ ]
23
41
 
24
- s.add_development_dependency 'rspec', '2.4.0'
25
- s.add_development_dependency 'vcr', '1.5.1'
26
- s.add_development_dependency 'webmock', '1.6.2'
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
27
45
 
28
- s.files = `git ls-files`.split("\n")
29
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
30
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
31
- s.require_paths = ["lib"]
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
53
+ end
32
54
  end
55
+
metadata CHANGED
@@ -1,232 +1,88 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wordnik
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 2
9
- version: 0.0.2
4
+ version: 0.1.0
10
5
  platform: ruby
11
6
  authors:
12
- - Zeke Sikelianos
13
- - John McGrath
7
+ - Jason Adams
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
11
 
18
- date: 2011-02-16 00:00:00 -08:00
12
+ date: 2009-11-07 00:00:00 -05:00
19
13
  default_executable:
20
14
  dependencies:
21
15
  - !ruby/object:Gem::Dependency
22
- name: typhoeus
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - "="
28
- - !ruby/object:Gem::Version
29
- segments:
30
- - 0
31
- - 2
32
- - 1
33
- version: 0.2.1
34
- type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: htmlentities
38
- prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - "="
43
- - !ruby/object:Gem::Version
44
- segments:
45
- - 4
46
- - 2
47
- - 4
48
- version: 4.2.4
49
- type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: addressable
53
- prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - "="
58
- - !ruby/object:Gem::Version
59
- segments:
60
- - 2
61
- - 2
62
- - 4
63
- version: 2.2.4
64
- type: :runtime
65
- version_requirements: *id003
66
- - !ruby/object:Gem::Dependency
67
- name: nokogiri
68
- prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
70
- none: false
71
- requirements:
72
- - - "="
73
- - !ruby/object:Gem::Version
74
- segments:
75
- - 1
76
- - 4
77
- - 4
78
- version: 1.4.4
79
- type: :runtime
80
- version_requirements: *id004
81
- - !ruby/object:Gem::Dependency
82
- name: activemodel
83
- prerelease: false
84
- requirement: &id005 !ruby/object:Gem::Requirement
85
- none: false
86
- requirements:
87
- - - "="
88
- - !ruby/object:Gem::Version
89
- segments:
90
- - 3
91
- - 0
92
- - 3
93
- version: 3.0.3
16
+ name: httparty
94
17
  type: :runtime
95
- version_requirements: *id005
96
- - !ruby/object:Gem::Dependency
97
- name: json
98
- prerelease: false
99
- requirement: &id006 !ruby/object:Gem::Requirement
100
- none: false
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
101
20
  requirements:
102
- - - "="
21
+ - - ">="
103
22
  - !ruby/object:Gem::Version
104
- segments:
105
- - 1
106
- - 4
107
- - 6
108
- version: 1.4.6
109
- type: :runtime
110
- version_requirements: *id006
23
+ version: 0.4.5
24
+ version:
111
25
  - !ruby/object:Gem::Dependency
112
- name: rspec
113
- prerelease: false
114
- requirement: &id007 !ruby/object:Gem::Requirement
115
- none: false
116
- requirements:
117
- - - "="
118
- - !ruby/object:Gem::Version
119
- segments:
120
- - 2
121
- - 4
122
- - 0
123
- version: 2.4.0
26
+ name: thoughtbot-shoulda
124
27
  type: :development
125
- version_requirements: *id007
126
- - !ruby/object:Gem::Dependency
127
- name: vcr
128
- prerelease: false
129
- requirement: &id008 !ruby/object:Gem::Requirement
130
- none: false
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
131
30
  requirements:
132
- - - "="
31
+ - - ">="
133
32
  - !ruby/object:Gem::Version
134
- segments:
135
- - 1
136
- - 5
137
- - 1
138
- version: 1.5.1
139
- type: :development
140
- version_requirements: *id008
141
- - !ruby/object:Gem::Dependency
142
- name: webmock
143
- prerelease: false
144
- requirement: &id009 !ruby/object:Gem::Requirement
145
- none: false
146
- requirements:
147
- - - "="
148
- - !ruby/object:Gem::Version
149
- segments:
150
- - 1
151
- - 6
152
- - 2
153
- version: 1.6.2
154
- type: :development
155
- version_requirements: *id009
156
- description: This gem provides a simple interface to the entire Wordnik API. Its methods are defined by the documentation that comes from the API itself, so it's guaranteed to be up to date.
157
- email:
158
- - zeke@wordnik.com
159
- - john@wordnik.com
33
+ version: "0"
34
+ version:
35
+ description: Ruby interface to the Wordnik API. Details at http://docs.wordnik.com/api/methods.
36
+ email: jasonmadams@gmail.com
160
37
  executables: []
161
38
 
162
39
  extensions: []
163
40
 
164
- extra_rdoc_files: []
165
-
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
166
44
  files:
45
+ - .document
167
46
  - .gitignore
168
- - Gemfile
169
- - Gemfile.lock
170
- - README.md
47
+ - CHANGELOG
48
+ - LICENSE
49
+ - README.rdoc
171
50
  - Rakefile
51
+ - VERSION
172
52
  - lib/wordnik.rb
173
- - lib/wordnik/configuration.rb
174
- - lib/wordnik/endpoint.rb
175
- - lib/wordnik/operation.rb
176
- - lib/wordnik/operation_parameter.rb
177
- - lib/wordnik/request.rb
178
- - lib/wordnik/resource.rb
179
- - lib/wordnik/response.rb
180
- - lib/wordnik/version.rb
181
- - spec/endpoint_spec.rb
182
- - spec/operation_parameter_spec.rb
183
- - spec/operation_spec.rb
184
- - spec/request_spec.rb
185
- - spec/resource_spec.rb
186
- - spec/response_spec.rb
187
- - spec/spec.opts
188
- - spec/spec_helper.rb
189
- - spec/wordnik_spec.rb
53
+ - lib/wordnik/word.rb
54
+ - lib/wordnik/wordnik.rb
55
+ - test/helper.rb
56
+ - test/test_wordnik.rb
190
57
  - wordnik.gemspec
191
58
  has_rdoc: true
192
- homepage: http://developer.wordnik.com
59
+ homepage: http://github.com/ealdent/wordnik
193
60
  licenses: []
194
61
 
195
62
  post_install_message:
196
- rdoc_options: []
197
-
63
+ rdoc_options:
64
+ - --charset=UTF-8
198
65
  require_paths:
199
66
  - lib
200
67
  required_ruby_version: !ruby/object:Gem::Requirement
201
- none: false
202
68
  requirements:
203
69
  - - ">="
204
70
  - !ruby/object:Gem::Version
205
- segments:
206
- - 0
207
71
  version: "0"
72
+ version:
208
73
  required_rubygems_version: !ruby/object:Gem::Requirement
209
- none: false
210
74
  requirements:
211
75
  - - ">="
212
76
  - !ruby/object:Gem::Version
213
- segments:
214
- - 0
215
77
  version: "0"
78
+ version:
216
79
  requirements: []
217
80
 
218
- rubyforge_project: wordnik
219
- rubygems_version: 1.3.7
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.5
220
83
  signing_key:
221
84
  specification_version: 3
222
- summary: A ruby wrapper for the Wordnik API
85
+ summary: Ruby interface to the Wordnik API
223
86
  test_files:
224
- - spec/endpoint_spec.rb
225
- - spec/operation_parameter_spec.rb
226
- - spec/operation_spec.rb
227
- - spec/request_spec.rb
228
- - spec/resource_spec.rb
229
- - spec/response_spec.rb
230
- - spec/spec.opts
231
- - spec/spec_helper.rb
232
- - spec/wordnik_spec.rb
87
+ - test/helper.rb
88
+ - test/test_wordnik.rb