wordnik 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec-tm +2 -0
- data/Gemfile.lock +9 -9
- data/README.md +7 -9
- data/Rakefile +89 -4
- data/USAGE.md +151 -29
- data/api_docs/account.json +1 -1
- data/api_docs/system.json +1 -1
- data/api_docs/user.json +1 -1
- data/api_docs/word.json +1 -1
- data/api_docs/wordList.json +1 -1
- data/api_docs/wordLists.json +1 -1
- data/api_docs/words.json +1 -1
- data/lib/wordnik/operation.rb +1 -17
- data/lib/wordnik/request.rb +1 -1
- data/lib/wordnik/resource.rb +11 -72
- data/lib/wordnik/resource_modules/account.rb +230 -0
- data/lib/wordnik/resource_modules/system.rb +37 -0
- data/lib/wordnik/resource_modules/user.rb +283 -0
- data/lib/wordnik/resource_modules/word.rb +438 -0
- data/lib/wordnik/resource_modules/word_list.rb +211 -0
- data/lib/wordnik/resource_modules/word_lists.rb +68 -0
- data/lib/wordnik/resource_modules/words.rb +482 -0
- data/lib/wordnik/version.rb +1 -1
- data/lib/wordnik.rb +19 -11
- data/spec/endpoint_spec.rb +1 -1
- data/spec/operation_parameter_spec.rb +1 -1
- data/spec/operation_spec.rb +1 -1
- data/spec/request_spec.rb +5 -1
- data/spec/resource_spec.rb +131 -2
- data/spec/response_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -0
- data/spec/wordnik_spec.rb +7 -106
- data/wordnik.gemspec +1 -1
- metadata +11 -3
data/spec/resource_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe Wordnik::Resource do
|
|
4
4
|
|
5
5
|
before(:each) do
|
6
6
|
VCR.use_cassette('words', :record => :new_episodes) do
|
7
|
-
@response = Typhoeus::Request.get("http://
|
7
|
+
@response = Typhoeus::Request.get("http://beta.wordnik.com/v4/word.json")
|
8
8
|
end
|
9
9
|
|
10
10
|
@default_params = {
|
@@ -22,10 +22,139 @@ describe Wordnik::Resource do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "sets endpoints" do
|
25
|
-
@resource.endpoints.size.should
|
25
|
+
@resource.endpoints.size.should >= 10
|
26
26
|
@resource.endpoints.first.class.should == Wordnik::Endpoint
|
27
27
|
end
|
28
|
+
|
29
|
+
it "defines a method for each operation nickname" do
|
30
|
+
@resource.public_methods.should include(:get_word)
|
31
|
+
@resource.public_methods.should include(:get_definitions)
|
32
|
+
@resource.public_methods.should include(:contextual_lookup_post)
|
33
|
+
@resource.public_methods.should_not include(:get_busy)
|
34
|
+
end
|
28
35
|
|
29
36
|
end
|
37
|
+
|
38
|
+
describe "auto-generated methods" do
|
39
|
+
|
40
|
+
before(:each) do
|
41
|
+
configure_wordnik
|
42
|
+
Wordnik.authenticate
|
43
|
+
end
|
30
44
|
|
45
|
+
it "builds requests but doesn't run them if :request_only is passed" do
|
46
|
+
@request = Wordnik.word.get_word('dynamo', :request_only => true)
|
47
|
+
@request.class.should == Wordnik::Request
|
48
|
+
end
|
49
|
+
|
50
|
+
it "runs requests and returns their body if :request_only is absent" do
|
51
|
+
@response_body = Wordnik.word.get_word('dynamo')
|
52
|
+
@response_body.class.should == Hash
|
53
|
+
@response_body.keys.sort.should == %w(canonicalForm word)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "allows the same auto-generated method to be called with different parameters" do
|
57
|
+
request1 = Wordnik.word_list.get_word_list_by_id('dog', :request_only => true)
|
58
|
+
request2 = Wordnik.word_list.get_word_list_by_id('cat', :request_only => true)
|
59
|
+
request1.path.should_not == request2.path
|
60
|
+
end
|
61
|
+
|
62
|
+
context "argument handling" do
|
63
|
+
|
64
|
+
before(:each) do
|
65
|
+
@request = Wordnik.word.get_examples('dynamo', :skip => 2, :limit => 10, :request_only => true)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "injects required arguments into the path" do
|
69
|
+
@request.path.should == "/word/dynamo/examples"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "passes optional key-value arguments to the query string" do
|
73
|
+
@request.query_string.should == "?limit=10&skip=2"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "puts key-value arguments in the request body instead of the query params for POSTs and PUTs" do
|
77
|
+
body = {
|
78
|
+
:name => "Wordnik Ruby Test List #{RAND}",
|
79
|
+
:description => 'This is created by the test suite.',
|
80
|
+
:type => 'PUBLIC',
|
81
|
+
:user_id => Wordnik.configuration.user_id,
|
82
|
+
:request_only => true
|
83
|
+
}
|
84
|
+
@request = Wordnik.word_lists.create_word_list(body)
|
85
|
+
@request.body.should have_key(:name)
|
86
|
+
@request.body.should have_key(:description)
|
87
|
+
@request.body.should have_key(:type)
|
88
|
+
@request.body.should have_key(:userId)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
context "response transmogrification" do
|
94
|
+
|
95
|
+
it "converts definitions response into an array of definition objects" # do
|
96
|
+
# defs = Wordnik.word.get_definitions('boogaloo')
|
97
|
+
# defs.should be_an(Array)
|
98
|
+
# defs.first.should be_a(Wordnik::Definition)
|
99
|
+
# end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
context "wordlists" do
|
106
|
+
|
107
|
+
before do
|
108
|
+
configure_wordnik
|
109
|
+
Wordnik.authenticate
|
110
|
+
@permalink = "wordnik-ruby-test-list-#{RAND}"
|
111
|
+
end
|
112
|
+
|
113
|
+
it "creates a wordlist" do
|
114
|
+
body = {
|
115
|
+
:name => "Wordnik Ruby Test List #{RAND}",
|
116
|
+
:description => 'This is created by the test suite.',
|
117
|
+
:type => 'PUBLIC',
|
118
|
+
:user_id => Wordnik.configuration.user_id,
|
119
|
+
:request_only => true
|
120
|
+
}
|
121
|
+
request = Wordnik.word_lists.create_word_list(body)
|
122
|
+
response = request.response
|
123
|
+
response.body.should be_a_kind_of(Hash)
|
124
|
+
response.body.should have_key('permalink')
|
125
|
+
response.body['permalink'].should == @permalink
|
126
|
+
end
|
127
|
+
|
128
|
+
it "finds the new wordlist (method 1, using the wordList resource)" do
|
129
|
+
list = Wordnik.word_list.get_word_list_by_id(@permalink)
|
130
|
+
list.should have_key('permalink')
|
131
|
+
list['permalink'].should == @permalink
|
132
|
+
end
|
133
|
+
|
134
|
+
it "finds the new wordlist (method 2, among user's wordlists)" do
|
135
|
+
lists = Wordnik.account.get_word_lists_for_current_user
|
136
|
+
permalinks = lists.map { |list| list['permalink'] }
|
137
|
+
permalinks.should include(@permalink)
|
138
|
+
end
|
139
|
+
|
140
|
+
it "adds words to it" #do
|
141
|
+
# body = [
|
142
|
+
# {:word => 'foo'},
|
143
|
+
# {:word => 'bar'},
|
144
|
+
# {:word => 'metasyntactic'},
|
145
|
+
# ]
|
146
|
+
# request = Wordnik.word_list.post_words(@permalink, body)
|
147
|
+
# # raise request.response.inspect
|
148
|
+
#
|
149
|
+
# list = Wordnik.word_list.get(@permalink)
|
150
|
+
# # raise list.inspect
|
151
|
+
# end
|
152
|
+
|
153
|
+
it "updates words"
|
154
|
+
|
155
|
+
it "get all the words"
|
156
|
+
|
157
|
+
it "deletes a wordlist"
|
158
|
+
|
159
|
+
end
|
31
160
|
end
|
data/spec/response_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Wordnik::Response do
|
|
5
5
|
before(:each) do
|
6
6
|
|
7
7
|
VCR.use_cassette('default_response_request', :record => :new_episodes) do
|
8
|
-
@raw = Typhoeus::Request.get("http://
|
8
|
+
@raw = Typhoeus::Request.get("http://beta.wordnik.com/v4/word.json")
|
9
9
|
end
|
10
10
|
|
11
11
|
@response = Wordnik::Response.new(@raw)
|
@@ -37,7 +37,7 @@ describe Wordnik::Response do
|
|
37
37
|
|
38
38
|
it "recognizes xml" do
|
39
39
|
VCR.use_cassette('xml_response_request', :record => :new_episodes) do
|
40
|
-
@raw = Typhoeus::Request.get("http://
|
40
|
+
@raw = Typhoeus::Request.get("http://beta.wordnik.com/v4/word.xml/help")
|
41
41
|
end
|
42
42
|
@response = Wordnik::Response.new(@raw)
|
43
43
|
@response.format.should == :xml
|
@@ -63,7 +63,7 @@ describe Wordnik::Response do
|
|
63
63
|
|
64
64
|
it "has a pretty xml body" do
|
65
65
|
VCR.use_cassette('xml_response_request', :record => :new_episodes) do
|
66
|
-
@raw = Typhoeus::Request.get("http://
|
66
|
+
@raw = Typhoeus::Request.get("http://beta.wordnik.com/v4/word.xml/help")
|
67
67
|
end
|
68
68
|
@response = Wordnik::Response.new(@raw)
|
69
69
|
@response.pretty_body.should =~ /\?xml/
|
data/spec/spec_helper.rb
CHANGED
data/spec/wordnik_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require 'spec_helper'
|
1
|
+
# require 'spec_helper'
|
2
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
3
|
|
3
4
|
describe Wordnik do
|
4
5
|
|
@@ -22,7 +23,7 @@ describe Wordnik do
|
|
22
23
|
end
|
23
24
|
|
24
25
|
it "assigns resource keys that match the resource names" do
|
25
|
-
Wordnik.resources[:word].name.should == :word
|
26
|
+
Wordnik.resources[:word].name.should == :word
|
26
27
|
end
|
27
28
|
|
28
29
|
end
|
@@ -74,109 +75,9 @@ describe Wordnik do
|
|
74
75
|
|
75
76
|
end
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
Wordnik.word.name.should == :word
|
82
|
-
end
|
83
|
-
|
84
|
-
it "builds requests but doesn't run them if method name begins with 'build_'" do
|
85
|
-
@request = Wordnik.word.build_get('dynamo')
|
86
|
-
@request.class.should == Wordnik::Request
|
87
|
-
end
|
88
|
-
|
89
|
-
it "runs requests and returns their body if method name doesn't begin with 'build_'" do
|
90
|
-
@response_body = Wordnik.word.get('dynamo')
|
91
|
-
@response_body.class.should == Hash
|
92
|
-
@response_body.keys.sort.should == %w(canonicalForm word)
|
93
|
-
end
|
94
|
-
|
95
|
-
context "argument handling" do
|
96
|
-
|
97
|
-
before(:each) do
|
98
|
-
@request = Wordnik.word.build_get_examples('dynamo', :skip => 2, :limit => 10)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "injects required arguments into the path" do
|
102
|
-
@request.path.should == "/word/dynamo/examples"
|
103
|
-
end
|
104
|
-
|
105
|
-
it "passes optional key-value arguments to the query string" do
|
106
|
-
@request.query_string.should == "?limit=10&skip=2"
|
107
|
-
end
|
108
|
-
|
109
|
-
it "puts key-value arguments in the request body instead of the query params for POSTs and PUTs" do
|
110
|
-
body = {
|
111
|
-
:name => "Wordnik Ruby Test List #{RAND}",
|
112
|
-
:description => 'This is created by the test suite.',
|
113
|
-
:type => 'PUBLIC',
|
114
|
-
:user_id => Wordnik.configuration.user_id
|
115
|
-
}
|
116
|
-
@request = Wordnik.word_lists.build_post(body)
|
117
|
-
@request.body.should have_key(:name)
|
118
|
-
@request.body.should have_key(:description)
|
119
|
-
@request.body.should have_key(:type)
|
120
|
-
@request.body.should have_key(:userId)
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
124
|
-
|
125
|
-
context "wordlists" do
|
126
|
-
|
127
|
-
before do
|
128
|
-
configure_wordnik
|
129
|
-
Wordnik.authenticate
|
130
|
-
@permalink = "wordnik-ruby-test-list-#{RAND}"
|
131
|
-
end
|
132
|
-
|
133
|
-
it "creates a wordlist" do
|
134
|
-
body = {
|
135
|
-
:name => "Wordnik Ruby Test List #{RAND}",
|
136
|
-
:description => 'This is created by the test suite.',
|
137
|
-
:type => 'PUBLIC',
|
138
|
-
:user_id => Wordnik.configuration.user_id
|
139
|
-
}
|
140
|
-
request = Wordnik.word_lists.build_post(body)
|
141
|
-
response = request.response
|
142
|
-
response.body.should be_a_kind_of(Hash)
|
143
|
-
response.body.should have_key('permalink')
|
144
|
-
response.body['permalink'].should == @permalink
|
145
|
-
end
|
146
|
-
|
147
|
-
it "finds the new wordlist (method 1, using the wordList resource)" do
|
148
|
-
list = Wordnik.word_list.get(@permalink)
|
149
|
-
list.should have_key('permalink')
|
150
|
-
list['permalink'].should == @permalink
|
151
|
-
end
|
152
|
-
|
153
|
-
it "finds the new wordlist (method 2, among user's wordlists)" do
|
154
|
-
lists = Wordnik.account.get_word_lists
|
155
|
-
permalinks = lists.map { |list| list['permalink'] }
|
156
|
-
permalinks.should include(@permalink)
|
157
|
-
end
|
158
|
-
|
159
|
-
it "adds words to it" do
|
160
|
-
body = [
|
161
|
-
{:word => 'foo'},
|
162
|
-
{:word => 'bar'},
|
163
|
-
{:word => 'metasyntactic'},
|
164
|
-
]
|
165
|
-
request = Wordnik.word_list.build_post_words(@permalink, body)
|
166
|
-
# raise request.response.inspect
|
167
|
-
|
168
|
-
list = Wordnik.word_list.get(@permalink)
|
169
|
-
# raise list.inspect
|
170
|
-
end
|
171
|
-
|
172
|
-
it "updates words"
|
173
|
-
|
174
|
-
it "get all the words"
|
175
|
-
|
176
|
-
it "deletes a wordlist"
|
177
|
-
|
178
|
-
end
|
179
|
-
|
180
|
-
end
|
78
|
+
it "maps shorthand Wordnik.resource calls to their resources" do
|
79
|
+
Wordnik.word.class.should == Wordnik::Resource
|
80
|
+
Wordnik.word.name.should == :word
|
81
|
+
end
|
181
82
|
|
182
83
|
end
|
data/wordnik.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_dependency 'activemodel', '>=3.0.3'
|
22
22
|
s.add_dependency 'json', '>=1.4.6'
|
23
23
|
|
24
|
-
s.add_development_dependency 'rspec', '>=2.
|
24
|
+
s.add_development_dependency 'rspec', '>=2.5.0'
|
25
25
|
s.add_development_dependency 'vcr', '>=1.5.1'
|
26
26
|
s.add_development_dependency 'webmock', '>=1.6.2'
|
27
27
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: wordnik
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.4.
|
5
|
+
version: 0.4.6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Zeke Sikelianos
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-
|
14
|
+
date: 2011-05-03 00:00:00 -07:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -88,7 +88,7 @@ dependencies:
|
|
88
88
|
requirements:
|
89
89
|
- - ">="
|
90
90
|
- !ruby/object:Gem::Version
|
91
|
-
version: 2.
|
91
|
+
version: 2.5.0
|
92
92
|
type: :development
|
93
93
|
version_requirements: *id007
|
94
94
|
- !ruby/object:Gem::Dependency
|
@@ -125,6 +125,7 @@ extra_rdoc_files: []
|
|
125
125
|
|
126
126
|
files:
|
127
127
|
- .gitignore
|
128
|
+
- .rspec-tm
|
128
129
|
- Gemfile
|
129
130
|
- Gemfile.lock
|
130
131
|
- README.md
|
@@ -151,6 +152,13 @@ files:
|
|
151
152
|
- lib/wordnik/operation_parameter.rb
|
152
153
|
- lib/wordnik/request.rb
|
153
154
|
- lib/wordnik/resource.rb
|
155
|
+
- lib/wordnik/resource_modules/account.rb
|
156
|
+
- lib/wordnik/resource_modules/system.rb
|
157
|
+
- lib/wordnik/resource_modules/user.rb
|
158
|
+
- lib/wordnik/resource_modules/word.rb
|
159
|
+
- lib/wordnik/resource_modules/word_list.rb
|
160
|
+
- lib/wordnik/resource_modules/word_lists.rb
|
161
|
+
- lib/wordnik/resource_modules/words.rb
|
154
162
|
- lib/wordnik/response.rb
|
155
163
|
- lib/wordnik/version.rb
|
156
164
|
- spec/active_support_spec.rb
|