wordnik 0.4.5 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -0,0 +1,68 @@
|
|
1
|
+
# HEY HACKER! THIS IS AN AUTO-GENERATED FILE.
|
2
|
+
# So don't bother editing it. To see how it's built, take a look at the Rakefile
|
3
|
+
|
4
|
+
module WordListsMethods
|
5
|
+
|
6
|
+
# Returns information about API parameters
|
7
|
+
#
|
8
|
+
def get_help(*args)
|
9
|
+
http_method = :get
|
10
|
+
path = '/wordLists'
|
11
|
+
# Ruby turns all key-value arguments at the end into a single hash
|
12
|
+
# e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
|
13
|
+
# becomes {:limit => 10, :part_of_speech => 'verb'}
|
14
|
+
last_arg = args.pop if args.last.is_a?(Hash)
|
15
|
+
last_arg = args.pop if args.last.is_a?(Array)
|
16
|
+
last_arg ||= {}
|
17
|
+
|
18
|
+
# Look for a kwarg called :request_only, whose presence indicates
|
19
|
+
# that we want the request itself back, not the response body
|
20
|
+
if last_arg.is_a?(Hash) && last_arg[:request_only].present?
|
21
|
+
request_only = true
|
22
|
+
last_arg.delete(:request_only)
|
23
|
+
end
|
24
|
+
|
25
|
+
if [:post, :put].include?(http_method)
|
26
|
+
params = nil
|
27
|
+
body = last_arg
|
28
|
+
else
|
29
|
+
params = last_arg
|
30
|
+
body = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
|
34
|
+
request_only ? request : request.response.body
|
35
|
+
end
|
36
|
+
|
37
|
+
# Creates a WordList.
|
38
|
+
#
|
39
|
+
def create_word_list(*args)
|
40
|
+
http_method = :post
|
41
|
+
path = '/wordLists'
|
42
|
+
# Ruby turns all key-value arguments at the end into a single hash
|
43
|
+
# e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
|
44
|
+
# becomes {:limit => 10, :part_of_speech => 'verb'}
|
45
|
+
last_arg = args.pop if args.last.is_a?(Hash)
|
46
|
+
last_arg = args.pop if args.last.is_a?(Array)
|
47
|
+
last_arg ||= {}
|
48
|
+
|
49
|
+
# Look for a kwarg called :request_only, whose presence indicates
|
50
|
+
# that we want the request itself back, not the response body
|
51
|
+
if last_arg.is_a?(Hash) && last_arg[:request_only].present?
|
52
|
+
request_only = true
|
53
|
+
last_arg.delete(:request_only)
|
54
|
+
end
|
55
|
+
|
56
|
+
if [:post, :put].include?(http_method)
|
57
|
+
params = nil
|
58
|
+
body = last_arg
|
59
|
+
else
|
60
|
+
params = last_arg
|
61
|
+
body = nil
|
62
|
+
end
|
63
|
+
|
64
|
+
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
|
65
|
+
request_only ? request : request.response.body
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,482 @@
|
|
1
|
+
# HEY HACKER! THIS IS AN AUTO-GENERATED FILE.
|
2
|
+
# So don't bother editing it. To see how it's built, take a look at the Rakefile
|
3
|
+
|
4
|
+
module WordsMethods
|
5
|
+
|
6
|
+
# Returns a single random WordObject, in the format specified by the URL
|
7
|
+
#
|
8
|
+
def get_random_word(*args)
|
9
|
+
http_method = :get
|
10
|
+
path = '/words/randomWord'
|
11
|
+
# Ruby turns all key-value arguments at the end into a single hash
|
12
|
+
# e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
|
13
|
+
# becomes {:limit => 10, :part_of_speech => 'verb'}
|
14
|
+
last_arg = args.pop if args.last.is_a?(Hash)
|
15
|
+
last_arg = args.pop if args.last.is_a?(Array)
|
16
|
+
last_arg ||= {}
|
17
|
+
|
18
|
+
# Look for a kwarg called :request_only, whose presence indicates
|
19
|
+
# that we want the request itself back, not the response body
|
20
|
+
if last_arg.is_a?(Hash) && last_arg[:request_only].present?
|
21
|
+
request_only = true
|
22
|
+
last_arg.delete(:request_only)
|
23
|
+
end
|
24
|
+
|
25
|
+
if [:post, :put].include?(http_method)
|
26
|
+
params = nil
|
27
|
+
body = last_arg
|
28
|
+
else
|
29
|
+
params = last_arg
|
30
|
+
body = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
|
34
|
+
request_only ? request : request.response.body
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns an array of random WordObjects, in the format specified by the URL
|
38
|
+
#
|
39
|
+
def get_random_words(*args)
|
40
|
+
http_method = :get
|
41
|
+
path = '/words/randomWords'
|
42
|
+
# Ruby turns all key-value arguments at the end into a single hash
|
43
|
+
# e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
|
44
|
+
# becomes {:limit => 10, :part_of_speech => 'verb'}
|
45
|
+
last_arg = args.pop if args.last.is_a?(Hash)
|
46
|
+
last_arg = args.pop if args.last.is_a?(Array)
|
47
|
+
last_arg ||= {}
|
48
|
+
|
49
|
+
# Look for a kwarg called :request_only, whose presence indicates
|
50
|
+
# that we want the request itself back, not the response body
|
51
|
+
if last_arg.is_a?(Hash) && last_arg[:request_only].present?
|
52
|
+
request_only = true
|
53
|
+
last_arg.delete(:request_only)
|
54
|
+
end
|
55
|
+
|
56
|
+
if [:post, :put].include?(http_method)
|
57
|
+
params = nil
|
58
|
+
body = last_arg
|
59
|
+
else
|
60
|
+
params = last_arg
|
61
|
+
body = nil
|
62
|
+
end
|
63
|
+
|
64
|
+
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
|
65
|
+
request_only ? request : request.response.body
|
66
|
+
end
|
67
|
+
|
68
|
+
# Searches words.
|
69
|
+
#
|
70
|
+
def search_words(*args)
|
71
|
+
http_method = :get
|
72
|
+
path = '/words/search'
|
73
|
+
# Ruby turns all key-value arguments at the end into a single hash
|
74
|
+
# e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
|
75
|
+
# becomes {:limit => 10, :part_of_speech => 'verb'}
|
76
|
+
last_arg = args.pop if args.last.is_a?(Hash)
|
77
|
+
last_arg = args.pop if args.last.is_a?(Array)
|
78
|
+
last_arg ||= {}
|
79
|
+
|
80
|
+
# Look for a kwarg called :request_only, whose presence indicates
|
81
|
+
# that we want the request itself back, not the response body
|
82
|
+
if last_arg.is_a?(Hash) && last_arg[:request_only].present?
|
83
|
+
request_only = true
|
84
|
+
last_arg.delete(:request_only)
|
85
|
+
end
|
86
|
+
|
87
|
+
if [:post, :put].include?(http_method)
|
88
|
+
params = nil
|
89
|
+
body = last_arg
|
90
|
+
else
|
91
|
+
params = last_arg
|
92
|
+
body = nil
|
93
|
+
end
|
94
|
+
|
95
|
+
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
|
96
|
+
request_only ? request : request.response.body
|
97
|
+
end
|
98
|
+
|
99
|
+
# Fetches an array of WordOfTheDayList basd on a criteria
|
100
|
+
#
|
101
|
+
def get_word_of_the_day_lists_containing_word(*args)
|
102
|
+
http_method = :get
|
103
|
+
path = '/words/wordOfTheDayLists'
|
104
|
+
# Ruby turns all key-value arguments at the end into a single hash
|
105
|
+
# e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
|
106
|
+
# becomes {:limit => 10, :part_of_speech => 'verb'}
|
107
|
+
last_arg = args.pop if args.last.is_a?(Hash)
|
108
|
+
last_arg = args.pop if args.last.is_a?(Array)
|
109
|
+
last_arg ||= {}
|
110
|
+
|
111
|
+
# Look for a kwarg called :request_only, whose presence indicates
|
112
|
+
# that we want the request itself back, not the response body
|
113
|
+
if last_arg.is_a?(Hash) && last_arg[:request_only].present?
|
114
|
+
request_only = true
|
115
|
+
last_arg.delete(:request_only)
|
116
|
+
end
|
117
|
+
|
118
|
+
if [:post, :put].include?(http_method)
|
119
|
+
params = nil
|
120
|
+
body = last_arg
|
121
|
+
else
|
122
|
+
params = last_arg
|
123
|
+
body = nil
|
124
|
+
end
|
125
|
+
|
126
|
+
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
|
127
|
+
request_only ? request : request.response.body
|
128
|
+
end
|
129
|
+
|
130
|
+
# Fetches WordOfTheDay objects for a specific date
|
131
|
+
#
|
132
|
+
def get_word_of_the_day_lists_for_date(date, *args)
|
133
|
+
http_method = :get
|
134
|
+
path = '/words/wordOfTheDayLists/{date}'
|
135
|
+
path.sub!('{date}', date)
|
136
|
+
|
137
|
+
# Ruby turns all key-value arguments at the end into a single hash
|
138
|
+
# e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
|
139
|
+
# becomes {:limit => 10, :part_of_speech => 'verb'}
|
140
|
+
last_arg = args.pop if args.last.is_a?(Hash)
|
141
|
+
last_arg = args.pop if args.last.is_a?(Array)
|
142
|
+
last_arg ||= {}
|
143
|
+
|
144
|
+
# Look for a kwarg called :request_only, whose presence indicates
|
145
|
+
# that we want the request itself back, not the response body
|
146
|
+
if last_arg.is_a?(Hash) && last_arg[:request_only].present?
|
147
|
+
request_only = true
|
148
|
+
last_arg.delete(:request_only)
|
149
|
+
end
|
150
|
+
|
151
|
+
if [:post, :put].include?(http_method)
|
152
|
+
params = nil
|
153
|
+
body = last_arg
|
154
|
+
else
|
155
|
+
params = last_arg
|
156
|
+
body = nil
|
157
|
+
end
|
158
|
+
|
159
|
+
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
|
160
|
+
request_only ? request : request.response.body
|
161
|
+
end
|
162
|
+
|
163
|
+
# Subscribes a user to a WordOfTheDayList
|
164
|
+
#
|
165
|
+
def subscribe_to_list(permalink, *args)
|
166
|
+
http_method = :post
|
167
|
+
path = '/words/wordOfTheDayList/{permalink}/subscription'
|
168
|
+
path.sub!('{permalink}', permalink)
|
169
|
+
|
170
|
+
# Ruby turns all key-value arguments at the end into a single hash
|
171
|
+
# e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
|
172
|
+
# becomes {:limit => 10, :part_of_speech => 'verb'}
|
173
|
+
last_arg = args.pop if args.last.is_a?(Hash)
|
174
|
+
last_arg = args.pop if args.last.is_a?(Array)
|
175
|
+
last_arg ||= {}
|
176
|
+
|
177
|
+
# Look for a kwarg called :request_only, whose presence indicates
|
178
|
+
# that we want the request itself back, not the response body
|
179
|
+
if last_arg.is_a?(Hash) && last_arg[:request_only].present?
|
180
|
+
request_only = true
|
181
|
+
last_arg.delete(:request_only)
|
182
|
+
end
|
183
|
+
|
184
|
+
if [:post, :put].include?(http_method)
|
185
|
+
params = nil
|
186
|
+
body = last_arg
|
187
|
+
else
|
188
|
+
params = last_arg
|
189
|
+
body = nil
|
190
|
+
end
|
191
|
+
|
192
|
+
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
|
193
|
+
request_only ? request : request.response.body
|
194
|
+
end
|
195
|
+
|
196
|
+
# Searches definitions.
|
197
|
+
#
|
198
|
+
def search_definitions(*args)
|
199
|
+
http_method = :get
|
200
|
+
path = '/words/searchDefinitions'
|
201
|
+
# Ruby turns all key-value arguments at the end into a single hash
|
202
|
+
# e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
|
203
|
+
# becomes {:limit => 10, :part_of_speech => 'verb'}
|
204
|
+
last_arg = args.pop if args.last.is_a?(Hash)
|
205
|
+
last_arg = args.pop if args.last.is_a?(Array)
|
206
|
+
last_arg ||= {}
|
207
|
+
|
208
|
+
# Look for a kwarg called :request_only, whose presence indicates
|
209
|
+
# that we want the request itself back, not the response body
|
210
|
+
if last_arg.is_a?(Hash) && last_arg[:request_only].present?
|
211
|
+
request_only = true
|
212
|
+
last_arg.delete(:request_only)
|
213
|
+
end
|
214
|
+
|
215
|
+
if [:post, :put].include?(http_method)
|
216
|
+
params = nil
|
217
|
+
body = last_arg
|
218
|
+
else
|
219
|
+
params = last_arg
|
220
|
+
body = nil
|
221
|
+
end
|
222
|
+
|
223
|
+
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
|
224
|
+
request_only ? request : request.response.body
|
225
|
+
end
|
226
|
+
|
227
|
+
# Searches dictionary entries.
|
228
|
+
#
|
229
|
+
def search_entries(*args)
|
230
|
+
http_method = :get
|
231
|
+
path = '/words/searchEntries'
|
232
|
+
# Ruby turns all key-value arguments at the end into a single hash
|
233
|
+
# e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
|
234
|
+
# becomes {:limit => 10, :part_of_speech => 'verb'}
|
235
|
+
last_arg = args.pop if args.last.is_a?(Hash)
|
236
|
+
last_arg = args.pop if args.last.is_a?(Array)
|
237
|
+
last_arg ||= {}
|
238
|
+
|
239
|
+
# Look for a kwarg called :request_only, whose presence indicates
|
240
|
+
# that we want the request itself back, not the response body
|
241
|
+
if last_arg.is_a?(Hash) && last_arg[:request_only].present?
|
242
|
+
request_only = true
|
243
|
+
last_arg.delete(:request_only)
|
244
|
+
end
|
245
|
+
|
246
|
+
if [:post, :put].include?(http_method)
|
247
|
+
params = nil
|
248
|
+
body = last_arg
|
249
|
+
else
|
250
|
+
params = last_arg
|
251
|
+
body = nil
|
252
|
+
end
|
253
|
+
|
254
|
+
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
|
255
|
+
request_only ? request : request.response.body
|
256
|
+
end
|
257
|
+
|
258
|
+
# Fetches surface forms of a word
|
259
|
+
#
|
260
|
+
def get_surface_forms(*args)
|
261
|
+
http_method = :get
|
262
|
+
path = '/words/surfaceForms'
|
263
|
+
# Ruby turns all key-value arguments at the end into a single hash
|
264
|
+
# e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
|
265
|
+
# becomes {:limit => 10, :part_of_speech => 'verb'}
|
266
|
+
last_arg = args.pop if args.last.is_a?(Hash)
|
267
|
+
last_arg = args.pop if args.last.is_a?(Array)
|
268
|
+
last_arg ||= {}
|
269
|
+
|
270
|
+
# Look for a kwarg called :request_only, whose presence indicates
|
271
|
+
# that we want the request itself back, not the response body
|
272
|
+
if last_arg.is_a?(Hash) && last_arg[:request_only].present?
|
273
|
+
request_only = true
|
274
|
+
last_arg.delete(:request_only)
|
275
|
+
end
|
276
|
+
|
277
|
+
if [:post, :put].include?(http_method)
|
278
|
+
params = nil
|
279
|
+
body = last_arg
|
280
|
+
else
|
281
|
+
params = last_arg
|
282
|
+
body = nil
|
283
|
+
end
|
284
|
+
|
285
|
+
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
|
286
|
+
request_only ? request : request.response.body
|
287
|
+
end
|
288
|
+
|
289
|
+
# Returns a specific WordOfTheDay
|
290
|
+
#
|
291
|
+
def get_word_of_the_day(*args)
|
292
|
+
http_method = :get
|
293
|
+
path = '/words/wordOfTheDay'
|
294
|
+
# Ruby turns all key-value arguments at the end into a single hash
|
295
|
+
# e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
|
296
|
+
# becomes {:limit => 10, :part_of_speech => 'verb'}
|
297
|
+
last_arg = args.pop if args.last.is_a?(Hash)
|
298
|
+
last_arg = args.pop if args.last.is_a?(Array)
|
299
|
+
last_arg ||= {}
|
300
|
+
|
301
|
+
# Look for a kwarg called :request_only, whose presence indicates
|
302
|
+
# that we want the request itself back, not the response body
|
303
|
+
if last_arg.is_a?(Hash) && last_arg[:request_only].present?
|
304
|
+
request_only = true
|
305
|
+
last_arg.delete(:request_only)
|
306
|
+
end
|
307
|
+
|
308
|
+
if [:post, :put].include?(http_method)
|
309
|
+
params = nil
|
310
|
+
body = last_arg
|
311
|
+
else
|
312
|
+
params = last_arg
|
313
|
+
body = nil
|
314
|
+
end
|
315
|
+
|
316
|
+
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
|
317
|
+
request_only ? request : request.response.body
|
318
|
+
end
|
319
|
+
|
320
|
+
# Returns a WordOfTheDay range
|
321
|
+
#
|
322
|
+
def get_word_of_the_day_range(*args)
|
323
|
+
http_method = :get
|
324
|
+
path = '/words/wordOfTheDay/range'
|
325
|
+
# Ruby turns all key-value arguments at the end into a single hash
|
326
|
+
# e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
|
327
|
+
# becomes {:limit => 10, :part_of_speech => 'verb'}
|
328
|
+
last_arg = args.pop if args.last.is_a?(Hash)
|
329
|
+
last_arg = args.pop if args.last.is_a?(Array)
|
330
|
+
last_arg ||= {}
|
331
|
+
|
332
|
+
# Look for a kwarg called :request_only, whose presence indicates
|
333
|
+
# that we want the request itself back, not the response body
|
334
|
+
if last_arg.is_a?(Hash) && last_arg[:request_only].present?
|
335
|
+
request_only = true
|
336
|
+
last_arg.delete(:request_only)
|
337
|
+
end
|
338
|
+
|
339
|
+
if [:post, :put].include?(http_method)
|
340
|
+
params = nil
|
341
|
+
body = last_arg
|
342
|
+
else
|
343
|
+
params = last_arg
|
344
|
+
body = nil
|
345
|
+
end
|
346
|
+
|
347
|
+
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
|
348
|
+
request_only ? request : request.response.body
|
349
|
+
end
|
350
|
+
|
351
|
+
# Fetches a WordOfTheDayList by ID
|
352
|
+
#
|
353
|
+
def get_word_of_the_day_list(permalink, *args)
|
354
|
+
http_method = :get
|
355
|
+
path = '/words/wordOfTheDayList/{permalink}'
|
356
|
+
path.sub!('{permalink}', permalink)
|
357
|
+
|
358
|
+
# Ruby turns all key-value arguments at the end into a single hash
|
359
|
+
# e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
|
360
|
+
# becomes {:limit => 10, :part_of_speech => 'verb'}
|
361
|
+
last_arg = args.pop if args.last.is_a?(Hash)
|
362
|
+
last_arg = args.pop if args.last.is_a?(Array)
|
363
|
+
last_arg ||= {}
|
364
|
+
|
365
|
+
# Look for a kwarg called :request_only, whose presence indicates
|
366
|
+
# that we want the request itself back, not the response body
|
367
|
+
if last_arg.is_a?(Hash) && last_arg[:request_only].present?
|
368
|
+
request_only = true
|
369
|
+
last_arg.delete(:request_only)
|
370
|
+
end
|
371
|
+
|
372
|
+
if [:post, :put].include?(http_method)
|
373
|
+
params = nil
|
374
|
+
body = last_arg
|
375
|
+
else
|
376
|
+
params = last_arg
|
377
|
+
body = nil
|
378
|
+
end
|
379
|
+
|
380
|
+
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
|
381
|
+
request_only ? request : request.response.body
|
382
|
+
end
|
383
|
+
|
384
|
+
# Fetches a WordOfTheDayList by ID
|
385
|
+
#
|
386
|
+
def get_word_of_the_day_list_item(permalink, specifier, *args)
|
387
|
+
http_method = :get
|
388
|
+
path = '/words/wordOfTheDayList/{permalink}/{specifier}'
|
389
|
+
path.sub!('{permalink}', permalink)
|
390
|
+
|
391
|
+
path.sub!('{specifier}', specifier)
|
392
|
+
|
393
|
+
# Ruby turns all key-value arguments at the end into a single hash
|
394
|
+
# e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
|
395
|
+
# becomes {:limit => 10, :part_of_speech => 'verb'}
|
396
|
+
last_arg = args.pop if args.last.is_a?(Hash)
|
397
|
+
last_arg = args.pop if args.last.is_a?(Array)
|
398
|
+
last_arg ||= {}
|
399
|
+
|
400
|
+
# Look for a kwarg called :request_only, whose presence indicates
|
401
|
+
# that we want the request itself back, not the response body
|
402
|
+
if last_arg.is_a?(Hash) && last_arg[:request_only].present?
|
403
|
+
request_only = true
|
404
|
+
last_arg.delete(:request_only)
|
405
|
+
end
|
406
|
+
|
407
|
+
if [:post, :put].include?(http_method)
|
408
|
+
params = nil
|
409
|
+
body = last_arg
|
410
|
+
else
|
411
|
+
params = last_arg
|
412
|
+
body = nil
|
413
|
+
end
|
414
|
+
|
415
|
+
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
|
416
|
+
request_only ? request : request.response.body
|
417
|
+
end
|
418
|
+
|
419
|
+
# Fetches recently created WordOfTheDayLists
|
420
|
+
#
|
421
|
+
def get_recent_word_of_the_day_lists(*args)
|
422
|
+
http_method = :get
|
423
|
+
path = '/words/wordOfTheDayLists/recent'
|
424
|
+
# Ruby turns all key-value arguments at the end into a single hash
|
425
|
+
# e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
|
426
|
+
# becomes {:limit => 10, :part_of_speech => 'verb'}
|
427
|
+
last_arg = args.pop if args.last.is_a?(Hash)
|
428
|
+
last_arg = args.pop if args.last.is_a?(Array)
|
429
|
+
last_arg ||= {}
|
430
|
+
|
431
|
+
# Look for a kwarg called :request_only, whose presence indicates
|
432
|
+
# that we want the request itself back, not the response body
|
433
|
+
if last_arg.is_a?(Hash) && last_arg[:request_only].present?
|
434
|
+
request_only = true
|
435
|
+
last_arg.delete(:request_only)
|
436
|
+
end
|
437
|
+
|
438
|
+
if [:post, :put].include?(http_method)
|
439
|
+
params = nil
|
440
|
+
body = last_arg
|
441
|
+
else
|
442
|
+
params = last_arg
|
443
|
+
body = nil
|
444
|
+
end
|
445
|
+
|
446
|
+
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
|
447
|
+
request_only ? request : request.response.body
|
448
|
+
end
|
449
|
+
|
450
|
+
# Returns whether or not a subscription process has been run.
|
451
|
+
# Uses the current server time (day resolution) as the default date to check for, optionally a dateString can be supplied for a specific date to check for.
|
452
|
+
#
|
453
|
+
def get_word_of_the_day_list_subscription_process_status(*args)
|
454
|
+
http_method = :get
|
455
|
+
path = '/words/wordOfTheDayLists/subscriptionProcess'
|
456
|
+
# Ruby turns all key-value arguments at the end into a single hash
|
457
|
+
# e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
|
458
|
+
# becomes {:limit => 10, :part_of_speech => 'verb'}
|
459
|
+
last_arg = args.pop if args.last.is_a?(Hash)
|
460
|
+
last_arg = args.pop if args.last.is_a?(Array)
|
461
|
+
last_arg ||= {}
|
462
|
+
|
463
|
+
# Look for a kwarg called :request_only, whose presence indicates
|
464
|
+
# that we want the request itself back, not the response body
|
465
|
+
if last_arg.is_a?(Hash) && last_arg[:request_only].present?
|
466
|
+
request_only = true
|
467
|
+
last_arg.delete(:request_only)
|
468
|
+
end
|
469
|
+
|
470
|
+
if [:post, :put].include?(http_method)
|
471
|
+
params = nil
|
472
|
+
body = last_arg
|
473
|
+
else
|
474
|
+
params = last_arg
|
475
|
+
body = nil
|
476
|
+
end
|
477
|
+
|
478
|
+
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
|
479
|
+
request_only ? request : request.response.body
|
480
|
+
end
|
481
|
+
|
482
|
+
end
|
data/lib/wordnik/version.rb
CHANGED
data/lib/wordnik.rb
CHANGED
@@ -48,6 +48,13 @@ module Wordnik
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
# The names of all the resources (in the production API).
|
52
|
+
# This is used by Wordnik.build_resources and the rake task that fetches remote API docs
|
53
|
+
#
|
54
|
+
def resource_names
|
55
|
+
%w(account corpus document partners system tag user users word words wordList wordLists)
|
56
|
+
end
|
57
|
+
|
51
58
|
def authenticated?
|
52
59
|
Wordnik.configuration.user_id.present? && Wordnik.configuration.auth_token.present?
|
53
60
|
end
|
@@ -64,7 +71,16 @@ module Wordnik
|
|
64
71
|
raise ConfigurationError, "Username and password are required to authenticate."
|
65
72
|
end
|
66
73
|
|
67
|
-
response_body = Wordnik.account.get_authenticate(Wordnik.configuration.username, :password => Wordnik.configuration.password)
|
74
|
+
# response_body = Wordnik.account.get_authenticate(Wordnik.configuration.username, :password => Wordnik.configuration.password)
|
75
|
+
|
76
|
+
request = Wordnik::Request.new(
|
77
|
+
:get,
|
78
|
+
"account/authenticate/{username}",
|
79
|
+
:params => {:username => Wordnik.configuration.username, :password => Wordnik.configuration.password}
|
80
|
+
)
|
81
|
+
|
82
|
+
response_body = request.response.body
|
83
|
+
|
68
84
|
if response_body.is_a?(Hash) && response_body['userId'].present? && response_body['token'].present?
|
69
85
|
Wordnik.configuration.user_id = response_body['userId']
|
70
86
|
Wordnik.configuration.auth_token = response_body['token']
|
@@ -72,14 +88,7 @@ module Wordnik
|
|
72
88
|
raise ApiServerError, response_body.to_s
|
73
89
|
end
|
74
90
|
end
|
75
|
-
|
76
|
-
# The names of all the resources (in the production API).
|
77
|
-
# This is used by Wordnik.build_resources and the rake task that fetches remote API docs
|
78
|
-
#
|
79
|
-
def resource_names
|
80
|
-
%w(account corpus document partners system tag user users word words wordList wordLists wordoftheday)
|
81
|
-
end
|
82
|
-
|
91
|
+
|
83
92
|
# Aliases. For convenience.
|
84
93
|
#
|
85
94
|
def account; Wordnik.resources[:account]; end
|
@@ -95,8 +104,7 @@ module Wordnik
|
|
95
104
|
def words; Wordnik.resources[:words]; end
|
96
105
|
def word_list; Wordnik.resources[:word_list]; end
|
97
106
|
def word_lists; Wordnik.resources[:word_lists]; end
|
98
|
-
|
99
|
-
|
107
|
+
|
100
108
|
end
|
101
109
|
|
102
110
|
end
|
data/spec/endpoint_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe Wordnik::Endpoint 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
|
@resource = Wordnik::Resource.new(:name => "word", :raw_data => JSON.parse(@response.body))
|
10
10
|
@endpoint = @resource.endpoints.first
|
@@ -4,7 +4,7 @@ describe Wordnik::OperationParameter 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
|
@operation_parameter = Wordnik::OperationParameter.new(JSON.parse(@response.body)['endPoints'].first['operations'].first['parameters'].first)
|
data/spec/operation_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe Wordnik::Operation 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
|
@resource = Wordnik::Resource.new(:name => "word", :raw_data => JSON.parse(@response.body))
|
10
10
|
@endpoint = @resource.endpoints.first
|
data/spec/request_spec.rb
CHANGED
@@ -162,7 +162,11 @@ describe Wordnik::Request do
|
|
162
162
|
@request.query_string.should == "?badDog=bud&goodDog=dud"
|
163
163
|
end
|
164
164
|
|
165
|
-
it "converts boolean values to their string representation"
|
165
|
+
it "converts boolean values to their string representation" do
|
166
|
+
params = {:stringy => "fish", :truthy => true, :falsey => false}
|
167
|
+
@request = Wordnik::Request.new(:get, 'fakeMethod', :params => params)
|
168
|
+
@request.query_string.should == "?falsey=false&stringy=fish&truthy=true"
|
169
|
+
end
|
166
170
|
|
167
171
|
end
|
168
172
|
|