wordnik 4.06.05 → 4.06.06

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/.rspec +1 -0
  2. data/Gemfile.lock +22 -16
  3. data/Rakefile +29 -166
  4. data/api_docs/account.json +1 -1
  5. data/api_docs/analytics.json +1 -0
  6. data/api_docs/corpus.json +1 -1
  7. data/api_docs/document.json +1 -1
  8. data/api_docs/partner.json +1 -0
  9. data/api_docs/partners.json +1 -1
  10. data/api_docs/suggest.json +1 -0
  11. data/api_docs/system.json +1 -0
  12. data/api_docs/tag.json +1 -1
  13. data/api_docs/user.json +1 -1
  14. data/api_docs/users.json +1 -1
  15. data/api_docs/word.json +1 -1
  16. data/api_docs/wordList.json +1 -1
  17. data/api_docs/wordLists.json +1 -1
  18. data/api_docs/words.json +1 -1
  19. data/lib/wordnik.rb +58 -17
  20. data/lib/wordnik/configuration.rb +21 -6
  21. data/lib/wordnik/operation.rb +3 -2
  22. data/lib/wordnik/operation_parameter.rb +4 -6
  23. data/lib/wordnik/request.rb +53 -53
  24. data/lib/wordnik/resource.rb +68 -3
  25. data/lib/wordnik/resource_modules/account.rb +0 -26
  26. data/lib/wordnik/resource_modules/analytics.rb +89 -0
  27. data/lib/wordnik/resource_modules/corpus.rb +26 -26
  28. data/lib/wordnik/resource_modules/document.rb +0 -26
  29. data/lib/wordnik/resource_modules/partner.rb +140 -0
  30. data/lib/wordnik/resource_modules/partners.rb +0 -26
  31. data/lib/wordnik/resource_modules/suggest.rb +33 -0
  32. data/lib/wordnik/resource_modules/system.rb +192 -0
  33. data/lib/wordnik/resource_modules/tag.rb +0 -26
  34. data/lib/wordnik/resource_modules/user.rb +0 -26
  35. data/lib/wordnik/resource_modules/users.rb +12 -38
  36. data/lib/wordnik/resource_modules/word.rb +23 -49
  37. data/lib/wordnik/resource_modules/word_list.rb +0 -26
  38. data/lib/wordnik/resource_modules/word_lists.rb +0 -26
  39. data/lib/wordnik/resource_modules/words.rb +0 -26
  40. data/lib/wordnik/response.rb +3 -5
  41. data/lib/wordnik/version.rb +1 -1
  42. data/spec/endpoint_spec.rb +2 -5
  43. data/spec/operation_parameter_spec.rb +32 -11
  44. data/spec/operation_spec.rb +2 -5
  45. data/spec/request_spec.rb +9 -30
  46. data/spec/resource_spec.rb +7 -7
  47. data/spec/response_spec.rb +13 -19
  48. data/spec/spec_helper.rb +14 -2
  49. data/spec/vcr/crazier_json_request.yml +31 -0
  50. data/spec/vcr/default_response.yml +25 -0
  51. data/spec/vcr/get_word_dynamo.yml +33 -0
  52. data/spec/vcr/unauthorized_response.yml +25 -0
  53. data/spec/vcr/wordnik_authenticate.yml +31 -0
  54. data/spec/vcr/wordnik_authenticate_fail.yml +172 -0
  55. data/spec/vcr/xml_response_request.yml +25 -0
  56. data/spec/wordnik_spec.rb +68 -17
  57. data/wordnik.gemspec +2 -0
  58. metadata +48 -5
@@ -3,32 +3,6 @@
3
3
 
4
4
  module TagMethods
5
5
 
6
- # Returns information about API parameters
7
- #
8
- def get_help(*args)
9
- http_method = :get
10
- path = '/tag'
11
-
12
- # Ruby turns all key-value arguments at the end into a single hash
13
- # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
14
- # becomes {:limit => 10, :part_of_speech => 'verb'}
15
- last_arg = args.pop if args.last.is_a?(Hash)
16
- last_arg = args.pop if args.last.is_a?(Array)
17
- last_arg ||= {}
18
-
19
- # Look for a kwarg called :request_only, whose presence indicates
20
- # that we want the request itself back, not the response body
21
- if last_arg.is_a?(Hash) && last_arg[:request_only].present?
22
- request_only = true
23
- last_arg.delete(:request_only)
24
- end
25
-
26
- params = last_arg
27
- body ||= {}
28
- request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
29
- request_only ? request : request.response.body
30
- end
31
-
32
6
  # Fetches Words with a specific Tag.
33
7
  #
34
8
  def get_words_tagged(tag, *args)
@@ -1178,30 +1178,4 @@ module UserMethods
1178
1178
  request_only ? request : request.response.body
1179
1179
  end
1180
1180
 
1181
- # Returns information about API parameters
1182
- #
1183
- def get_help(*args)
1184
- http_method = :get
1185
- path = '/user'
1186
-
1187
- # Ruby turns all key-value arguments at the end into a single hash
1188
- # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
1189
- # becomes {:limit => 10, :part_of_speech => 'verb'}
1190
- last_arg = args.pop if args.last.is_a?(Hash)
1191
- last_arg = args.pop if args.last.is_a?(Array)
1192
- last_arg ||= {}
1193
-
1194
- # Look for a kwarg called :request_only, whose presence indicates
1195
- # that we want the request itself back, not the response body
1196
- if last_arg.is_a?(Hash) && last_arg[:request_only].present?
1197
- request_only = true
1198
- last_arg.delete(:request_only)
1199
- end
1200
-
1201
- params = last_arg
1202
- body ||= {}
1203
- request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
1204
- request_only ? request : request.response.body
1205
- end
1206
-
1207
1181
  end
@@ -29,37 +29,12 @@ module UsersMethods
29
29
  request_only ? request : request.response.body
30
30
  end
31
31
 
32
- # Returns information about API parameters
32
+ # Fetches a User by ID
33
33
  #
34
- def get_help(*args)
34
+ def get_user_by_id(id, *args)
35
35
  http_method = :get
36
- path = '/users'
37
-
38
- # Ruby turns all key-value arguments at the end into a single hash
39
- # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
40
- # becomes {:limit => 10, :part_of_speech => 'verb'}
41
- last_arg = args.pop if args.last.is_a?(Hash)
42
- last_arg = args.pop if args.last.is_a?(Array)
43
- last_arg ||= {}
44
-
45
- # Look for a kwarg called :request_only, whose presence indicates
46
- # that we want the request itself back, not the response body
47
- if last_arg.is_a?(Hash) && last_arg[:request_only].present?
48
- request_only = true
49
- last_arg.delete(:request_only)
50
- end
51
-
52
- params = last_arg
53
- body ||= {}
54
- request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
55
- request_only ? request : request.response.body
56
- end
57
-
58
- # Creates a User
59
- #
60
- def create_user(body, *args)
61
- http_method = :post
62
- path = '/users'
36
+ path = '/users/id/{id}'
37
+ path.sub!('{id}', id.to_s)
63
38
 
64
39
  # Ruby turns all key-value arguments at the end into a single hash
65
40
  # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
@@ -81,12 +56,12 @@ module UsersMethods
81
56
  request_only ? request : request.response.body
82
57
  end
83
58
 
84
- # Fetches a User by ID
59
+ # Fetches a User by Facebook ID
85
60
  #
86
- def get_user_by_id(id, *args)
61
+ def get_by_facebook_id(facebookId, *args)
87
62
  http_method = :get
88
- path = '/users/id/{id}'
89
- path.sub!('{id}', id.to_s)
63
+ path = '/users/facebook/{facebookId}'
64
+ path.sub!('{facebookId}', facebookId.to_s)
90
65
 
91
66
  # Ruby turns all key-value arguments at the end into a single hash
92
67
  # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
@@ -108,12 +83,11 @@ module UsersMethods
108
83
  request_only ? request : request.response.body
109
84
  end
110
85
 
111
- # Fetches a User by Facebook ID
86
+ # Creates a User
112
87
  #
113
- def get_by_facebook_id(facebookId, *args)
114
- http_method = :get
115
- path = '/users/facebook/{facebookId}'
116
- path.sub!('{facebookId}', facebookId.to_s)
88
+ def create_user(body, *args)
89
+ http_method = :post
90
+ path = '/users'
117
91
 
118
92
  # Ruby turns all key-value arguments at the end into a single hash
119
93
  # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
@@ -246,11 +246,12 @@ module WordMethods
246
246
  request_only ? request : request.response.body
247
247
  end
248
248
 
249
- # Returns information about API parameters
249
+ # Returns a top example for a word
250
250
  #
251
- def get_help(*args)
251
+ def get_top_example(word, *args)
252
252
  http_method = :get
253
- path = '/word'
253
+ path = '/word/{word}/topExample'
254
+ path.sub!('{word}', word.to_s)
254
255
 
255
256
  # Ruby turns all key-value arguments at the end into a single hash
256
257
  # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
@@ -272,11 +273,12 @@ module WordMethods
272
273
  request_only ? request : request.response.body
273
274
  end
274
275
 
275
- # Returns a top example for a word
276
+ # Fetches other forms of a word
277
+ # Deprecated
276
278
  #
277
- def get_top_example(word, *args)
279
+ def get_punctuation_factor(word, *args)
278
280
  http_method = :get
279
- path = '/word/{word}/topExample'
281
+ path = '/word/{word}/punctuationFactor'
280
282
  path.sub!('{word}', word.to_s)
281
283
 
282
284
  # Ruby turns all key-value arguments at the end into a single hash
@@ -299,12 +301,12 @@ module WordMethods
299
301
  request_only ? request : request.response.body
300
302
  end
301
303
 
302
- # Fetches other forms of a word
303
- # Deprecated
304
+ # Returns definitions for a word based on the sentence in which it is found
305
+ # Use the offset parameter when the word occurs more than once in the sentence
304
306
  #
305
- def get_punctuation_factor(word, *args)
307
+ def contextual_lookup(word, *args)
306
308
  http_method = :get
307
- path = '/word/{word}/punctuationFactor'
309
+ path = '/word/{word}/contextualLookup'
308
310
  path.sub!('{word}', word.to_s)
309
311
 
310
312
  # Ruby turns all key-value arguments at the end into a single hash
@@ -330,8 +332,8 @@ module WordMethods
330
332
  # Returns definitions for a word based on the sentence in which it is found
331
333
  # Use the offset parameter when the word occurs more than once in the sentence
332
334
  #
333
- def contextual_lookup(word, *args)
334
- http_method = :get
335
+ def contextual_lookup_post(word, body, *args)
336
+ http_method = :post
335
337
  path = '/word/{word}/contextualLookup'
336
338
  path.sub!('{word}', word.to_s)
337
339
 
@@ -355,12 +357,11 @@ module WordMethods
355
357
  request_only ? request : request.response.body
356
358
  end
357
359
 
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
+ # Returns the number of comments on a word
360
361
  #
361
- def contextual_lookup_post(word, body, *args)
362
- http_method = :post
363
- path = '/word/{word}/contextualLookup'
362
+ def get_comment_count(word, *args)
363
+ http_method = :get
364
+ path = '/word/{word}/commentCount'
364
365
  path.sub!('{word}', word.to_s)
365
366
 
366
367
  # Ruby turns all key-value arguments at the end into a single hash
@@ -383,11 +384,11 @@ module WordMethods
383
384
  request_only ? request : request.response.body
384
385
  end
385
386
 
386
- # Returns the number of comments on a word
387
+ # Returns citations for a word
387
388
  #
388
- def get_comment_count(word, *args)
389
+ def get_citations(word, *args)
389
390
  http_method = :get
390
- path = '/word/{word}/commentCount'
391
+ path = '/word/{word}/citations'
391
392
  path.sub!('{word}', word.to_s)
392
393
 
393
394
  # Ruby turns all key-value arguments at the end into a single hash
@@ -626,33 +627,6 @@ module WordMethods
626
627
  request_only ? request : request.response.body
627
628
  end
628
629
 
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
630
  # Returns syllable information for a word
657
631
  #
658
632
  def get_hyphenation(word, *args)
@@ -1197,7 +1171,7 @@ module WordMethods
1197
1171
 
1198
1172
  # Fetches a Comment by ID
1199
1173
  #
1200
- def delete_comment_on_word(word, commentId, *args)
1174
+ def get_comment_on_word(word, commentId, *args)
1201
1175
  http_method = :get
1202
1176
  path = '/word/{word}/comment/{commentId}'
1203
1177
  path.sub!('{word}', word.to_s)
@@ -1361,7 +1335,7 @@ module WordMethods
1361
1335
  end
1362
1336
 
1363
1337
  # Fetches single audio pronunciation.
1364
- # 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.
1338
+ # 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.
1365
1339
  #
1366
1340
  def get_pronunciation(word, pronId, *args)
1367
1341
  http_method = :get
@@ -138,32 +138,6 @@ module WordListMethods
138
138
  request_only ? request : request.response.body
139
139
  end
140
140
 
141
- # Returns information about API parameters
142
- #
143
- def get_help(*args)
144
- http_method = :get
145
- path = '/wordList'
146
-
147
- # Ruby turns all key-value arguments at the end into a single hash
148
- # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
149
- # becomes {:limit => 10, :part_of_speech => 'verb'}
150
- last_arg = args.pop if args.last.is_a?(Hash)
151
- last_arg = args.pop if args.last.is_a?(Array)
152
- last_arg ||= {}
153
-
154
- # Look for a kwarg called :request_only, whose presence indicates
155
- # that we want the request itself back, not the response body
156
- if last_arg.is_a?(Hash) && last_arg[:request_only].present?
157
- request_only = true
158
- last_arg.delete(:request_only)
159
- end
160
-
161
- params = last_arg
162
- body ||= {}
163
- request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
164
- request_only ? request : request.response.body
165
- end
166
-
167
141
  # Checks to see if a WordList has been favorited for a user
168
142
  #
169
143
  def is_favorite_word_list(wordListId, *args)
@@ -57,32 +57,6 @@ module WordListsMethods
57
57
  request_only ? request : request.response.body
58
58
  end
59
59
 
60
- # Returns information about API parameters
61
- #
62
- def get_help(*args)
63
- http_method = :get
64
- path = '/wordLists'
65
-
66
- # Ruby turns all key-value arguments at the end into a single hash
67
- # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
68
- # becomes {:limit => 10, :part_of_speech => 'verb'}
69
- last_arg = args.pop if args.last.is_a?(Hash)
70
- last_arg = args.pop if args.last.is_a?(Array)
71
- last_arg ||= {}
72
-
73
- # Look for a kwarg called :request_only, whose presence indicates
74
- # that we want the request itself back, not the response body
75
- if last_arg.is_a?(Hash) && last_arg[:request_only].present?
76
- request_only = true
77
- last_arg.delete(:request_only)
78
- end
79
-
80
- params = last_arg
81
- body ||= {}
82
- request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
83
- request_only ? request : request.response.body
84
- end
85
-
86
60
  # Fetches a CommentSummary for WordList objects.
87
61
  # The CommentSummary is sorted by comment count, descending
88
62
  #
@@ -82,32 +82,6 @@ module WordsMethods
82
82
  request_only ? request : request.response.body
83
83
  end
84
84
 
85
- # Returns information about API parameters
86
- #
87
- def get_help(*args)
88
- http_method = :get
89
- path = '/words'
90
-
91
- # Ruby turns all key-value arguments at the end into a single hash
92
- # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
93
- # becomes {:limit => 10, :part_of_speech => 'verb'}
94
- last_arg = args.pop if args.last.is_a?(Hash)
95
- last_arg = args.pop if args.last.is_a?(Array)
96
- last_arg ||= {}
97
-
98
- # Look for a kwarg called :request_only, whose presence indicates
99
- # that we want the request itself back, not the response body
100
- if last_arg.is_a?(Hash) && last_arg[:request_only].present?
101
- request_only = true
102
- last_arg.delete(:request_only)
103
- end
104
-
105
- params = last_arg
106
- body ||= {}
107
- request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
108
- request_only ? request : request.response.body
109
- end
110
-
111
85
  # Searches definitions.
112
86
  #
113
87
  def search_definitions(*args)
@@ -36,11 +36,9 @@ module Wordnik
36
36
  # TODO: If body is XML, parse it
37
37
  # Otherwise return raw string
38
38
  def body
39
- begin
40
- JSON.parse raw.body
41
- rescue
42
- raw.body
43
- end
39
+ JSON.parse raw.body
40
+ rescue
41
+ raw.body
44
42
  end
45
43
 
46
44
  def headers
@@ -1,4 +1,4 @@
1
1
  module Wordnik
2
- VERSION = "4.06.05"
2
+ VERSION = "4.06.06"
3
3
  end
4
4
 
@@ -3,17 +3,14 @@ require 'spec_helper'
3
3
  describe Wordnik::Endpoint do
4
4
 
5
5
  before(:each) do
6
- VCR.use_cassette('words', :record => :new_episodes) do
7
- @response = Typhoeus::Request.get("http://beta.wordnik.com/v4/word.json")
8
- end
9
- @resource = Wordnik::Resource.new(:name => "word", :raw_data => JSON.parse(@response.body))
6
+ @resource = Wordnik::Resource.new(:name => "word", :raw_data => JSON.parse(sample_resource_body))
10
7
  @endpoint = @resource.endpoints.first
11
8
  end
12
9
 
13
10
  describe "initialization" do
14
11
 
15
12
  it "successfully initializes" do
16
- @endpoint.path.should == "/word.{format}/{word}"
13
+ @endpoint.path.should =~ /word\.{format}\/{word}/i
17
14
  end
18
15
 
19
16
  it "sets operations" do
@@ -3,11 +3,7 @@ require 'spec_helper'
3
3
  describe Wordnik::OperationParameter do
4
4
 
5
5
  before(:each) do
6
- VCR.use_cassette('words', :record => :new_episodes) do
7
- @response = Typhoeus::Request.get("http://beta.wordnik.com/v4/word.json")
8
- end
9
-
10
- @operation_parameter = Wordnik::OperationParameter.new(JSON.parse(@response.body)['endPoints'].first['operations'].first['parameters'].first)
6
+ @operation_parameter = Wordnik::OperationParameter.new(JSON.parse(sample_resource_body)['apis'].first['operations'].first['parameters'].first)
11
7
  end
12
8
 
13
9
  it "initializes" do
@@ -18,14 +14,39 @@ describe Wordnik::OperationParameter do
18
14
  @operation_parameter.should respond_to(:default_value)
19
15
  @operation_parameter.should respond_to(:allowable_values)
20
16
  @operation_parameter.should respond_to(:param_access)
21
- end
22
-
23
- it "has a human name"
17
+ end
18
+
19
+ context "human_name" do
20
+ it "is inferred from name" do
21
+ @operation_parameter.should_receive(:param_type).and_return('path')
22
+ @operation_parameter.human_name.should == @operation_parameter.name
23
+ end
24
24
 
25
- it "detects if its allowable values are delimited as an array"
25
+ it "is made more descriptive when it's the actual body of the request" do
26
+ @operation_parameter.should_receive(:param_type).and_return('body')
27
+ @operation_parameter.human_name.should == 'request body'
28
+ end
29
+ end
26
30
 
27
- it "is required if it's part of the path"
31
+ it "has an array of allowable values" do
32
+ @operation_parameter.allowable_values.should be_an(Array)
33
+ end
28
34
 
29
- it "is positional if it's part of the path"
35
+ it "is required if it's a path param" do
36
+ @operation_parameter.should_receive(:required).and_return(false)
37
+ @operation_parameter.should_receive(:param_type).and_return('path')
38
+ @operation_parameter.required?.should == true
39
+ end
40
+
41
+ it "is positional if it's a body param" do
42
+ @operation_parameter.should_receive(:param_type).and_return('body')
43
+ @operation_parameter.positional?.should == true
44
+ end
45
+
46
+ it "is positional if it's a path param (except for 'format')" do
47
+ @operation_parameter.should_receive(:param_type).at_least(:once).and_return('path')
48
+ @operation_parameter.should_receive(:name).and_return('coolness')
49
+ @operation_parameter.positional?.should == true
50
+ end
30
51
 
31
52
  end