wordnik 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +6 -6
- data/lib/wordnik/request.rb +2 -5
- data/lib/wordnik/resource.rb +17 -3
- data/lib/wordnik/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/wordnik_spec.rb +41 -9
- metadata +2 -2
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
wordnik (0.4.
|
4
|
+
wordnik (0.4.5)
|
5
5
|
activemodel (>= 3.0.3)
|
6
6
|
addressable (>= 2.2.4)
|
7
7
|
htmlentities (>= 4.2.4)
|
@@ -12,16 +12,16 @@ PATH
|
|
12
12
|
GEM
|
13
13
|
remote: http://rubygems.org/
|
14
14
|
specs:
|
15
|
-
activemodel (3.0.
|
16
|
-
activesupport (= 3.0.
|
15
|
+
activemodel (3.0.6)
|
16
|
+
activesupport (= 3.0.6)
|
17
17
|
builder (~> 2.1.2)
|
18
|
-
i18n (~> 0.
|
19
|
-
activesupport (3.0.
|
18
|
+
i18n (~> 0.5.0)
|
19
|
+
activesupport (3.0.6)
|
20
20
|
addressable (2.2.4)
|
21
21
|
builder (2.1.2)
|
22
22
|
crack (0.1.8)
|
23
23
|
diff-lcs (1.1.2)
|
24
|
-
htmlentities (4.
|
24
|
+
htmlentities (4.3.0)
|
25
25
|
i18n (0.5.0)
|
26
26
|
json (1.5.1)
|
27
27
|
mime-types (1.16)
|
data/lib/wordnik/request.rb
CHANGED
@@ -165,14 +165,11 @@ module Wordnik
|
|
165
165
|
:headers => self.headers.stringify_keys
|
166
166
|
)
|
167
167
|
end
|
168
|
-
|
169
|
-
@response_obj = Response.new(response)
|
168
|
+
Response.new(response)
|
170
169
|
end
|
171
170
|
|
172
|
-
# If the request has been made, return the existing response
|
173
|
-
# If not, make the request and return the response
|
174
171
|
def response
|
175
|
-
|
172
|
+
self.make
|
176
173
|
end
|
177
174
|
|
178
175
|
def response_code_pretty
|
data/lib/wordnik/resource.rb
CHANGED
@@ -58,11 +58,25 @@ module Wordnik
|
|
58
58
|
# Ruby turns all key-value arguments at the end into a single hash
|
59
59
|
# e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
|
60
60
|
# becomes {:limit => 10, :part_of_speech => 'verb'}
|
61
|
-
|
61
|
+
last_arg = args.pop if args.last.is_a?(Hash)
|
62
|
+
last_arg = args.pop if args.last.is_a?(Array)
|
63
|
+
last_arg ||= {}
|
64
|
+
|
65
|
+
if [:post, :put].include?(http_method)
|
66
|
+
params = nil
|
67
|
+
body = last_arg
|
68
|
+
else
|
69
|
+
params = last_arg
|
70
|
+
body = nil
|
71
|
+
end
|
62
72
|
|
63
73
|
# Find the path that corresponds to this method nickname
|
64
74
|
# e.g. post_words -> "/wordList.{format}/{wordListId}/words"
|
65
|
-
|
75
|
+
begin
|
76
|
+
path = self.path_for_operation_nickname(nickname)
|
77
|
+
rescue
|
78
|
+
raise "Cannot find a resource path that corresponds to the method nickname '#{nickname}'"
|
79
|
+
end
|
66
80
|
|
67
81
|
# Take the '.{format}' portion out of the string so it doesn't interfere with
|
68
82
|
# the interpolation we're going to do on the path.
|
@@ -75,7 +89,7 @@ module Wordnik
|
|
75
89
|
|
76
90
|
# TODO: treat kwargs as body instead of params if request method is post or put
|
77
91
|
|
78
|
-
request = Wordnik::Request.new(http_method, path, :params => params)
|
92
|
+
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
|
79
93
|
|
80
94
|
if build_only
|
81
95
|
request
|
data/lib/wordnik/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/wordnik_spec.rb
CHANGED
@@ -106,7 +106,19 @@ describe Wordnik do
|
|
106
106
|
@request.query_string.should == "?limit=10&skip=2"
|
107
107
|
end
|
108
108
|
|
109
|
-
it "puts key-value arguments in the request body instead of the query params"
|
109
|
+
it "puts key-value arguments in the request body instead of the query params for POSTs and PUTs" do
|
110
|
+
body = {
|
111
|
+
:name => "Wordnik Ruby Test List #{RAND}",
|
112
|
+
:description => 'This is created by the test suite.',
|
113
|
+
:type => 'PUBLIC',
|
114
|
+
:user_id => Wordnik.configuration.user_id
|
115
|
+
}
|
116
|
+
@request = Wordnik.word_lists.build_post(body)
|
117
|
+
@request.body.should have_key(:name)
|
118
|
+
@request.body.should have_key(:description)
|
119
|
+
@request.body.should have_key(:type)
|
120
|
+
@request.body.should have_key(:userId)
|
121
|
+
end
|
110
122
|
|
111
123
|
end
|
112
124
|
|
@@ -114,28 +126,48 @@ describe Wordnik do
|
|
114
126
|
|
115
127
|
before do
|
116
128
|
configure_wordnik
|
117
|
-
Wordnik.authenticate
|
129
|
+
Wordnik.authenticate
|
130
|
+
@permalink = "wordnik-ruby-test-list-#{RAND}"
|
118
131
|
end
|
119
132
|
|
120
133
|
it "creates a wordlist" do
|
121
134
|
body = {
|
122
|
-
:name=> "Wordnik Ruby Test List #{RAND}",
|
135
|
+
:name => "Wordnik Ruby Test List #{RAND}",
|
123
136
|
:description => 'This is created by the test suite.',
|
124
137
|
:type => 'PUBLIC',
|
125
138
|
:user_id => Wordnik.configuration.user_id
|
126
139
|
}
|
127
|
-
request = Wordnik
|
128
|
-
request.response
|
129
|
-
|
140
|
+
request = Wordnik.word_lists.build_post(body)
|
141
|
+
response = request.response
|
142
|
+
response.body.should be_a_kind_of(Hash)
|
143
|
+
response.body.should have_key('permalink')
|
144
|
+
response.body['permalink'].should == @permalink
|
145
|
+
end
|
146
|
+
|
147
|
+
it "finds the new wordlist (method 1, using the wordList resource)" do
|
148
|
+
list = Wordnik.word_list.get(@permalink)
|
149
|
+
list.should have_key('permalink')
|
150
|
+
list['permalink'].should == @permalink
|
130
151
|
end
|
131
152
|
|
132
|
-
it "finds the new wordlist" do
|
153
|
+
it "finds the new wordlist (method 2, among user's wordlists)" do
|
133
154
|
lists = Wordnik.account.get_word_lists
|
134
155
|
permalinks = lists.map { |list| list['permalink'] }
|
135
|
-
permalinks.should include(
|
156
|
+
permalinks.should include(@permalink)
|
136
157
|
end
|
137
158
|
|
138
|
-
it "
|
159
|
+
it "adds words to it" do
|
160
|
+
body = [
|
161
|
+
{:word => 'foo'},
|
162
|
+
{:word => 'bar'},
|
163
|
+
{:word => 'metasyntactic'},
|
164
|
+
]
|
165
|
+
request = Wordnik.word_list.build_post_words(@permalink, body)
|
166
|
+
# raise request.response.inspect
|
167
|
+
|
168
|
+
list = Wordnik.word_list.get(@permalink)
|
169
|
+
# raise list.inspect
|
170
|
+
end
|
139
171
|
|
140
172
|
it "updates words"
|
141
173
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: wordnik
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.4.
|
5
|
+
version: 0.4.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Zeke Sikelianos
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-04-
|
14
|
+
date: 2011-04-21 00:00:00 -07:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|