wordnik 0.4.7 → 4.06.00

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,12 +3,743 @@
3
3
 
4
4
  module WordMethods
5
5
 
6
+ # Return entries for a word
7
+ #
8
+ def get_entries(word, *args)
9
+ http_method = :get
10
+ path = '/word/{word}/entries'
11
+ path.sub!('{word}', word.to_s)
12
+
13
+ # Ruby turns all key-value arguments at the end into a single hash
14
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
15
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
16
+ last_arg = args.pop if args.last.is_a?(Hash)
17
+ last_arg = args.pop if args.last.is_a?(Array)
18
+ last_arg ||= {}
19
+
20
+ # Look for a kwarg called :request_only, whose presence indicates
21
+ # that we want the request itself back, not the response body
22
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
23
+ request_only = true
24
+ last_arg.delete(:request_only)
25
+ end
26
+
27
+ params = last_arg
28
+ body ||= {}
29
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
30
+ request_only ? request : request.response.body
31
+ end
32
+
33
+ # Returns examples for a word
34
+ #
35
+ def get_examples(word, *args)
36
+ http_method = :get
37
+ path = '/word/{word}/examples'
38
+ path.sub!('{word}', word.to_s)
39
+
40
+ # Ruby turns all key-value arguments at the end into a single hash
41
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
42
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
43
+ last_arg = args.pop if args.last.is_a?(Hash)
44
+ last_arg = args.pop if args.last.is_a?(Array)
45
+ last_arg ||= {}
46
+
47
+ # Look for a kwarg called :request_only, whose presence indicates
48
+ # that we want the request itself back, not the response body
49
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
50
+ request_only = true
51
+ last_arg.delete(:request_only)
52
+ end
53
+
54
+ params = last_arg
55
+ body ||= {}
56
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
57
+ request_only ? request : request.response.body
58
+ end
59
+
60
+ # Fetches examples for a word
61
+ #
62
+ def get_examples_post(word, body, *args)
63
+ http_method = :post
64
+ path = '/word/{word}/examples'
65
+ path.sub!('{word}', word.to_s)
66
+
67
+ # Ruby turns all key-value arguments at the end into a single hash
68
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
69
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
70
+ last_arg = args.pop if args.last.is_a?(Hash)
71
+ last_arg = args.pop if args.last.is_a?(Array)
72
+ last_arg ||= {}
73
+
74
+ # Look for a kwarg called :request_only, whose presence indicates
75
+ # that we want the request itself back, not the response body
76
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
77
+ request_only = true
78
+ last_arg.delete(:request_only)
79
+ end
80
+
81
+ params = last_arg
82
+ body ||= {}
83
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
84
+ request_only ? request : request.response.body
85
+ end
86
+
87
+ # Adds a Relationship Map to a word
88
+ #
89
+ def add_word_form(word, body, *args)
90
+ http_method = :post
91
+ path = '/word/{word}/wordForms'
92
+ path.sub!('{word}', word.to_s)
93
+
94
+ # Ruby turns all key-value arguments at the end into a single hash
95
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
96
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
97
+ last_arg = args.pop if args.last.is_a?(Hash)
98
+ last_arg = args.pop if args.last.is_a?(Array)
99
+ last_arg ||= {}
100
+
101
+ # Look for a kwarg called :request_only, whose presence indicates
102
+ # that we want the request itself back, not the response body
103
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
104
+ request_only = true
105
+ last_arg.delete(:request_only)
106
+ end
107
+
108
+ params = last_arg
109
+ body ||= {}
110
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
111
+ request_only ? request : request.response.body
112
+ end
113
+
114
+ # Returns other forms of a word
115
+ #
116
+ def get_word_forms(word, *args)
117
+ http_method = :get
118
+ path = '/word/{word}/wordForms'
119
+ path.sub!('{word}', word.to_s)
120
+
121
+ # Ruby turns all key-value arguments at the end into a single hash
122
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
123
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
124
+ last_arg = args.pop if args.last.is_a?(Hash)
125
+ last_arg = args.pop if args.last.is_a?(Array)
126
+ last_arg ||= {}
127
+
128
+ # Look for a kwarg called :request_only, whose presence indicates
129
+ # that we want the request itself back, not the response body
130
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
131
+ request_only = true
132
+ last_arg.delete(:request_only)
133
+ end
134
+
135
+ params = last_arg
136
+ body ||= {}
137
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
138
+ request_only ? request : request.response.body
139
+ end
140
+
141
+ # Deletes a relationship from a word
142
+ #
143
+ def delete_word_form(word, *args)
144
+ http_method = :delete
145
+ path = '/word/{word}/wordForms'
146
+ path.sub!('{word}', word.to_s)
147
+
148
+ # Ruby turns all key-value arguments at the end into a single hash
149
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
150
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
151
+ last_arg = args.pop if args.last.is_a?(Hash)
152
+ last_arg = args.pop if args.last.is_a?(Array)
153
+ last_arg ||= {}
154
+
155
+ # Look for a kwarg called :request_only, whose presence indicates
156
+ # that we want the request itself back, not the response body
157
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
158
+ request_only = true
159
+ last_arg.delete(:request_only)
160
+ end
161
+
162
+ params = last_arg
163
+ body ||= {}
164
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
165
+ request_only ? request : request.response.body
166
+ end
167
+
6
168
  # Given a word as a string, returns the WordObject that represents it
7
169
  #
8
170
  def get_word(word, *args)
9
171
  http_method = :get
10
- path = '/word/{word}'
11
- path.sub!('{word}', word)
172
+ path = '/word/{word}'
173
+ path.sub!('{word}', word.to_s)
174
+
175
+ # Ruby turns all key-value arguments at the end into a single hash
176
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
177
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
178
+ last_arg = args.pop if args.last.is_a?(Hash)
179
+ last_arg = args.pop if args.last.is_a?(Array)
180
+ last_arg ||= {}
181
+
182
+ # Look for a kwarg called :request_only, whose presence indicates
183
+ # that we want the request itself back, not the response body
184
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
185
+ request_only = true
186
+ last_arg.delete(:request_only)
187
+ end
188
+
189
+ params = last_arg
190
+ body ||= {}
191
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
192
+ request_only ? request : request.response.body
193
+ end
194
+
195
+ # Return definitions for a word
196
+ #
197
+ def get_definitions(word, *args)
198
+ http_method = :get
199
+ path = '/word/{word}/definitions'
200
+ path.sub!('{word}', word.to_s)
201
+
202
+ # Ruby turns all key-value arguments at the end into a single hash
203
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
204
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
205
+ last_arg = args.pop if args.last.is_a?(Hash)
206
+ last_arg = args.pop if args.last.is_a?(Array)
207
+ last_arg ||= {}
208
+
209
+ # Look for a kwarg called :request_only, whose presence indicates
210
+ # that we want the request itself back, not the response body
211
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
212
+ request_only = true
213
+ last_arg.delete(:request_only)
214
+ end
215
+
216
+ params = last_arg
217
+ body ||= {}
218
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
219
+ request_only ? request : request.response.body
220
+ end
221
+
222
+ # Returns word statistics
223
+ #
224
+ def get_word_stats(word, *args)
225
+ http_method = :get
226
+ path = '/word/{word}/stats'
227
+ path.sub!('{word}', word.to_s)
228
+
229
+ # Ruby turns all key-value arguments at the end into a single hash
230
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
231
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
232
+ last_arg = args.pop if args.last.is_a?(Hash)
233
+ last_arg = args.pop if args.last.is_a?(Array)
234
+ last_arg ||= {}
235
+
236
+ # Look for a kwarg called :request_only, whose presence indicates
237
+ # that we want the request itself back, not the response body
238
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
239
+ request_only = true
240
+ last_arg.delete(:request_only)
241
+ end
242
+
243
+ params = last_arg
244
+ body ||= {}
245
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
246
+ request_only ? request : request.response.body
247
+ end
248
+
249
+ # Returns information about API parameters
250
+ #
251
+ def get_help(*args)
252
+ http_method = :get
253
+ path = '/word'
254
+
255
+ # Ruby turns all key-value arguments at the end into a single hash
256
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
257
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
258
+ last_arg = args.pop if args.last.is_a?(Hash)
259
+ last_arg = args.pop if args.last.is_a?(Array)
260
+ last_arg ||= {}
261
+
262
+ # Look for a kwarg called :request_only, whose presence indicates
263
+ # that we want the request itself back, not the response body
264
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
265
+ request_only = true
266
+ last_arg.delete(:request_only)
267
+ end
268
+
269
+ params = last_arg
270
+ body ||= {}
271
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
272
+ request_only ? request : request.response.body
273
+ end
274
+
275
+ # Returns a top example for a word
276
+ #
277
+ def get_top_example(word, *args)
278
+ http_method = :get
279
+ path = '/word/{word}/topExample'
280
+ path.sub!('{word}', word.to_s)
281
+
282
+ # Ruby turns all key-value arguments at the end into a single hash
283
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
284
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
285
+ last_arg = args.pop if args.last.is_a?(Hash)
286
+ last_arg = args.pop if args.last.is_a?(Array)
287
+ last_arg ||= {}
288
+
289
+ # Look for a kwarg called :request_only, whose presence indicates
290
+ # that we want the request itself back, not the response body
291
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
292
+ request_only = true
293
+ last_arg.delete(:request_only)
294
+ end
295
+
296
+ params = last_arg
297
+ body ||= {}
298
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
299
+ request_only ? request : request.response.body
300
+ end
301
+
302
+ # Fetches other forms of a word
303
+ # Deprecated
304
+ #
305
+ def get_punctuation_factor(word, *args)
306
+ http_method = :get
307
+ path = '/word/{word}/punctuationFactor'
308
+ path.sub!('{word}', word.to_s)
309
+
310
+ # Ruby turns all key-value arguments at the end into a single hash
311
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
312
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
313
+ last_arg = args.pop if args.last.is_a?(Hash)
314
+ last_arg = args.pop if args.last.is_a?(Array)
315
+ last_arg ||= {}
316
+
317
+ # Look for a kwarg called :request_only, whose presence indicates
318
+ # that we want the request itself back, not the response body
319
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
320
+ request_only = true
321
+ last_arg.delete(:request_only)
322
+ end
323
+
324
+ params = last_arg
325
+ body ||= {}
326
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
327
+ request_only ? request : request.response.body
328
+ end
329
+
330
+ # Returns definitions for a word based on the sentence in which it is found
331
+ # Use the offset parameter when the word occurs more than once in the sentence
332
+ #
333
+ def contextual_lookup(word, *args)
334
+ http_method = :get
335
+ path = '/word/{word}/contextualLookup'
336
+ path.sub!('{word}', word.to_s)
337
+
338
+ # Ruby turns all key-value arguments at the end into a single hash
339
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
340
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
341
+ last_arg = args.pop if args.last.is_a?(Hash)
342
+ last_arg = args.pop if args.last.is_a?(Array)
343
+ last_arg ||= {}
344
+
345
+ # Look for a kwarg called :request_only, whose presence indicates
346
+ # that we want the request itself back, not the response body
347
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
348
+ request_only = true
349
+ last_arg.delete(:request_only)
350
+ end
351
+
352
+ params = last_arg
353
+ body ||= {}
354
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
355
+ request_only ? request : request.response.body
356
+ end
357
+
358
+ # Returns definitions for a word based on the sentence in which it is found
359
+ # Use the offset parameter when the word occurs more than once in the sentence
360
+ #
361
+ def contextual_lookup_post(word, body, *args)
362
+ http_method = :post
363
+ path = '/word/{word}/contextualLookup'
364
+ path.sub!('{word}', word.to_s)
365
+
366
+ # Ruby turns all key-value arguments at the end into a single hash
367
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
368
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
369
+ last_arg = args.pop if args.last.is_a?(Hash)
370
+ last_arg = args.pop if args.last.is_a?(Array)
371
+ last_arg ||= {}
372
+
373
+ # Look for a kwarg called :request_only, whose presence indicates
374
+ # that we want the request itself back, not the response body
375
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
376
+ request_only = true
377
+ last_arg.delete(:request_only)
378
+ end
379
+
380
+ params = last_arg
381
+ body ||= {}
382
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
383
+ request_only ? request : request.response.body
384
+ end
385
+
386
+ # Returns the number of comments on a word
387
+ #
388
+ def get_comment_count(word, *args)
389
+ http_method = :get
390
+ path = '/word/{word}/commentCount'
391
+ path.sub!('{word}', word.to_s)
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
+ params = last_arg
408
+ body ||= {}
409
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
410
+ request_only ? request : request.response.body
411
+ end
412
+
413
+ # Return related words (thesaurus data) for a word
414
+ #
415
+ def get_related_words(word, *args)
416
+ http_method = :get
417
+ path = '/word/{word}/related'
418
+ path.sub!('{word}', word.to_s)
419
+
420
+ # Ruby turns all key-value arguments at the end into a single hash
421
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
422
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
423
+ last_arg = args.pop if args.last.is_a?(Hash)
424
+ last_arg = args.pop if args.last.is_a?(Array)
425
+ last_arg ||= {}
426
+
427
+ # Look for a kwarg called :request_only, whose presence indicates
428
+ # that we want the request itself back, not the response body
429
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
430
+ request_only = true
431
+ last_arg.delete(:request_only)
432
+ end
433
+
434
+ params = last_arg
435
+ body ||= {}
436
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
437
+ request_only ? request : request.response.body
438
+ end
439
+
440
+ # Returns WordLists containing a word
441
+ #
442
+ def get_listed_in(word, *args)
443
+ http_method = :get
444
+ path = '/word/{word}/listedIn'
445
+ path.sub!('{word}', word.to_s)
446
+
447
+ # Ruby turns all key-value arguments at the end into a single hash
448
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
449
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
450
+ last_arg = args.pop if args.last.is_a?(Hash)
451
+ last_arg = args.pop if args.last.is_a?(Array)
452
+ last_arg ||= {}
453
+
454
+ # Look for a kwarg called :request_only, whose presence indicates
455
+ # that we want the request itself back, not the response body
456
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
457
+ request_only = true
458
+ last_arg.delete(:request_only)
459
+ end
460
+
461
+ params = last_arg
462
+ body ||= {}
463
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
464
+ request_only ? request : request.response.body
465
+ end
466
+
467
+ # Returns a count of lists a word appears in
468
+ #
469
+ def get_listed_in_count(word, *args)
470
+ http_method = :get
471
+ path = '/word/{word}/listedInCount'
472
+ path.sub!('{word}', word.to_s)
473
+
474
+ # Ruby turns all key-value arguments at the end into a single hash
475
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
476
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
477
+ last_arg = args.pop if args.last.is_a?(Hash)
478
+ last_arg = args.pop if args.last.is_a?(Array)
479
+ last_arg ||= {}
480
+
481
+ # Look for a kwarg called :request_only, whose presence indicates
482
+ # that we want the request itself back, not the response body
483
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
484
+ request_only = true
485
+ last_arg.delete(:request_only)
486
+ end
487
+
488
+ params = last_arg
489
+ body ||= {}
490
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
491
+ request_only ? request : request.response.body
492
+ end
493
+
494
+ # Returns the first WordList a word appeared in
495
+ #
496
+ def get_first_listed_in(word, *args)
497
+ http_method = :get
498
+ path = '/word/{word}/firstListedIn'
499
+ path.sub!('{word}', word.to_s)
500
+
501
+ # Ruby turns all key-value arguments at the end into a single hash
502
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
503
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
504
+ last_arg = args.pop if args.last.is_a?(Hash)
505
+ last_arg = args.pop if args.last.is_a?(Array)
506
+ last_arg ||= {}
507
+
508
+ # Look for a kwarg called :request_only, whose presence indicates
509
+ # that we want the request itself back, not the response body
510
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
511
+ request_only = true
512
+ last_arg.delete(:request_only)
513
+ end
514
+
515
+ params = last_arg
516
+ body ||= {}
517
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
518
+ request_only ? request : request.response.body
519
+ end
520
+
521
+ # Returns the first User to list a particular word
522
+ #
523
+ def get_first_listed_by(word, *args)
524
+ http_method = :get
525
+ path = '/word/{word}/firstListedBy'
526
+ path.sub!('{word}', word.to_s)
527
+
528
+ # Ruby turns all key-value arguments at the end into a single hash
529
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
530
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
531
+ last_arg = args.pop if args.last.is_a?(Hash)
532
+ last_arg = args.pop if args.last.is_a?(Array)
533
+ last_arg ||= {}
534
+
535
+ # Look for a kwarg called :request_only, whose presence indicates
536
+ # that we want the request itself back, not the response body
537
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
538
+ request_only = true
539
+ last_arg.delete(:request_only)
540
+ end
541
+
542
+ params = last_arg
543
+ body ||= {}
544
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
545
+ request_only ? request : request.response.body
546
+ end
547
+
548
+ # Returns text pronunciations for a given word
549
+ #
550
+ def get_text_pronunciations(word, *args)
551
+ http_method = :get
552
+ path = '/word/{word}/pronunciations'
553
+ path.sub!('{word}', word.to_s)
554
+
555
+ # Ruby turns all key-value arguments at the end into a single hash
556
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
557
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
558
+ last_arg = args.pop if args.last.is_a?(Hash)
559
+ last_arg = args.pop if args.last.is_a?(Array)
560
+ last_arg ||= {}
561
+
562
+ # Look for a kwarg called :request_only, whose presence indicates
563
+ # that we want the request itself back, not the response body
564
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
565
+ request_only = true
566
+ last_arg.delete(:request_only)
567
+ end
568
+
569
+ params = last_arg
570
+ body ||= {}
571
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
572
+ request_only ? request : request.response.body
573
+ end
574
+
575
+ # Returns Flickr images for a word
576
+ #
577
+ def get_flickr_images(word, *args)
578
+ http_method = :get
579
+ path = '/word/{word}/images/flickr'
580
+ path.sub!('{word}', word.to_s)
581
+
582
+ # Ruby turns all key-value arguments at the end into a single hash
583
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
584
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
585
+ last_arg = args.pop if args.last.is_a?(Hash)
586
+ last_arg = args.pop if args.last.is_a?(Array)
587
+ last_arg ||= {}
588
+
589
+ # Look for a kwarg called :request_only, whose presence indicates
590
+ # that we want the request itself back, not the response body
591
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
592
+ request_only = true
593
+ last_arg.delete(:request_only)
594
+ end
595
+
596
+ params = last_arg
597
+ body ||= {}
598
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
599
+ request_only ? request : request.response.body
600
+ end
601
+
602
+ # Returns the Scrabble score for a word
603
+ #
604
+ def get_scrabble_score(word, *args)
605
+ http_method = :get
606
+ path = '/word/{word}/scrabbleScore'
607
+ path.sub!('{word}', word.to_s)
608
+
609
+ # Ruby turns all key-value arguments at the end into a single hash
610
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
611
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
612
+ last_arg = args.pop if args.last.is_a?(Hash)
613
+ last_arg = args.pop if args.last.is_a?(Array)
614
+ last_arg ||= {}
615
+
616
+ # Look for a kwarg called :request_only, whose presence indicates
617
+ # that we want the request itself back, not the response body
618
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
619
+ request_only = true
620
+ last_arg.delete(:request_only)
621
+ end
622
+
623
+ params = last_arg
624
+ body ||= {}
625
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
626
+ request_only ? request : request.response.body
627
+ end
628
+
629
+ # Returns citations for a word
630
+ #
631
+ def get_citations(word, *args)
632
+ http_method = :get
633
+ path = '/word/{word}/citations'
634
+ path.sub!('{word}', word.to_s)
635
+
636
+ # Ruby turns all key-value arguments at the end into a single hash
637
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
638
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
639
+ last_arg = args.pop if args.last.is_a?(Hash)
640
+ last_arg = args.pop if args.last.is_a?(Array)
641
+ last_arg ||= {}
642
+
643
+ # Look for a kwarg called :request_only, whose presence indicates
644
+ # that we want the request itself back, not the response body
645
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
646
+ request_only = true
647
+ last_arg.delete(:request_only)
648
+ end
649
+
650
+ params = last_arg
651
+ body ||= {}
652
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
653
+ request_only ? request : request.response.body
654
+ end
655
+
656
+ # Returns syllable information for a word
657
+ #
658
+ def get_hyphenation(word, *args)
659
+ http_method = :get
660
+ path = '/word/{word}/hyphenation'
661
+ path.sub!('{word}', word.to_s)
662
+
663
+ # Ruby turns all key-value arguments at the end into a single hash
664
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
665
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
666
+ last_arg = args.pop if args.last.is_a?(Hash)
667
+ last_arg = args.pop if args.last.is_a?(Array)
668
+ last_arg ||= {}
669
+
670
+ # Look for a kwarg called :request_only, whose presence indicates
671
+ # that we want the request itself back, not the response body
672
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
673
+ request_only = true
674
+ last_arg.delete(:request_only)
675
+ end
676
+
677
+ params = last_arg
678
+ body ||= {}
679
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
680
+ request_only ? request : request.response.body
681
+ end
682
+
683
+ # Returns syllable information for a word
684
+ #
685
+ def get_unigram_count_internal(word, *args)
686
+ http_method = :get
687
+ path = '/word/{word}/unigramCountInternal'
688
+ path.sub!('{word}', word.to_s)
689
+
690
+ # Ruby turns all key-value arguments at the end into a single hash
691
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
692
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
693
+ last_arg = args.pop if args.last.is_a?(Hash)
694
+ last_arg = args.pop if args.last.is_a?(Array)
695
+ last_arg ||= {}
696
+
697
+ # Look for a kwarg called :request_only, whose presence indicates
698
+ # that we want the request itself back, not the response body
699
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
700
+ request_only = true
701
+ last_arg.delete(:request_only)
702
+ end
703
+
704
+ params = last_arg
705
+ body ||= {}
706
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
707
+ request_only ? request : request.response.body
708
+ end
709
+
710
+ # Returns Bigrams for the given word
711
+ #
712
+ def get_bigrams_internal(word, *args)
713
+ http_method = :get
714
+ path = '/word/{word}/phrasesInternal'
715
+ path.sub!('{word}', word.to_s)
716
+
717
+ # Ruby turns all key-value arguments at the end into a single hash
718
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
719
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
720
+ last_arg = args.pop if args.last.is_a?(Hash)
721
+ last_arg = args.pop if args.last.is_a?(Array)
722
+ last_arg ||= {}
723
+
724
+ # Look for a kwarg called :request_only, whose presence indicates
725
+ # that we want the request itself back, not the response body
726
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
727
+ request_only = true
728
+ last_arg.delete(:request_only)
729
+ end
730
+
731
+ params = last_arg
732
+ body ||= {}
733
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
734
+ request_only ? request : request.response.body
735
+ end
736
+
737
+ # Returns the number of times a word has been viewed
738
+ #
739
+ def get_lookup_count(word, *args)
740
+ http_method = :get
741
+ path = '/word/{word}/lookupCount'
742
+ path.sub!('{word}', word.to_s)
12
743
 
13
744
  # Ruby turns all key-value arguments at the end into a single hash
14
745
  # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
@@ -24,24 +755,18 @@ module WordMethods
24
755
  last_arg.delete(:request_only)
25
756
  end
26
757
 
27
- if [:post, :put].include?(http_method)
28
- params = nil
29
- body = last_arg
30
- else
31
- params = last_arg
32
- body = nil
33
- end
34
-
758
+ params = last_arg
759
+ body ||= {}
35
760
  request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
36
761
  request_only ? request : request.response.body
37
762
  end
38
763
 
39
- # Returns examples for a word
764
+ # Fetches tags for a word
40
765
  #
41
- def get_examples(word, *args)
766
+ def get_tags_on_word(word, *args)
42
767
  http_method = :get
43
- path = '/word/{word}/examples'
44
- path.sub!('{word}', word)
768
+ path = '/word/{word}/tags'
769
+ path.sub!('{word}', word.to_s)
45
770
 
46
771
  # Ruby turns all key-value arguments at the end into a single hash
47
772
  # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
@@ -57,24 +782,45 @@ module WordMethods
57
782
  last_arg.delete(:request_only)
58
783
  end
59
784
 
60
- if [:post, :put].include?(http_method)
61
- params = nil
62
- body = last_arg
63
- else
64
- params = last_arg
65
- body = nil
785
+ params = last_arg
786
+ body ||= {}
787
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
788
+ request_only ? request : request.response.body
789
+ end
790
+
791
+ # Fetches tag count for a word
792
+ #
793
+ def get_tag_count_on_word(word, *args)
794
+ http_method = :get
795
+ path = '/word/{word}/tagCount'
796
+ path.sub!('{word}', word.to_s)
797
+
798
+ # Ruby turns all key-value arguments at the end into a single hash
799
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
800
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
801
+ last_arg = args.pop if args.last.is_a?(Hash)
802
+ last_arg = args.pop if args.last.is_a?(Array)
803
+ last_arg ||= {}
804
+
805
+ # Look for a kwarg called :request_only, whose presence indicates
806
+ # that we want the request itself back, not the response body
807
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
808
+ request_only = true
809
+ last_arg.delete(:request_only)
66
810
  end
67
811
 
812
+ params = last_arg
813
+ body ||= {}
68
814
  request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
69
815
  request_only ? request : request.response.body
70
816
  end
71
817
 
72
- # Return definitions for a word
818
+ # Adds a tag to a word
73
819
  #
74
- def get_definitions(word, *args)
75
- http_method = :get
76
- path = '/word/{word}/definitions'
77
- path.sub!('{word}', word)
820
+ def add_tag_to_word(word, *args)
821
+ http_method = :post
822
+ path = '/word/{word}/tag'
823
+ path.sub!('{word}', word.to_s)
78
824
 
79
825
  # Ruby turns all key-value arguments at the end into a single hash
80
826
  # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
@@ -90,14 +836,35 @@ module WordMethods
90
836
  last_arg.delete(:request_only)
91
837
  end
92
838
 
93
- if [:post, :put].include?(http_method)
94
- params = nil
95
- body = last_arg
96
- else
97
- params = last_arg
98
- body = nil
839
+ params = last_arg
840
+ body ||= {}
841
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
842
+ request_only ? request : request.response.body
843
+ end
844
+
845
+ # Removes a tag from a word
846
+ #
847
+ def delete_tag_from_word(word, *args)
848
+ http_method = :delete
849
+ path = '/word/{word}/tag'
850
+ path.sub!('{word}', word.to_s)
851
+
852
+ # Ruby turns all key-value arguments at the end into a single hash
853
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
854
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
855
+ last_arg = args.pop if args.last.is_a?(Hash)
856
+ last_arg = args.pop if args.last.is_a?(Array)
857
+ last_arg ||= {}
858
+
859
+ # Look for a kwarg called :request_only, whose presence indicates
860
+ # that we want the request itself back, not the response body
861
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
862
+ request_only = true
863
+ last_arg.delete(:request_only)
99
864
  end
100
865
 
866
+ params = last_arg
867
+ body ||= {}
101
868
  request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
102
869
  request_only ? request : request.response.body
103
870
  end
@@ -107,7 +874,34 @@ module WordMethods
107
874
  def get_word_frequency(word, *args)
108
875
  http_method = :get
109
876
  path = '/word/{word}/frequency'
110
- path.sub!('{word}', word)
877
+ path.sub!('{word}', word.to_s)
878
+
879
+ # Ruby turns all key-value arguments at the end into a single hash
880
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
881
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
882
+ last_arg = args.pop if args.last.is_a?(Hash)
883
+ last_arg = args.pop if args.last.is_a?(Array)
884
+ last_arg ||= {}
885
+
886
+ # Look for a kwarg called :request_only, whose presence indicates
887
+ # that we want the request itself back, not the response body
888
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
889
+ request_only = true
890
+ last_arg.delete(:request_only)
891
+ end
892
+
893
+ params = last_arg
894
+ body ||= {}
895
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
896
+ request_only ? request : request.response.body
897
+ end
898
+
899
+ # Returns first usage of a word
900
+ #
901
+ def get_first_usage_of_word(word, *args)
902
+ http_method = :get
903
+ path = '/word/{word}/firstUsed'
904
+ path.sub!('{word}', word.to_s)
111
905
 
112
906
  # Ruby turns all key-value arguments at the end into a single hash
113
907
  # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
@@ -123,24 +917,45 @@ module WordMethods
123
917
  last_arg.delete(:request_only)
124
918
  end
125
919
 
126
- if [:post, :put].include?(http_method)
127
- params = nil
128
- body = last_arg
129
- else
130
- params = last_arg
131
- body = nil
920
+ params = last_arg
921
+ body ||= {}
922
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
923
+ request_only ? request : request.response.body
924
+ end
925
+
926
+ # Records a word view from the website
927
+ #
928
+ def add_word_view(word, *args)
929
+ http_method = :post
930
+ path = '/word/{word}/wordView'
931
+ path.sub!('{word}', word.to_s)
932
+
933
+ # Ruby turns all key-value arguments at the end into a single hash
934
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
935
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
936
+ last_arg = args.pop if args.last.is_a?(Hash)
937
+ last_arg = args.pop if args.last.is_a?(Array)
938
+ last_arg ||= {}
939
+
940
+ # Look for a kwarg called :request_only, whose presence indicates
941
+ # that we want the request itself back, not the response body
942
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
943
+ request_only = true
944
+ last_arg.delete(:request_only)
132
945
  end
133
946
 
947
+ params = last_arg
948
+ body ||= {}
134
949
  request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
135
950
  request_only ? request : request.response.body
136
951
  end
137
952
 
138
- # Returns a top example for a word
953
+ # Checks to see if a word is a user's favorite
139
954
  #
140
- def get_top_example(word, *args)
955
+ def is_favorite(word, *args)
141
956
  http_method = :get
142
- path = '/word/{word}/topExample'
143
- path.sub!('{word}', word)
957
+ path = '/word/{word}/isFavorite'
958
+ path.sub!('{word}', word.to_s)
144
959
 
145
960
  # Ruby turns all key-value arguments at the end into a single hash
146
961
  # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
@@ -156,24 +971,45 @@ module WordMethods
156
971
  last_arg.delete(:request_only)
157
972
  end
158
973
 
159
- if [:post, :put].include?(http_method)
160
- params = nil
161
- body = last_arg
162
- else
163
- params = last_arg
164
- body = nil
974
+ params = last_arg
975
+ body ||= {}
976
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
977
+ request_only ? request : request.response.body
978
+ end
979
+
980
+ # Returns the number of times a word has been Favorited
981
+ #
982
+ def get_favorite_count(word, *args)
983
+ http_method = :get
984
+ path = '/word/{word}/favoriteCount'
985
+ path.sub!('{word}', word.to_s)
986
+
987
+ # Ruby turns all key-value arguments at the end into a single hash
988
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
989
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
990
+ last_arg = args.pop if args.last.is_a?(Hash)
991
+ last_arg = args.pop if args.last.is_a?(Array)
992
+ last_arg ||= {}
993
+
994
+ # Look for a kwarg called :request_only, whose presence indicates
995
+ # that we want the request itself back, not the response body
996
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
997
+ request_only = true
998
+ last_arg.delete(:request_only)
165
999
  end
166
1000
 
1001
+ params = last_arg
1002
+ body ||= {}
167
1003
  request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
168
1004
  request_only ? request : request.response.body
169
1005
  end
170
1006
 
171
- # Return related words (thesaurus data) for a word
1007
+ # Favorites a Word for a user
172
1008
  #
173
- def get_related_words(word, *args)
174
- http_method = :get
175
- path = '/word/{word}/related'
176
- path.sub!('{word}', word)
1009
+ def add_word_to_favorites(word, *args)
1010
+ http_method = :post
1011
+ path = '/word/{word}/favorite'
1012
+ path.sub!('{word}', word.to_s)
177
1013
 
178
1014
  # Ruby turns all key-value arguments at the end into a single hash
179
1015
  # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
@@ -189,14 +1025,35 @@ module WordMethods
189
1025
  last_arg.delete(:request_only)
190
1026
  end
191
1027
 
192
- if [:post, :put].include?(http_method)
193
- params = nil
194
- body = last_arg
195
- else
196
- params = last_arg
197
- body = nil
1028
+ params = last_arg
1029
+ body ||= {}
1030
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
1031
+ request_only ? request : request.response.body
1032
+ end
1033
+
1034
+ # Removes a Word from a user's Favorites
1035
+ #
1036
+ def delete_from_favorites(word, *args)
1037
+ http_method = :delete
1038
+ path = '/word/{word}/favorite'
1039
+ path.sub!('{word}', word.to_s)
1040
+
1041
+ # Ruby turns all key-value arguments at the end into a single hash
1042
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
1043
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
1044
+ last_arg = args.pop if args.last.is_a?(Hash)
1045
+ last_arg = args.pop if args.last.is_a?(Array)
1046
+ last_arg ||= {}
1047
+
1048
+ # Look for a kwarg called :request_only, whose presence indicates
1049
+ # that we want the request itself back, not the response body
1050
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
1051
+ request_only = true
1052
+ last_arg.delete(:request_only)
198
1053
  end
199
1054
 
1055
+ params = last_arg
1056
+ body ||= {}
200
1057
  request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
201
1058
  request_only ? request : request.response.body
202
1059
  end
@@ -206,7 +1063,7 @@ module WordMethods
206
1063
  def get_phrases(word, *args)
207
1064
  http_method = :get
208
1065
  path = '/word/{word}/phrases'
209
- path.sub!('{word}', word)
1066
+ path.sub!('{word}', word.to_s)
210
1067
 
211
1068
  # Ruby turns all key-value arguments at the end into a single hash
212
1069
  # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
@@ -222,24 +1079,46 @@ module WordMethods
222
1079
  last_arg.delete(:request_only)
223
1080
  end
224
1081
 
225
- if [:post, :put].include?(http_method)
226
- params = nil
227
- body = last_arg
228
- else
229
- params = last_arg
230
- body = nil
1082
+ params = last_arg
1083
+ body ||= {}
1084
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
1085
+ request_only ? request : request.response.body
1086
+ end
1087
+
1088
+ # Fetches etymology data
1089
+ #
1090
+ def get_etymologies(word, *args)
1091
+ http_method = :get
1092
+ path = '/word/{word}/etymologies'
1093
+ path.sub!('{word}', word.to_s)
1094
+
1095
+ # Ruby turns all key-value arguments at the end into a single hash
1096
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
1097
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
1098
+ last_arg = args.pop if args.last.is_a?(Hash)
1099
+ last_arg = args.pop if args.last.is_a?(Array)
1100
+ last_arg ||= {}
1101
+
1102
+ # Look for a kwarg called :request_only, whose presence indicates
1103
+ # that we want the request itself back, not the response body
1104
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
1105
+ request_only = true
1106
+ last_arg.delete(:request_only)
231
1107
  end
232
1108
 
1109
+ params = last_arg
1110
+ body ||= {}
233
1111
  request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
234
1112
  request_only ? request : request.response.body
235
1113
  end
236
1114
 
237
- # Returns syllable information for a word
1115
+ # Fetches other forms of a word
1116
+ # Deprecated
238
1117
  #
239
- def get_hyphenation(word, *args)
1118
+ def get_other_forms_internal(word, *args)
240
1119
  http_method = :get
241
- path = '/word/{word}/hyphenation'
242
- path.sub!('{word}', word)
1120
+ path = '/word/{word}/otherFormsInternal'
1121
+ path.sub!('{word}', word.to_s)
243
1122
 
244
1123
  # Ruby turns all key-value arguments at the end into a single hash
245
1124
  # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
@@ -255,24 +1134,46 @@ module WordMethods
255
1134
  last_arg.delete(:request_only)
256
1135
  end
257
1136
 
258
- if [:post, :put].include?(http_method)
259
- params = nil
260
- body = last_arg
261
- else
262
- params = last_arg
263
- body = nil
1137
+ params = last_arg
1138
+ body ||= {}
1139
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
1140
+ request_only ? request : request.response.body
1141
+ end
1142
+
1143
+ # Adds a word relationship
1144
+ # Deprecated
1145
+ #
1146
+ def add_word_relationship_internal(word, body, *args)
1147
+ http_method = :post
1148
+ path = '/word/{word}/wordRelationshipInternal'
1149
+ path.sub!('{word}', word.to_s)
1150
+
1151
+ # Ruby turns all key-value arguments at the end into a single hash
1152
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
1153
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
1154
+ last_arg = args.pop if args.last.is_a?(Hash)
1155
+ last_arg = args.pop if args.last.is_a?(Array)
1156
+ last_arg ||= {}
1157
+
1158
+ # Look for a kwarg called :request_only, whose presence indicates
1159
+ # that we want the request itself back, not the response body
1160
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
1161
+ request_only = true
1162
+ last_arg.delete(:request_only)
264
1163
  end
265
1164
 
1165
+ params = last_arg
1166
+ body ||= {}
266
1167
  request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
267
1168
  request_only ? request : request.response.body
268
1169
  end
269
1170
 
270
- # Returns text pronunciations for a given word
1171
+ # Fetches comments on a Word
271
1172
  #
272
- def get_text_pronunciations(word, *args)
1173
+ def get_comments_on_word(word, *args)
273
1174
  http_method = :get
274
- path = '/word/{word}/pronunciations'
275
- path.sub!('{word}', word)
1175
+ path = '/word/{word}/comments'
1176
+ path.sub!('{word}', word.to_s)
276
1177
 
277
1178
  # Ruby turns all key-value arguments at the end into a single hash
278
1179
  # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
@@ -288,24 +1189,19 @@ module WordMethods
288
1189
  last_arg.delete(:request_only)
289
1190
  end
290
1191
 
291
- if [:post, :put].include?(http_method)
292
- params = nil
293
- body = last_arg
294
- else
295
- params = last_arg
296
- body = nil
297
- end
298
-
1192
+ params = last_arg
1193
+ body ||= {}
299
1194
  request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
300
1195
  request_only ? request : request.response.body
301
1196
  end
302
1197
 
303
- # Returns other forms of a word
1198
+ # Fetches a Comment by ID
304
1199
  #
305
- def get_word_forms(word, *args)
1200
+ def delete_comment_on_word(word, commentId, *args)
306
1201
  http_method = :get
307
- path = '/word/{word}/wordForms'
308
- path.sub!('{word}', word)
1202
+ path = '/word/{word}/comment/{commentId}'
1203
+ path.sub!('{word}', word.to_s)
1204
+ path.sub!('{commentId}', commentId.to_s)
309
1205
 
310
1206
  # Ruby turns all key-value arguments at the end into a single hash
311
1207
  # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
@@ -321,25 +1217,46 @@ module WordMethods
321
1217
  last_arg.delete(:request_only)
322
1218
  end
323
1219
 
324
- if [:post, :put].include?(http_method)
325
- params = nil
326
- body = last_arg
327
- else
328
- params = last_arg
329
- body = nil
1220
+ params = last_arg
1221
+ body ||= {}
1222
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
1223
+ request_only ? request : request.response.body
1224
+ end
1225
+
1226
+ # Deletes an existing word comment
1227
+ #
1228
+ def delete_comment_by_id_on_word(word, commentId, *args)
1229
+ http_method = :delete
1230
+ path = '/word/{word}/comment/{commentId}'
1231
+ path.sub!('{word}', word.to_s)
1232
+ path.sub!('{commentId}', commentId.to_s)
1233
+
1234
+ # Ruby turns all key-value arguments at the end into a single hash
1235
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
1236
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
1237
+ last_arg = args.pop if args.last.is_a?(Hash)
1238
+ last_arg = args.pop if args.last.is_a?(Array)
1239
+ last_arg ||= {}
1240
+
1241
+ # Look for a kwarg called :request_only, whose presence indicates
1242
+ # that we want the request itself back, not the response body
1243
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
1244
+ request_only = true
1245
+ last_arg.delete(:request_only)
330
1246
  end
331
1247
 
1248
+ params = last_arg
1249
+ body ||= {}
332
1250
  request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
333
1251
  request_only ? request : request.response.body
334
1252
  end
335
1253
 
336
- # Fetches audio metadata for a word.
337
- # 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.
1254
+ # Adds a comment to a word
338
1255
  #
339
- def get_audio(word, *args)
340
- http_method = :get
341
- path = '/word/{word}/audio'
342
- path.sub!('{word}', word)
1256
+ def comment_on_word(word, body, *args)
1257
+ http_method = :post
1258
+ path = '/word/{word}/comment'
1259
+ path.sub!('{word}', word.to_s)
343
1260
 
344
1261
  # Ruby turns all key-value arguments at the end into a single hash
345
1262
  # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
@@ -355,25 +1272,46 @@ module WordMethods
355
1272
  last_arg.delete(:request_only)
356
1273
  end
357
1274
 
358
- if [:post, :put].include?(http_method)
359
- params = nil
360
- body = last_arg
361
- else
362
- params = last_arg
363
- body = nil
1275
+ params = last_arg
1276
+ body ||= {}
1277
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
1278
+ request_only ? request : request.response.body
1279
+ end
1280
+
1281
+ # Updates an existing word comment
1282
+ #
1283
+ def update_comment_on_word(word, body, *args)
1284
+ http_method = :put
1285
+ path = '/word/{word}/comment'
1286
+ path.sub!('{word}', word.to_s)
1287
+
1288
+ # Ruby turns all key-value arguments at the end into a single hash
1289
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
1290
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
1291
+ last_arg = args.pop if args.last.is_a?(Hash)
1292
+ last_arg = args.pop if args.last.is_a?(Array)
1293
+ last_arg ||= {}
1294
+
1295
+ # Look for a kwarg called :request_only, whose presence indicates
1296
+ # that we want the request itself back, not the response body
1297
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
1298
+ request_only = true
1299
+ last_arg.delete(:request_only)
364
1300
  end
365
1301
 
1302
+ params = last_arg
1303
+ body ||= {}
366
1304
  request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
367
1305
  request_only ? request : request.response.body
368
1306
  end
369
1307
 
370
- # Returns definitions for a word based on the sentence in which it is found
371
- # Use the offset parameter when the word occurs more than once in the sentence
1308
+ # Fetches audio metadata for a word.
1309
+ # 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.
372
1310
  #
373
- def contextual_lookup(word, *args)
1311
+ def get_audio(word, *args)
374
1312
  http_method = :get
375
- path = '/word/{word}/contextualLookup'
376
- path.sub!('{word}', word)
1313
+ path = '/word/{word}/audio'
1314
+ path.sub!('{word}', word.to_s)
377
1315
 
378
1316
  # Ruby turns all key-value arguments at the end into a single hash
379
1317
  # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
@@ -389,25 +1327,18 @@ module WordMethods
389
1327
  last_arg.delete(:request_only)
390
1328
  end
391
1329
 
392
- if [:post, :put].include?(http_method)
393
- params = nil
394
- body = last_arg
395
- else
396
- params = last_arg
397
- body = nil
398
- end
399
-
1330
+ params = last_arg
1331
+ body ||= {}
400
1332
  request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
401
1333
  request_only ? request : request.response.body
402
1334
  end
403
1335
 
404
- # Returns definitions for a word based on the sentence in which it is found
405
- # Use the offset parameter when the word occurs more than once in the sentence
1336
+ # Creates AudioPron metadata
406
1337
  #
407
- def contextual_lookup_post(word, *args)
1338
+ def add_audio(word, body, *args)
408
1339
  http_method = :post
409
- path = '/word/{word}/contextualLookup'
410
- path.sub!('{word}', word)
1340
+ path = '/word/{word}/audio'
1341
+ path.sub!('{word}', word.to_s)
411
1342
 
412
1343
  # Ruby turns all key-value arguments at the end into a single hash
413
1344
  # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
@@ -423,14 +1354,36 @@ module WordMethods
423
1354
  last_arg.delete(:request_only)
424
1355
  end
425
1356
 
426
- if [:post, :put].include?(http_method)
427
- params = nil
428
- body = last_arg
429
- else
430
- params = last_arg
431
- body = nil
1357
+ params = last_arg
1358
+ body ||= {}
1359
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
1360
+ request_only ? request : request.response.body
1361
+ end
1362
+
1363
+ # Deletes an AudioPron
1364
+ #
1365
+ def delete_audio(word, audio_id, *args)
1366
+ http_method = :delete
1367
+ path = '/word/{word}/audio/{audio_id}'
1368
+ path.sub!('{word}', word.to_s)
1369
+ path.sub!('{audio_id}', audio_id.to_s)
1370
+
1371
+ # Ruby turns all key-value arguments at the end into a single hash
1372
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
1373
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
1374
+ last_arg = args.pop if args.last.is_a?(Hash)
1375
+ last_arg = args.pop if args.last.is_a?(Array)
1376
+ last_arg ||= {}
1377
+
1378
+ # Look for a kwarg called :request_only, whose presence indicates
1379
+ # that we want the request itself back, not the response body
1380
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
1381
+ request_only = true
1382
+ last_arg.delete(:request_only)
432
1383
  end
433
1384
 
1385
+ params = last_arg
1386
+ body ||= {}
434
1387
  request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
435
1388
  request_only ? request : request.response.body
436
1389
  end