wordnik 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/config/pretty_print.xsl +46 -0
- data/lib/wordnik/request.rb +2 -2
- data/lib/wordnik/response.rb +5 -3
- data/lib/wordnik/version.rb +1 -1
- data/spec/response_spec.rb +20 -0
- metadata +2 -1
data/Gemfile.lock
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
2
|
+
<xsl:output method="xml" encoding="ISO-8859-1"/>
|
3
|
+
<xsl:param name="indent-increment" select="' '"/>
|
4
|
+
|
5
|
+
<xsl:template name="newline">
|
6
|
+
<xsl:text disable-output-escaping="yes">
|
7
|
+
</xsl:text>
|
8
|
+
</xsl:template>
|
9
|
+
|
10
|
+
<xsl:template match="comment() | processing-instruction()">
|
11
|
+
<xsl:param name="indent" select="''"/>
|
12
|
+
<xsl:call-template name="newline"/>
|
13
|
+
<xsl:value-of select="$indent"/>
|
14
|
+
<xsl:copy />
|
15
|
+
</xsl:template>
|
16
|
+
|
17
|
+
<xsl:template match="text()">
|
18
|
+
<xsl:param name="indent" select="''"/>
|
19
|
+
<xsl:call-template name="newline"/>
|
20
|
+
<xsl:value-of select="$indent"/>
|
21
|
+
<xsl:value-of select="normalize-space(.)"/>
|
22
|
+
</xsl:template>
|
23
|
+
|
24
|
+
<xsl:template match="text()[normalize-space(.)='']"/>
|
25
|
+
|
26
|
+
<xsl:template match="*">
|
27
|
+
<xsl:param name="indent" select="''"/>
|
28
|
+
<xsl:call-template name="newline"/>
|
29
|
+
<xsl:value-of select="$indent"/>
|
30
|
+
<xsl:choose>
|
31
|
+
<xsl:when test="count(child::*) > 0">
|
32
|
+
<xsl:copy>
|
33
|
+
<xsl:copy-of select="@*"/>
|
34
|
+
<xsl:apply-templates select="*|text()">
|
35
|
+
<xsl:with-param name="indent" select="concat ($indent, $indent-increment)"/>
|
36
|
+
</xsl:apply-templates>
|
37
|
+
<xsl:call-template name="newline"/>
|
38
|
+
<xsl:value-of select="$indent"/>
|
39
|
+
</xsl:copy>
|
40
|
+
</xsl:when>
|
41
|
+
<xsl:otherwise>
|
42
|
+
<xsl:copy-of select="."/>
|
43
|
+
</xsl:otherwise>
|
44
|
+
</xsl:choose>
|
45
|
+
</xsl:template>
|
46
|
+
</xsl:stylesheet>
|
data/lib/wordnik/request.rb
CHANGED
@@ -166,8 +166,8 @@ module Wordnik
|
|
166
166
|
|
167
167
|
def response_headers_pretty
|
168
168
|
return unless @response.present?
|
169
|
-
# JSON.pretty_generate(@response.headers).gsub(/\n/, '<br/>')
|
170
|
-
@response.headers.gsub(/\n/, '<br/>')
|
169
|
+
# JSON.pretty_generate(@response.headers).gsub(/\n/, '<br/>') # <- This was for RestClient
|
170
|
+
@response.headers.gsub(/\n/, '<br/>') # <- This is for Typhoeus
|
171
171
|
end
|
172
172
|
|
173
173
|
# It's an ActiveModel thing..
|
data/lib/wordnik/response.rb
CHANGED
@@ -3,6 +3,8 @@ module Wordnik
|
|
3
3
|
class Response
|
4
4
|
require 'active_model'
|
5
5
|
require 'json'
|
6
|
+
require 'nokogiri'
|
7
|
+
require 'htmlentities'
|
6
8
|
include ActiveModel::Validations
|
7
9
|
include ActiveModel::Conversion
|
8
10
|
extend ActiveModel::Naming
|
@@ -52,9 +54,9 @@ module Wordnik
|
|
52
54
|
return unless body.present?
|
53
55
|
case format
|
54
56
|
when :json
|
55
|
-
JSON.pretty_generate(body).gsub(/\n/, '<br/>')
|
57
|
+
JSON.pretty_generate(body).gsub(/\n/, '<br/>')
|
56
58
|
when :xml
|
57
|
-
xsl = Nokogiri::XSLT(File.open(
|
59
|
+
xsl = Nokogiri::XSLT(File.open(File.join(File.dirname(__FILE__), "../../config/pretty_print.xsl")))
|
58
60
|
xml = Nokogiri(body)
|
59
61
|
coder = HTMLEntities.new
|
60
62
|
coder.encode(xsl.apply_to(xml).to_s)
|
@@ -62,7 +64,7 @@ module Wordnik
|
|
62
64
|
end
|
63
65
|
|
64
66
|
def pretty_headers
|
65
|
-
JSON.pretty_generate(headers).gsub(/\n/, '<br/>')
|
67
|
+
JSON.pretty_generate(headers).gsub(/\n/, '<br/>')
|
66
68
|
end
|
67
69
|
|
68
70
|
# It's an ActiveModel thing..
|
data/lib/wordnik/version.rb
CHANGED
data/spec/response_spec.rb
CHANGED
@@ -45,5 +45,25 @@ describe Wordnik::Response do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
end
|
48
|
+
|
49
|
+
describe "prettiness" do
|
50
|
+
|
51
|
+
it "has a pretty json body" do
|
52
|
+
@response.pretty_body.should =~ /\{.*\}/
|
53
|
+
end
|
54
|
+
|
55
|
+
it "has a pretty xml body" do
|
56
|
+
VCR.use_cassette('xml_response_request', :record => :new_episodes) do
|
57
|
+
@raw = Typhoeus::Request.get("http://api.wordnik.com/v4/word.xml/help")
|
58
|
+
end
|
59
|
+
@response = Wordnik::Response.new(@raw)
|
60
|
+
@response.pretty_body.should =~ /\?xml/
|
61
|
+
end
|
62
|
+
|
63
|
+
it "has pretty headers" do
|
64
|
+
@response.pretty_headers.should =~ /\{.*\}/
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
48
68
|
|
49
69
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: wordnik
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Zeke Sikelianos
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- api_docs/wordLists.json
|
143
143
|
- api_docs/wordoftheday.json
|
144
144
|
- api_docs/words.json
|
145
|
+
- config/pretty_print.xsl
|
145
146
|
- lib/wordnik.rb
|
146
147
|
- lib/wordnik/configuration.rb
|
147
148
|
- lib/wordnik/endpoint.rb
|