wordnik 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +22 -3
- data/CHANGELOG +2 -0
- data/LICENSE +12 -0
- data/README.rdoc +23 -0
- data/Rakefile +51 -6
- data/VERSION +1 -0
- data/lib/wordnik.rb +4 -33
- data/lib/wordnik/word.rb +35 -0
- data/lib/wordnik/wordnik.rb +61 -0
- data/test/helper.rb +10 -0
- data/test/test_wordnik.rb +7 -0
- data/wordnik.gemspec +48 -25
- metadata +39 -183
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -57
- data/README.md +0 -0
- data/lib/wordnik/configuration.rb +0 -21
- data/lib/wordnik/endpoint.rb +0 -33
- data/lib/wordnik/operation.rb +0 -45
- data/lib/wordnik/operation_parameter.rb +0 -39
- data/lib/wordnik/request.rb +0 -163
- data/lib/wordnik/resource.rb +0 -53
- data/lib/wordnik/response.rb +0 -73
- data/lib/wordnik/version.rb +0 -3
- data/spec/endpoint_spec.rb +0 -26
- data/spec/operation_parameter_spec.rb +0 -26
- data/spec/operation_spec.rb +0 -37
- data/spec/request_spec.rb +0 -155
- data/spec/resource_spec.rb +0 -31
- data/spec/response_spec.rb +0 -49
- data/spec/spec.opts +0 -4
- data/spec/spec_helper.rb +0 -19
- data/spec/wordnik_spec.rb +0 -11
data/lib/wordnik/version.rb
DELETED
data/spec/endpoint_spec.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Endpoint do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
VCR.use_cassette('words', :record => :new_episodes) do
|
7
|
-
@response = Typhoeus::Request.get("http://api.wordnik.com/v4/word.json")
|
8
|
-
end
|
9
|
-
|
10
|
-
@endpoint = Endpoint.new(JSON.parse(@response.body)['endPoints'].first)
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "initialization" do
|
14
|
-
|
15
|
-
it "successfully initializes" do
|
16
|
-
@endpoint.path.should == "/word.{format}/{word}"
|
17
|
-
end
|
18
|
-
|
19
|
-
it "sets operations" do
|
20
|
-
@endpoint.operations.class.should == Array
|
21
|
-
@endpoint.operations.first.class.should == Operation
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe OperationParameter do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
VCR.use_cassette('words', :record => :new_episodes) do
|
7
|
-
@response = Typhoeus::Request.get("http://api.wordnik.com/v4/word.json")
|
8
|
-
end
|
9
|
-
|
10
|
-
@operation_parameter = OperationParameter.new(JSON.parse(@response.body)['endPoints'].first['operations'].first['parameters'].first)
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "initialization" do
|
14
|
-
|
15
|
-
it "successfully initializes" do
|
16
|
-
@operation_parameter.respond_to?(:name).should == true
|
17
|
-
@operation_parameter.respond_to?(:description).should == true
|
18
|
-
@operation_parameter.respond_to?(:required).should == true
|
19
|
-
@operation_parameter.respond_to?(:param_type).should == true
|
20
|
-
@operation_parameter.respond_to?(:default_value).should == true
|
21
|
-
@operation_parameter.respond_to?(:allowable_values).should == true
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
data/spec/operation_spec.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Operation do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
VCR.use_cassette('words', :record => :new_episodes) do
|
7
|
-
@response = Typhoeus::Request.get("http://api.wordnik.com/v4/word.json")
|
8
|
-
end
|
9
|
-
|
10
|
-
@operation = Operation.new(JSON.parse(@response.body)['endPoints'].first['operations'].first)
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "initialization" do
|
14
|
-
|
15
|
-
it "successfully initializes" do
|
16
|
-
@operation.summary.should =~ /returns the WordObject/i
|
17
|
-
end
|
18
|
-
|
19
|
-
it "sets parameters" do
|
20
|
-
@operation.parameters.class.should == Array
|
21
|
-
@operation.parameters.first.class.should == OperationParameter
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "instance methods" do
|
27
|
-
it "knows if its HTTP method is GET" do
|
28
|
-
@operation.http_method = "GET"
|
29
|
-
@operation.get?.should == true
|
30
|
-
@operation.http_method = "POST"
|
31
|
-
@operation.get?.should == false
|
32
|
-
@operation.http_method = "get"
|
33
|
-
@operation.get?.should == true
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
data/spec/request_spec.rb
DELETED
@@ -1,155 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Request do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@default_http_method = :get
|
7
|
-
@default_path = "words/fancy"
|
8
|
-
@default_params = {
|
9
|
-
:params => {:foo => "1", :bar => "2"}
|
10
|
-
}
|
11
|
-
@request = Request.new(@default_http_method, @default_path, @default_params)
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "initialization" do
|
15
|
-
it "sets default response format to json" do
|
16
|
-
@request.format.should == "json"
|
17
|
-
end
|
18
|
-
|
19
|
-
it "sets get default host from Wordnik.configuration" do
|
20
|
-
@request.host.should == Wordnik.configuration.base_uri
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "attr_accessors" do
|
26
|
-
|
27
|
-
it "has working attributes" do
|
28
|
-
@request.host.should == Wordnik.configuration.base_uri
|
29
|
-
@request.path.should == "words/fancy"
|
30
|
-
end
|
31
|
-
|
32
|
-
it "allows attributes to be overwritten" do
|
33
|
-
@request.http_method.should == :get
|
34
|
-
@request.http_method = "post"
|
35
|
-
@request.http_method.should == 'post'
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "url" do
|
41
|
-
|
42
|
-
it "constructs a base URL" do
|
43
|
-
@request.url.should == "http://beta.wordnik.com/v4/words.json/fancy"
|
44
|
-
end
|
45
|
-
|
46
|
-
it "constructs a query string" do
|
47
|
-
@request.query_string.should == "?bar=2&foo=1"
|
48
|
-
end
|
49
|
-
|
50
|
-
it "constructs a full url" do
|
51
|
-
@request.url_with_query_string.should == "http://beta.wordnik.com/v4/words.json/fancy?bar=2&foo=1"
|
52
|
-
end
|
53
|
-
|
54
|
-
it "accounts for excessive slashes" do
|
55
|
-
@request = Request.new(:get, "andBurn", @default_params.merge({
|
56
|
-
:host => "slash.com/"
|
57
|
-
}))
|
58
|
-
@request.url.should == "http://slash.com/andBurn.json"
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "path" do
|
64
|
-
|
65
|
-
it "accounts for a total absence of format in the path string" do
|
66
|
-
@request = Request.new(:get, "/word/{word}/entries", @default_params.merge({
|
67
|
-
:format => "xml",
|
68
|
-
:params => {
|
69
|
-
:word => "cat"
|
70
|
-
}
|
71
|
-
}))
|
72
|
-
@request.url.should == "http://beta.wordnik.com/v4/word.xml/cat/entries"
|
73
|
-
end
|
74
|
-
|
75
|
-
it "does string substitution on path params" do
|
76
|
-
@request = Request.new(:get, "/word.{format}/{word}/entries", @default_params.merge({
|
77
|
-
:format => "xml",
|
78
|
-
:params => {
|
79
|
-
:word => "cat"
|
80
|
-
}
|
81
|
-
}))
|
82
|
-
@request.url.should == "http://beta.wordnik.com/v4/word.xml/cat/entries"
|
83
|
-
end
|
84
|
-
|
85
|
-
it "leaves path-bound params out of the query string" do
|
86
|
-
@request = Request.new(:get, "/word.{format}/{word}/entries", @default_params.merge({
|
87
|
-
:params => {
|
88
|
-
:word => "cat",
|
89
|
-
:limit => 20
|
90
|
-
}
|
91
|
-
}))
|
92
|
-
@request.query_string.should == "?limit=20"
|
93
|
-
end
|
94
|
-
|
95
|
-
it "returns a question-mark free (blank) query string if no query params are present" do
|
96
|
-
@request = Request.new(:get, "/word.{format}/{word}/entries", @default_params.merge({
|
97
|
-
:params => {
|
98
|
-
:word => "cat",
|
99
|
-
}
|
100
|
-
}))
|
101
|
-
@request.query_string.should == ""
|
102
|
-
end
|
103
|
-
|
104
|
-
it "removes blank params" do
|
105
|
-
@request = Request.new(:get, "words/fancy", @default_params.merge({
|
106
|
-
:params => {
|
107
|
-
:word => "dog",
|
108
|
-
:limit => "",
|
109
|
-
:foo => "criminy"
|
110
|
-
}
|
111
|
-
}))
|
112
|
-
@request.query_string.should == "?foo=criminy&word=dog"
|
113
|
-
end
|
114
|
-
|
115
|
-
it "obfuscates the API key when needed" do
|
116
|
-
@request = Request.new(:get, "words/fancy", @default_params.merge({
|
117
|
-
:params => {
|
118
|
-
:word => "dog",
|
119
|
-
:api_key => "123456"
|
120
|
-
}
|
121
|
-
}))
|
122
|
-
@request.query_string_params.should == {:word => "dog", :api_key => "123456"}
|
123
|
-
@request.query_string_params(true).should == {:word => "dog", :api_key => "YOUR_API_KEY"}
|
124
|
-
|
125
|
-
@request.query_string.should == "?api_key=123456&word=dog"
|
126
|
-
@request.query_string(:obfuscated => true).should == "?api_key=YOUR_API_KEY&word=dog"
|
127
|
-
|
128
|
-
@request.url_with_query_string.should =~ /123456/
|
129
|
-
@request.url_with_query_string(:obfuscated => true).should =~ /YOUR\_API\_KEY/
|
130
|
-
end
|
131
|
-
|
132
|
-
it "URI encodes the path" do
|
133
|
-
@request = Request.new(:get, "word.{format}/{word}/definitions", @default_params.merge({
|
134
|
-
:params => {
|
135
|
-
:word => "bill gates"
|
136
|
-
}
|
137
|
-
}))
|
138
|
-
@request.url.should =~ /word.json\/bill\%20gates\/definitions/
|
139
|
-
end
|
140
|
-
|
141
|
-
it "converts numeric params to strings" do
|
142
|
-
@request = Request.new(@default_http_method, @default_path, @default_params.merge({
|
143
|
-
:params => {
|
144
|
-
:limit => 100
|
145
|
-
}
|
146
|
-
}))
|
147
|
-
|
148
|
-
@request.interpreted_path.should_not be_nil
|
149
|
-
@request.query_string.should =~ /\?limit=100/
|
150
|
-
@request.url_with_query_string.should =~ /\?limit=100/
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
end
|
data/spec/resource_spec.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Resource do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
VCR.use_cassette('words', :record => :new_episodes) do
|
7
|
-
@response = Typhoeus::Request.get("http://api.wordnik.com/v4/word.json")
|
8
|
-
end
|
9
|
-
|
10
|
-
@default_params = {
|
11
|
-
:name => "word",
|
12
|
-
:raw_data => JSON.parse(@response.body)
|
13
|
-
}
|
14
|
-
|
15
|
-
@resource = Resource.new(@default_params)
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "initialization" do
|
19
|
-
|
20
|
-
it "successfully initializes" do
|
21
|
-
@resource.name.should == "word"
|
22
|
-
end
|
23
|
-
|
24
|
-
it "sets endpoints" do
|
25
|
-
@resource.endpoints.size.should == 10
|
26
|
-
@resource.endpoints.first.class.to_s.should == "Endpoint"
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
data/spec/response_spec.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Response do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
|
7
|
-
VCR.use_cassette('default_response_request', :record => :new_episodes) do
|
8
|
-
@raw = Typhoeus::Request.get("http://api.wordnik.com/v4/word.json")
|
9
|
-
end
|
10
|
-
|
11
|
-
@response = Response.new(@raw)
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "initialization" do
|
15
|
-
it "sets body" do
|
16
|
-
@response.body.class.should == Hash
|
17
|
-
@response.body.has_key?('endPoints').should == true
|
18
|
-
end
|
19
|
-
|
20
|
-
it "sets code" do
|
21
|
-
@response.code.should == 200
|
22
|
-
end
|
23
|
-
|
24
|
-
it "converts header string into a hash" do
|
25
|
-
@response.headers.class.should == Hash
|
26
|
-
@response.headers['Wordnik-Api-Version'].to_s.should =~ /4\.0/
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "format" do
|
32
|
-
|
33
|
-
it "recognizes json" do
|
34
|
-
@response.format.should == :json
|
35
|
-
@response.json?.should == true
|
36
|
-
end
|
37
|
-
|
38
|
-
it "recognizes xml" do
|
39
|
-
VCR.use_cassette('xml_response_request', :record => :new_episodes) do
|
40
|
-
@raw = Typhoeus::Request.get("http://api.wordnik.com/v4/word.xml/help")
|
41
|
-
end
|
42
|
-
@response = Response.new(@raw)
|
43
|
-
@response.format.should == :xml
|
44
|
-
@response.xml?.should == true
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
data/spec/spec.opts
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler/setup'
|
3
|
-
require 'wordnik'
|
4
|
-
require 'vcr'
|
5
|
-
require 'typhoeus'
|
6
|
-
require 'json'
|
7
|
-
|
8
|
-
RSpec.configure do |config|
|
9
|
-
# some (optional) config here
|
10
|
-
end
|
11
|
-
|
12
|
-
VCR.config do |config|
|
13
|
-
config.cassette_library_dir = 'spec/vcr'
|
14
|
-
config.stub_with :webmock # or :fakeweb
|
15
|
-
end
|
16
|
-
|
17
|
-
Wordnik.configure do |config|
|
18
|
-
config.api_key = "12345"
|
19
|
-
end
|