foaas-client 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +107 -31
- data/lib/foaas-client/client.rb +6 -3
- data/lib/foaas-client/version.rb +1 -1
- data/spec/foaas-client/client_spec.rb +266 -158
- metadata +4 -4
- data/CHANGELOG.md~ +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6f403c522cdcffe8b5b575db4ecdeb9799c5841
|
4
|
+
data.tar.gz: f8acfb17a7d5b7683c0d041437f5642c11b8c21a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee06f9dbd7d1c2eba915bfc48acbae3237654eb29d2f68f7744e890076228826cd1844dc89b938d9436849a802fd1ca4b871d4490f960c97e1f5dd13d3d8d30e
|
7
|
+
data.tar.gz: 7f24ff69a416d1cb0eac18e445d5742756400d3b49846a38d5448093d844961eeaf46847128b1637a8ef6b38db4f116f0a74bc256a7a77e5f8e1c4758656a3ef
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.2.0
|
4
|
+
|
5
|
+
* Fix errors in README
|
6
|
+
* Add support for XML response type
|
7
|
+
* Implement the following FOAAS methods:
|
8
|
+
* Ballmer
|
9
|
+
* Field
|
10
|
+
* Caniuse
|
11
|
+
* Because
|
12
|
+
* What
|
13
|
+
* Yoda
|
14
|
+
* Nugget
|
15
|
+
* Cool
|
16
|
+
* Madison
|
17
|
+
|
3
18
|
## v0.1.0
|
4
19
|
|
5
20
|
* Implement the following FOAAS methods:
|
data/README.md
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
# Foaas Client
|
2
2
|
|
3
|
+
[](https://travis-ci.org/petedmarsh/foaas-client)
|
4
|
+
[](https://codeclimate.com/github/petedmarsh/foaas-client)
|
5
|
+
|
3
6
|
A client for [FOAAS](http://foaas.com).
|
4
7
|
|
5
8
|
## API Version
|
6
9
|
|
7
|
-
Version `0.0.
|
10
|
+
Version `0.0.4` of the FOAAS API is supported.
|
8
11
|
|
9
12
|
## Usage
|
10
13
|
|
@@ -28,71 +31,81 @@ fuck.off('Bob', 'Alice', :text)
|
|
28
31
|
|
29
32
|
fuck.off('Bob', 'Alice', :html)
|
30
33
|
#=> '<html>...</html>'
|
34
|
+
|
35
|
+
fuck.off('Bob', 'Alice', :xml)
|
36
|
+
#=> '<?xml version="1.0" encoding="utf-8"?>'
|
31
37
|
```
|
32
38
|
|
33
39
|
### Methods
|
34
40
|
|
35
|
-
|
41
|
+
### Ballmer
|
36
42
|
|
37
43
|
```ruby
|
38
|
-
fuck.
|
39
|
-
#=> { 'message' => '
|
44
|
+
fuck.ballmer('Bob', 'Alice', 'Clara')
|
45
|
+
#=> { 'message' => 'Fucking Bob is a fucking pussy. I'm going to fucking bury that guy, I have done it before, and I will do it again. I'm going to fucking kill Alice.', 'subtitle' => 'Clara' }
|
40
46
|
```
|
41
47
|
|
42
|
-
|
48
|
+
### Because
|
43
49
|
|
44
50
|
```ruby
|
45
|
-
fuck.
|
46
|
-
#=> { 'message' => 'Fuck
|
51
|
+
fuck.because('Alice')
|
52
|
+
#=> { 'message' => 'Why? Because Fuck you, that\'s why.', 'subtitle' => 'Alice' }
|
47
53
|
```
|
48
54
|
|
49
|
-
|
55
|
+
### Can I use?
|
50
56
|
|
51
57
|
```ruby
|
52
|
-
fuck.
|
53
|
-
#=> { 'message' => '
|
58
|
+
fuck.caniuse('Bob', 'Alice')
|
59
|
+
#=> { 'message' => 'Can you use Bob? Fuck no!', 'subtitle' => '- Alice' }
|
54
60
|
```
|
55
61
|
|
56
|
-
####
|
62
|
+
#### Chainsaw
|
57
63
|
|
58
64
|
```ruby
|
59
|
-
fuck.
|
60
|
-
#=> { 'message' => 'Fuck
|
65
|
+
fuck.chainsaw('Bob', 'Alice')
|
66
|
+
#=> { 'message' => 'Fuck me gently with a chainsaw, Bob. Do I look like Mother Teresa?', 'subtitle' => '- Alice' }
|
61
67
|
```
|
62
68
|
|
63
|
-
|
69
|
+
### Cool
|
64
70
|
|
65
71
|
```ruby
|
66
|
-
fuck.
|
67
|
-
#=> { 'message' => '
|
72
|
+
fuck.cool('Alice')
|
73
|
+
#=> { 'message' => 'Cool story, Bro', '- Alice' }
|
68
74
|
```
|
69
75
|
|
70
|
-
####
|
76
|
+
#### Donut
|
71
77
|
|
72
78
|
```ruby
|
73
|
-
fuck.
|
74
|
-
#=> { 'message' => '
|
79
|
+
fuck.donut('Bob', 'Alice')
|
80
|
+
#=> { 'message' => 'Bob, go and take a flying fuck at a rolling donut.', 'subtitle' => '- Alice' }
|
75
81
|
```
|
76
82
|
|
77
|
-
####
|
83
|
+
#### Everyone
|
78
84
|
|
79
85
|
```ruby
|
80
|
-
fuck.
|
81
|
-
#=> { 'message' => '
|
86
|
+
fuck.everyone('Alice')
|
87
|
+
#=> { 'message' => 'Everyone can go and fuck off.', 'subtitle' => '- Alice' }
|
82
88
|
```
|
83
89
|
|
84
|
-
####
|
90
|
+
#### Everything
|
85
91
|
|
86
92
|
```ruby
|
87
|
-
fuck.
|
88
|
-
#=> { 'message' => 'Fuck
|
93
|
+
fuck.everything('Alice')
|
94
|
+
#=> { 'message' => 'Fuck everything.', 'subtitle' => '- Alice' }
|
89
95
|
```
|
90
96
|
|
91
|
-
####
|
97
|
+
#### Fascinating
|
92
98
|
|
93
99
|
```ruby
|
94
|
-
fuck.
|
95
|
-
#=> { 'message' => '
|
100
|
+
fuck.fascinating('Alice')
|
101
|
+
#=> { 'message' => 'Fascinating story, in what chapter do you shut the fuck up?', 'subtitle' => '- Alice' }
|
102
|
+
```
|
103
|
+
|
104
|
+
### Field
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
fuck.field('Bob', 'Alice', 'Clara')
|
108
|
+
#=> { 'message' => 'And Alice said on to Bob, "Verily, cast thine eyes upon the field in which I grow my fucks", and Bobgave witness onto the field, and saw that it was barren.', => '- Clara' }
|
96
109
|
```
|
97
110
|
|
98
111
|
#### King
|
@@ -102,6 +115,13 @@ fuck.king('Bob', 'Alice')
|
|
102
115
|
#=> { 'message' => 'Oh fuck off, just really fuck off you total dickface. Christ Bob, you are fucking thick.', 'subtitle' => '- Alice' }
|
103
116
|
```
|
104
117
|
|
118
|
+
#### Life
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
fuck.life('Alice')
|
122
|
+
#=> { 'message' => 'Fuck my life.', 'subtitle' => '- Alice' }
|
123
|
+
```
|
124
|
+
|
105
125
|
#### Linus
|
106
126
|
|
107
127
|
```ruby
|
@@ -109,6 +129,20 @@ fuck.linus('Bob', 'Alice')
|
|
109
129
|
#=> { 'message' => 'Bob, there aren't enough swear-words in the English language, so now I'll have to call you perkeleen vittupää just to express my disgust and frustration with this crap.', 'subtitle' => '- Alice' }
|
110
130
|
```
|
111
131
|
|
132
|
+
### Madison
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
fuck.madison('Bob', 'Alice')
|
136
|
+
#=> { 'What you\'ve said is one of the most insantely idiotic things I have ever heard, Bob. At no point in your rambling, incoherent response were you even close to anything that could be considered a rational thought. Everyone in this room is now dumber for having listened to it. I award you no points Bob, and may God have mercy on your soul.', 'subtitle' => '- Alice' }
|
137
|
+
```
|
138
|
+
|
139
|
+
### Nugget
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
fuck.nugget('Bob', 'Alice')
|
143
|
+
#=> { ''Well Bob, aren\'t you a shining example of a rancid fuck-nugget.', 'subtitle' => '- Alice' }
|
144
|
+
```
|
145
|
+
|
112
146
|
#### Off
|
113
147
|
|
114
148
|
```ruby
|
@@ -116,6 +150,20 @@ fuck.off('Bob', 'Alice')
|
|
116
150
|
#=> { 'message' => 'Fuck off, Bob.', 'subtitle' => '- Alice' }
|
117
151
|
```
|
118
152
|
|
153
|
+
### Outside
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
fuck.outside('Bob', 'Alice')
|
157
|
+
#=> { 'message' => 'Bob, why don\'t you go outside and play hide-and-go-fuck-yourself?', 'subtitle' => '- Alice' }
|
158
|
+
```
|
159
|
+
|
160
|
+
#### Pink
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
fuck.pink('Alice')
|
164
|
+
#=> { 'message' => 'Well, Fuck me pink.', 'subtitle' => '- Alice' }
|
165
|
+
```
|
166
|
+
|
119
167
|
#### Shakespeare
|
120
168
|
|
121
169
|
```ruby
|
@@ -130,11 +178,11 @@ fuck.thanks('Bob', 'Alice')
|
|
130
178
|
#=> { 'message' => 'Fuck you very much', 'subtitle' => '- Alice' }
|
131
179
|
```
|
132
180
|
|
133
|
-
####
|
181
|
+
#### That
|
134
182
|
|
135
183
|
```ruby
|
136
|
-
fuck.
|
137
|
-
#=> { 'message' => 'Fuck
|
184
|
+
fuck.that('Alice')
|
185
|
+
#=> { 'message' => 'Fuck that', 'subtitle' => '- Alice' }
|
138
186
|
```
|
139
187
|
|
140
188
|
#### Thing
|
@@ -143,3 +191,31 @@ fuck.you('Bob', 'Alice')
|
|
143
191
|
fuck.thing('it', 'Alice')
|
144
192
|
#=> { 'message' => 'Fuck it.', 'subtitle' => '- Alice' }
|
145
193
|
```
|
194
|
+
|
195
|
+
#### This
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
fuck.this('Alice')
|
199
|
+
#=> { 'message' => 'Fuck this.', 'subtitle' => '- Alice' }
|
200
|
+
```
|
201
|
+
|
202
|
+
### What
|
203
|
+
|
204
|
+
```ruby
|
205
|
+
fuck.what('Alice')
|
206
|
+
#=> { 'message' => 'What the fuck?!', 'subtitle' => '- Alice' }
|
207
|
+
```
|
208
|
+
|
209
|
+
### Yoda
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
fuck.yoda('Bob', 'Alice')
|
213
|
+
#=> { 'message' => 'Fuck off, you must, Bob', 'subtitle' => '- Alice' }
|
214
|
+
```
|
215
|
+
|
216
|
+
#### You
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
fuck.you('Bob', 'Alice')
|
220
|
+
#=> { 'message' => 'Fuck you, Bob.', 'subtitle' => '- Alice' }
|
221
|
+
```
|
data/lib/foaas-client/client.rb
CHANGED
@@ -5,16 +5,19 @@ require 'json'
|
|
5
5
|
module Foaas
|
6
6
|
class Client
|
7
7
|
|
8
|
-
URL = Addressable::Template.new("http://foaas.com/{method}{/name}/{from}")
|
8
|
+
URL = Addressable::Template.new("http://foaas.com/{method}{/name}/{from}{/other}")
|
9
9
|
|
10
|
-
METHODS_ONE_PARAM = [:
|
11
|
-
METHODS_TWO_PARAMS = [:
|
10
|
+
METHODS_ONE_PARAM = [:because, :cool, :everyone, :everything, :fascinating, :flying, :life, :pink, :thanks, :this, :what]
|
11
|
+
METHODS_TWO_PARAMS = [:donut, :caniuse, :chainsaw, :king, :linus, :madison, :nugget, :off, :outside, :shakespeare, :you, :yoda]
|
12
|
+
METHODS_THREE_PARAMS = [:ballmer, :field]
|
12
13
|
|
13
14
|
def method_missing(sym, *args, &block)
|
14
15
|
if METHODS_TWO_PARAMS.include? sym
|
15
16
|
make_request(URL.expand(method: sym, name: args[0], from: args[1]), args[2])
|
16
17
|
elsif METHODS_ONE_PARAM.include? sym
|
17
18
|
make_request(URL.expand(method: sym, from: args[0]), args[1])
|
19
|
+
elsif METHODS_THREE_PARAMS.include? sym
|
20
|
+
make_request(URL.expand(method: sym, name: args[0], from: args[1], other: args[2]), args[3])
|
18
21
|
elsif sym == :thing
|
19
22
|
make_request(URL.expand(method: args[0], from: args[1]), args[2])
|
20
23
|
else
|
data/lib/foaas-client/version.rb
CHANGED
@@ -4,242 +4,350 @@ require 'foaas-client/client'
|
|
4
4
|
|
5
5
|
describe Foaas::Client do
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
it 'raises an exception if a method is unsupported' do
|
8
|
+
expect { client.not_a_foaas_method }.to raise_error NoMethodError
|
9
|
+
end
|
10
10
|
|
11
|
-
|
11
|
+
let(:client) { Foaas::Client.new }
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
Foaas::Client::METHODS_THREE_PARAMS.each do |method|
|
14
|
+
describe "##{method}" do
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
before do
|
17
|
+
RestClient.should_receive(:get).with(url, { accept: accept }).and_return('{ "message" : "", "subtitle" : ""}')
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
let(:name) { 'name' }
|
21
|
+
let(:from) { 'from' }
|
22
|
+
let(:other) { 'other' }
|
23
|
+
let(:type) { nil }
|
23
24
|
|
24
|
-
|
25
|
+
let(:url) { "http://foaas.com/#{method}/#{name}/#{from}/#{other}" }
|
25
26
|
|
26
|
-
|
27
|
+
context 'type is' do
|
27
28
|
|
28
|
-
|
29
|
+
context 'not specified' do
|
29
30
|
|
30
|
-
|
31
|
+
let(:accept) { :json }
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
it 'defaults to JSON' do
|
34
|
+
client.send(method, name, from, other, type)
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
+
context 'is specified' do
|
39
40
|
|
40
|
-
|
41
|
+
context 'as HTML' do
|
41
42
|
|
42
|
-
|
43
|
-
|
43
|
+
let(:type) { :html }
|
44
|
+
let(:accept) { :html }
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
it 'specifies text/html as the accept type' do
|
47
|
+
client.send(method, name, from, other, type)
|
48
|
+
end
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
+
context 'as JSON' do
|
51
52
|
|
52
|
-
|
53
|
-
|
53
|
+
let(:type) { :json }
|
54
|
+
let(:accept) { :json}
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
it 'specifies application/json as the accept type' do
|
57
|
+
client.send(method, name, from, other, type)
|
58
|
+
end
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
it 'parses the response into a hash' do
|
61
|
+
client.send(method, name, from, other, type).should == { 'message' => '', 'subtitle' => ''}
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
+
context 'as text' do
|
66
67
|
|
67
|
-
|
68
|
-
|
68
|
+
let(:type) { :text }
|
69
|
+
let(:accept) { 'text/plain' }
|
69
70
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
71
|
+
it 'specifies text/plain as the accept type' do
|
72
|
+
client.send(method, name, from, other, type)
|
73
|
+
end
|
74
|
+
end
|
76
75
|
|
77
|
-
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
76
|
+
context 'as xml' do
|
81
77
|
|
78
|
+
let(:type) { :xml }
|
79
|
+
let(:accept) { :xml }
|
82
80
|
|
83
|
-
|
84
|
-
|
81
|
+
it 'specifies application/xml as the acccept type' do
|
82
|
+
client.send(method, name, from, other, type)
|
83
|
+
end
|
84
|
+
end
|
85
85
|
|
86
|
-
|
87
|
-
RestClient.should_receive(:get).with(url, { accept: accept }).and_return('{ "message" : "", "subtitle" : ""}')
|
88
|
-
end
|
86
|
+
end
|
89
87
|
|
90
|
-
|
91
|
-
|
92
|
-
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
93
92
|
|
94
|
-
context 'type is' do
|
95
93
|
|
96
|
-
|
94
|
+
Foaas::Client::METHODS_TWO_PARAMS.each do |method|
|
95
|
+
describe "##{method}" do
|
97
96
|
|
98
|
-
|
97
|
+
before do
|
98
|
+
RestClient.should_receive(:get).with(url, { accept: accept }).and_return('{ "message" : "", "subtitle" : ""}')
|
99
|
+
end
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
|
101
|
+
let(:name) { 'name' }
|
102
|
+
let(:from) { 'from' }
|
103
|
+
let(:type) { nil }
|
103
104
|
|
104
|
-
|
105
|
+
let(:url) { "http://foaas.com/#{method}/#{name}/#{from}" }
|
105
106
|
|
106
|
-
|
107
|
+
context 'type is' do
|
107
108
|
|
108
|
-
|
109
|
+
context 'not specified' do
|
109
110
|
|
110
|
-
|
111
|
-
let(:accept) { :html }
|
111
|
+
let(:accept) { :json }
|
112
112
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
end
|
113
|
+
it 'defaults to JSON' do
|
114
|
+
client.send(method, name, from, type)
|
115
|
+
end
|
117
116
|
|
118
|
-
|
117
|
+
end
|
119
118
|
|
120
|
-
|
121
|
-
let(:accept) { :json }
|
119
|
+
context 'is specified' do
|
122
120
|
|
123
|
-
|
124
|
-
client.send(method, from, type)
|
125
|
-
end
|
121
|
+
context 'as HTML' do
|
126
122
|
|
127
|
-
|
128
|
-
|
129
|
-
end
|
123
|
+
let(:type) { :html }
|
124
|
+
let(:accept) { :html }
|
130
125
|
|
131
|
-
|
126
|
+
it 'specifies text/html as the accept type' do
|
127
|
+
client.send(method, name, from, type)
|
128
|
+
end
|
129
|
+
end
|
132
130
|
|
133
|
-
|
131
|
+
context 'as JSON' do
|
134
132
|
|
135
|
-
|
136
|
-
|
133
|
+
let(:type) { :json }
|
134
|
+
let(:accept) { :json}
|
137
135
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
end
|
142
|
-
|
143
|
-
end
|
136
|
+
it 'specifies application/json as the accept type' do
|
137
|
+
client.send(method, name, from, type)
|
138
|
+
end
|
144
139
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
end
|
140
|
+
it 'parses the response into a hash' do
|
141
|
+
client.send(method, name, from, type).should == { 'message' => '', 'subtitle' => ''}
|
142
|
+
end
|
149
143
|
|
150
|
-
|
144
|
+
end
|
151
145
|
|
152
|
-
|
153
|
-
RestClient.should_receive(:get).with(url, { accept: accept }).and_return('{ "message" : "", "subtitle" : ""}')
|
154
|
-
end
|
146
|
+
context 'as text' do
|
155
147
|
|
156
|
-
|
157
|
-
|
158
|
-
let(:from) { 'from' }
|
159
|
-
let(:type) { nil }
|
148
|
+
let(:type) { :text }
|
149
|
+
let(:accept) { 'text/plain' }
|
160
150
|
|
161
|
-
|
151
|
+
it 'specifies text/plain as the accept type' do
|
152
|
+
client.send(method, name, from, type)
|
153
|
+
end
|
154
|
+
end
|
162
155
|
|
163
|
-
|
156
|
+
context 'as xml' do
|
164
157
|
|
165
|
-
|
158
|
+
let(:type) { :xml }
|
159
|
+
let(:accept) { :xml }
|
166
160
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
161
|
+
it 'specifies application/xml as the acccept type' do
|
162
|
+
client.send(method, name, from, type)
|
163
|
+
end
|
164
|
+
end
|
171
165
|
|
172
|
-
|
166
|
+
end
|
173
167
|
|
174
|
-
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
end
|
175
172
|
|
176
|
-
let(:type) { :html }
|
177
|
-
let(:accept) { :html }
|
178
173
|
|
179
|
-
|
180
|
-
|
181
|
-
end
|
182
|
-
end
|
174
|
+
Foaas::Client::METHODS_ONE_PARAM.each do |method|
|
175
|
+
describe "##{method}" do
|
183
176
|
|
184
|
-
|
177
|
+
before do
|
178
|
+
RestClient.should_receive(:get).with(url, { accept: accept }).and_return('{ "message" : "", "subtitle" : ""}')
|
179
|
+
end
|
185
180
|
|
186
|
-
|
187
|
-
|
181
|
+
let(:url) { "http://foaas.com/#{method}/#{from}" }
|
182
|
+
let(:from) { 'from' }
|
183
|
+
let(:type) { nil }
|
188
184
|
|
189
|
-
|
190
|
-
client.thing(thing, from, type)
|
191
|
-
end
|
185
|
+
context 'type is' do
|
192
186
|
|
193
|
-
|
194
|
-
client.thing(thing, from, type).should == { 'message' => '', 'subtitle' => ''}
|
195
|
-
end
|
196
|
-
|
197
|
-
end
|
187
|
+
context 'not specified' do
|
198
188
|
|
199
|
-
|
189
|
+
let(:accept) { :json }
|
200
190
|
|
201
|
-
|
202
|
-
|
191
|
+
it 'defaults to JSON' do
|
192
|
+
client.send(method, from, type)
|
193
|
+
end
|
203
194
|
|
204
|
-
|
205
|
-
client.thing(thing, from, type)
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
end
|
195
|
+
end
|
210
196
|
|
211
|
-
|
197
|
+
context 'is specified' do
|
212
198
|
|
213
|
-
|
199
|
+
context 'as HTML' do
|
214
200
|
|
215
|
-
|
201
|
+
let(:type) { :html }
|
202
|
+
let(:accept) { :html }
|
216
203
|
|
217
|
-
|
204
|
+
it 'specifies text/html as the accept type' do
|
205
|
+
client.send(method, from, type)
|
206
|
+
end
|
207
|
+
end
|
218
208
|
|
219
|
-
|
220
|
-
client.respond_to?(sym)
|
221
|
-
end
|
209
|
+
context 'as JSON' do
|
222
210
|
|
223
|
-
|
211
|
+
let(:type) { :json }
|
212
|
+
let(:accept) { :json }
|
224
213
|
|
225
|
-
|
214
|
+
it 'specifies application/json as the accept type' do
|
215
|
+
client.send(method, from, type)
|
216
|
+
end
|
226
217
|
|
227
|
-
|
218
|
+
it 'parses the response into a hash' do
|
219
|
+
client.send(method, from, type).should == { 'message' => '', 'subtitle' => ''}
|
220
|
+
end
|
228
221
|
|
229
|
-
|
222
|
+
end
|
230
223
|
|
231
|
-
|
224
|
+
context 'as text' do
|
232
225
|
|
233
|
-
|
226
|
+
let(:type) { :text }
|
227
|
+
let(:accept) { 'text/plain'}
|
234
228
|
|
235
|
-
|
229
|
+
it 'specifies text/plain as the accept type' do
|
230
|
+
client.send(method, from, type)
|
231
|
+
end
|
232
|
+
end
|
236
233
|
|
237
|
-
|
234
|
+
context 'as xml' do
|
235
|
+
let(:type) { :xml }
|
236
|
+
let(:accept) { :xml }
|
238
237
|
|
239
|
-
|
238
|
+
it 'specifies application/xml as the accept type' do
|
239
|
+
client.send(method, from, type)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
240
243
|
|
241
|
-
|
244
|
+
end
|
245
|
+
|
246
|
+
end
|
247
|
+
end
|
242
248
|
|
243
|
-
|
249
|
+
describe '#thing' do
|
250
|
+
|
251
|
+
before do
|
252
|
+
RestClient.should_receive(:get).with(url, { accept: accept }).and_return('{ "message" : "", "subtitle" : ""}')
|
253
|
+
end
|
254
|
+
|
255
|
+
let(:url) { "http://foaas.com/#{thing}/#{from}" }
|
256
|
+
let(:thing) { 'thing' }
|
257
|
+
let(:from) { 'from' }
|
258
|
+
let(:type) { nil }
|
259
|
+
|
260
|
+
context 'type is' do
|
261
|
+
|
262
|
+
context 'not specified' do
|
263
|
+
|
264
|
+
let(:accept) { :json }
|
265
|
+
|
266
|
+
it 'defaults to JSON' do
|
267
|
+
client.thing(thing, from, type)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
context 'is specified' do
|
272
|
+
|
273
|
+
context 'as HTML' do
|
274
|
+
|
275
|
+
let(:type) { :html }
|
276
|
+
let(:accept) { :html }
|
277
|
+
|
278
|
+
it 'specifies text/html as the accept type' do
|
279
|
+
client.thing(thing, from, type)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
context 'as JSON' do
|
284
|
+
|
285
|
+
let(:type) { :json }
|
286
|
+
let(:accept) { :json }
|
287
|
+
|
288
|
+
it 'specifies application/json as the accept type' do
|
289
|
+
client.thing(thing, from, type)
|
290
|
+
end
|
291
|
+
|
292
|
+
it 'parses the response into a hash' do
|
293
|
+
client.thing(thing, from, type).should == { 'message' => '', 'subtitle' => ''}
|
294
|
+
end
|
295
|
+
|
296
|
+
end
|
297
|
+
|
298
|
+
context 'as text' do
|
299
|
+
|
300
|
+
let(:type) { :text }
|
301
|
+
let(:accept) { 'text/plain' }
|
302
|
+
|
303
|
+
it 'specifies text/plain as the accept type' do
|
304
|
+
client.thing(thing, from, type)
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
context 'as xml' do
|
309
|
+
|
310
|
+
let(:type) { :xml }
|
311
|
+
let(:accept) { :xml }
|
312
|
+
|
313
|
+
it 'specifies application/xml as the accept type' do
|
314
|
+
client.thing(thing, from, type)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
end
|
320
|
+
|
321
|
+
end
|
322
|
+
|
323
|
+
describe '#respond_to?' do
|
324
|
+
|
325
|
+
let(:sym) { nil }
|
326
|
+
|
327
|
+
subject do
|
328
|
+
client.respond_to?(sym)
|
329
|
+
end
|
330
|
+
|
331
|
+
(Foaas::Client::METHODS_ONE_PARAM + Foaas::Client::METHODS_TWO_PARAMS + [:thing]).each do |method|
|
332
|
+
|
333
|
+
context "for :#{method}" do
|
334
|
+
|
335
|
+
let(:sym) { method }
|
336
|
+
|
337
|
+
it { should eq true }
|
338
|
+
|
339
|
+
end
|
340
|
+
|
341
|
+
context 'for non-FOAAS methods' do
|
342
|
+
|
343
|
+
let(:sym) { :not_a_foaas_method }
|
344
|
+
|
345
|
+
it { should eq false }
|
346
|
+
|
347
|
+
end
|
348
|
+
|
349
|
+
end
|
350
|
+
|
351
|
+
end
|
244
352
|
|
245
353
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foaas-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Marsh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -90,7 +90,6 @@ files:
|
|
90
90
|
- .gitignore
|
91
91
|
- .travis.yml
|
92
92
|
- CHANGELOG.md
|
93
|
-
- CHANGELOG.md~
|
94
93
|
- Gemfile
|
95
94
|
- LICENSE
|
96
95
|
- README.md
|
@@ -121,10 +120,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
120
|
version: '0'
|
122
121
|
requirements: []
|
123
122
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
123
|
+
rubygems_version: 2.2.2
|
125
124
|
signing_key:
|
126
125
|
specification_version: 4
|
127
126
|
summary: A client for FOAAS
|
128
127
|
test_files:
|
129
128
|
- spec/foaas-client/client_spec.rb
|
130
129
|
- spec/spec_helper.rb
|
130
|
+
has_rdoc:
|
data/CHANGELOG.md~
DELETED