wordnik 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/wordnik/request.rb +4 -3
- data/lib/wordnik/response.rb +2 -2
- data/lib/wordnik/version.rb +1 -1
- data/spec/request_spec.rb +9 -1
- data/spec/response_spec.rb +9 -0
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/lib/wordnik/request.rb
CHANGED
@@ -89,9 +89,10 @@ module Wordnik
|
|
89
89
|
def query_string_params(obfuscated=false)
|
90
90
|
qsp = {}
|
91
91
|
self.params.each_pair do |key, value|
|
92
|
-
next if self.path.include? "{#{key}}"
|
93
|
-
next if value.blank?
|
94
|
-
value = "YOUR_API_KEY" if key.to_sym == :api_key && obfuscated
|
92
|
+
next if self.path.include? "{#{key}}" # skip path params
|
93
|
+
next if value.blank? # skip empties
|
94
|
+
value = "YOUR_API_KEY" if key.to_sym == :api_key && obfuscated # obscure the API key
|
95
|
+
key = key.to_s.camelize(:lower).to_sym unless key.to_sym == :api_key # api_key is not a camelCased param
|
95
96
|
qsp[key] = value.to_s
|
96
97
|
end
|
97
98
|
qsp
|
data/lib/wordnik/response.rb
CHANGED
@@ -25,9 +25,9 @@ module Wordnik
|
|
25
25
|
# TODO: If body is XML, parse it
|
26
26
|
# Otherwise return raw string
|
27
27
|
def body
|
28
|
-
JSON.parse
|
28
|
+
JSON.parse raw.body.encode(::Encoding::UTF_8, undef: :replace)
|
29
29
|
rescue
|
30
|
-
raw.body
|
30
|
+
raw.body.encode(::Encoding::UTF_8, undef: :replace)
|
31
31
|
end
|
32
32
|
|
33
33
|
def headers
|
data/lib/wordnik/version.rb
CHANGED
data/spec/request_spec.rb
CHANGED
@@ -133,7 +133,15 @@ describe Wordnik::Request do
|
|
133
133
|
@request.url_with_query_string.should =~ /\?limit=100/
|
134
134
|
end
|
135
135
|
|
136
|
-
it "camelCases parameters"
|
136
|
+
it "camelCases parameters" do
|
137
|
+
@request = Wordnik::Request.new(@default_http_method, @default_path, @default_params.merge({
|
138
|
+
:params => {
|
139
|
+
:bad_dog => 'bud',
|
140
|
+
:goodDog => "dud"
|
141
|
+
}
|
142
|
+
}))
|
143
|
+
@request.query_string.should == "?badDog=bud&goodDog=dud"
|
144
|
+
end
|
137
145
|
|
138
146
|
end
|
139
147
|
|
data/spec/response_spec.rb
CHANGED
@@ -52,6 +52,15 @@ describe Wordnik::Response do
|
|
52
52
|
@response.pretty_body.should =~ /\{.*\}/
|
53
53
|
end
|
54
54
|
|
55
|
+
it "has a pretty XML body even in the face of adverse characters" do
|
56
|
+
configure_wordnik
|
57
|
+
VCR.use_cassette('crazier_json_request', :record => :new_episodes) do
|
58
|
+
# @request = Wordnik::Request.new(:get, "word.xml/cat/definitions", :params => {:source_dictionaries => "century"})
|
59
|
+
@request = Wordnik::Request.new(:get, "word.xml/hero/pronunciations", :params => {:limit => 1})
|
60
|
+
end
|
61
|
+
@request.response.pretty_body.should =~ /\?xml/
|
62
|
+
end
|
63
|
+
|
55
64
|
it "has a pretty xml body" do
|
56
65
|
VCR.use_cassette('xml_response_request', :record => :new_episodes) do
|
57
66
|
@raw = Typhoeus::Request.get("http://api.wordnik.com/v4/word.xml/help")
|