foaas-client 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6f403c522cdcffe8b5b575db4ecdeb9799c5841
4
- data.tar.gz: f8acfb17a7d5b7683c0d041437f5642c11b8c21a
3
+ metadata.gz: ecf9e557d80d2f2d2a82db773e35e8bc117f890c
4
+ data.tar.gz: b899311c9c0c914a7e0c3aa10f8d1297c0868926
5
5
  SHA512:
6
- metadata.gz: ee06f9dbd7d1c2eba915bfc48acbae3237654eb29d2f68f7744e890076228826cd1844dc89b938d9436849a802fd1ca4b871d4490f960c97e1f5dd13d3d8d30e
7
- data.tar.gz: 7f24ff69a416d1cb0eac18e445d5742756400d3b49846a38d5448093d844961eeaf46847128b1637a8ef6b38db4f116f0a74bc256a7a77e5f8e1c4758656a3ef
6
+ metadata.gz: 96712fadd99a8d1f6ae6a93880be768e8e424397a2a170bd9099ec729e33c51a658120776454f1adbdaf691a9274bb61db7803fffb99a7b5b6c00cf75e3ac0b2
7
+ data.tar.gz: bb0fecd8cb52e26dc75972d931ae32cf609fe3237f26e06004d98cf8e9010a24e4d0b2887c9ea5e042806eb691e81958ddada6c4688c5720eefbe252d860d510
data/CHANGELOG.md CHANGED
@@ -1,5 +1,51 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.0.0
4
+
5
+ * Fix formatting errors in README (heading level for method names)
6
+ * Add documentation for Flying method to README
7
+ * Fix documentation for Field method (key missing for subtitle)
8
+ * Fix documentation for Because method (missing dash in subtitle value)
9
+ * Alphabetise examples in Response Types section of README
10
+ * Update supported API version in README to `0.1.0`
11
+ * Implement the following FOAAS methods:
12
+ * Bus
13
+ * Bye
14
+ * Diabetes
15
+ * Operations (__Note:__ this is not an insult, it returns the avaialable methods)
16
+ * Version (__Note:__ this is not an insult, it returns the FOAAS version)
17
+ * Xmas
18
+ * Add support for JSONP response type
19
+ * Previously if the type was explicitly given as `:json` the reponse from FOAAS would
20
+ be parsed and returned as a Hash. Now, if no type is specified a request is made to
21
+ FOAAS with `accept/json` as the Accept-Type and the result **is** parsed and returned
22
+ as a Hash but if type __is__ specified as `:json` then the raw JSON will be returned.
23
+ This makes the responses for the various return types consistent. Example:
24
+
25
+ ```ruby
26
+ # Previous behaviour:
27
+
28
+ fuck.because('Alice')
29
+ #=> { 'message' => '...', ... }
30
+
31
+ fuck.because('Alice', :json)
32
+ #=> { 'message' => '...', ... }
33
+
34
+ fuck.because('Alice', :xml)
35
+ #=> '<?xml version="1.0" encoding="UTF-8"?>...'
36
+
37
+ # New behaviour:
38
+
39
+ fuck.because('Alice')
40
+ #=> { 'message' => '...', ... }
41
+
42
+ fuck.because('Alice', :json)
43
+ #=> '{ "message": "...", ... }'
44
+
45
+ fuck.because('Alice', :xml)
46
+ #=> '<?xml version="1.0" encoding="UTF-8"?>...'
47
+ ```
48
+
3
49
  ## v0.2.0
4
50
 
5
51
  * Fix errors in README
data/README.md CHANGED
@@ -7,7 +7,7 @@ A client for [FOAAS](http://foaas.com).
7
7
 
8
8
  ## API Version
9
9
 
10
- Version `0.0.4` of the FOAAS API is supported.
10
+ Version `0.1.0` of the FOAAS API is supported.
11
11
 
12
12
  ## Usage
13
13
 
@@ -23,36 +23,53 @@ fuck.off('Bob', 'Alice')
23
23
  ### Response Types
24
24
 
25
25
  ```ruby
26
+ fuck.off('Bob', 'Alice', :html)
27
+ #=> '<html>...</html>'
28
+
26
29
  fuck.off('Bob', 'Alice', :json)
27
- #=> { 'message' => 'Fuck off, Bob.' 'subtitle' => '- Alice' }
30
+ #=> '{ "message": "Fuck off, Bob.", "subtitle": "- Alice" }'
31
+
32
+ fuck.off('Bob', 'Alice', :jsonp)
33
+ #=> 'fuck && fuck({ "message": "Fuck off, Bob.", "subtitle": "- Alice\ });'
28
34
 
29
35
  fuck.off('Bob', 'Alice', :text)
30
36
  #=> 'Fuck off, Bob. - Alice'
31
37
 
32
- fuck.off('Bob', 'Alice', :html)
33
- #=> '<html>...</html>'
34
-
35
38
  fuck.off('Bob', 'Alice', :xml)
36
- #=> '<?xml version="1.0" encoding="utf-8"?>'
39
+ #=> '<?xml version="1.0" encoding="utf-8"?>...'
37
40
  ```
38
41
 
39
42
  ### Methods
40
43
 
41
- ### Ballmer
44
+ #### Ballmer
42
45
 
43
46
  ```ruby
44
47
  fuck.ballmer('Bob', 'Alice', 'Clara')
45
48
  #=> { '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' }
46
49
  ```
47
50
 
48
- ### Because
51
+ #### Because
49
52
 
50
53
  ```ruby
51
54
  fuck.because('Alice')
52
- #=> { 'message' => 'Why? Because Fuck you, that\'s why.', 'subtitle' => 'Alice' }
55
+ #=> { 'message' => 'Why? Because Fuck you, that\'s why.', 'subtitle' => '- Alice' }
53
56
  ```
54
57
 
55
- ### Can I use?
58
+ #### Bus
59
+
60
+ ```ruby
61
+ fuck.bus('Bob', 'Alice')
62
+ #=> { 'message' => 'Christ on a bendy-bus, Bob, don\'t be such a fucking faff-arse', 'subtitle' => '- Alice' }
63
+ ```
64
+
65
+ #### Bye
66
+
67
+ ```ruby
68
+ fuck.bye('Alice')
69
+ #=> { 'message' => 'Fuckity bye!', 'subtitle' => '- Alice' }
70
+ ```
71
+
72
+ #### Can I use?
56
73
 
57
74
  ```ruby
58
75
  fuck.caniuse('Bob', 'Alice')
@@ -66,13 +83,20 @@ fuck.chainsaw('Bob', 'Alice')
66
83
  #=> { 'message' => 'Fuck me gently with a chainsaw, Bob. Do I look like Mother Teresa?', 'subtitle' => '- Alice' }
67
84
  ```
68
85
 
69
- ### Cool
86
+ #### Cool
70
87
 
71
88
  ```ruby
72
89
  fuck.cool('Alice')
73
90
  #=> { 'message' => 'Cool story, Bro', '- Alice' }
74
91
  ```
75
92
 
93
+ #### Diabetes
94
+
95
+ ```ruby
96
+ fuck.diabetes('Alice')
97
+ #=> { 'message' => 'I\'d love to stop and chat to you but I\'d rather have type 2 diabetes.', 'subtitle' => '- Alice' }
98
+ ```
99
+
76
100
  #### Donut
77
101
 
78
102
  ```ruby
@@ -101,13 +125,19 @@ fuck.fascinating('Alice')
101
125
  #=> { 'message' => 'Fascinating story, in what chapter do you shut the fuck up?', 'subtitle' => '- Alice' }
102
126
  ```
103
127
 
104
- ### Field
128
+ #### Field
105
129
 
106
130
  ```ruby
107
131
  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' }
132
+ #=> { '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.', 'subtitle' => '- Clara' }
109
133
  ```
110
134
 
135
+ #### Flying
136
+
137
+ ```ruby
138
+ fuck.flying('Alice')
139
+ #=> { 'message' => 'I don\'t give a flying fuck.', 'subtitle' => '- Alice' }
140
+
111
141
  #### King
112
142
 
113
143
  ```ruby
@@ -129,14 +159,14 @@ fuck.linus('Bob', 'Alice')
129
159
  #=> { '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' }
130
160
  ```
131
161
 
132
- ### Madison
162
+ #### Madison
133
163
 
134
164
  ```ruby
135
165
  fuck.madison('Bob', 'Alice')
136
166
  #=> { '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
167
  ```
138
168
 
139
- ### Nugget
169
+ #### Nugget
140
170
 
141
171
  ```ruby
142
172
  fuck.nugget('Bob', 'Alice')
@@ -150,7 +180,17 @@ fuck.off('Bob', 'Alice')
150
180
  #=> { 'message' => 'Fuck off, Bob.', 'subtitle' => '- Alice' }
151
181
  ```
152
182
 
153
- ### Outside
183
+ #### Operations
184
+
185
+ __Note:__ This is not an "insult" method, it returns the avialble "insult" operations. Additionally, this method only returns JSON.
186
+
187
+
188
+ ```ruby
189
+ fuck.operations()
190
+ #=> [ { 'name' => 'Ballmer', 'url' => '/ballmer/:name/:company/:from', 'fields' => [ { 'name' => 'Name', 'field' => 'name' }, { 'name' => 'Company', 'field' => 'company' }, { 'name' => 'From', 'field' => 'field'} ] }, ...]
191
+ ```
192
+
193
+ #### Outside
154
194
 
155
195
  ```ruby
156
196
  fuck.outside('Bob', 'Alice')
@@ -199,14 +239,30 @@ fuck.this('Alice')
199
239
  #=> { 'message' => 'Fuck this.', 'subtitle' => '- Alice' }
200
240
  ```
201
241
 
202
- ### What
242
+ #### Version
243
+
244
+ __Note:__ This is not an "insult" method, it returns the version of the service.
245
+
246
+ ```ruby
247
+ fuck.version()
248
+ #=> { 'message' => '0.1.0', 'subtitle' => 'FOAAS' }
249
+ ```
250
+
251
+ #### What
203
252
 
204
253
  ```ruby
205
254
  fuck.what('Alice')
206
255
  #=> { 'message' => 'What the fuck?!', 'subtitle' => '- Alice' }
207
256
  ```
208
257
 
209
- ### Yoda
258
+ #### Xmas
259
+
260
+ ```ruby
261
+ fuck.xmas('Bob', 'Alice')
262
+ #=> { 'message' => 'Merry Fucking Christmsa, Bob', 'subtitle' => '- Alice' }
263
+ ```
264
+
265
+ #### Yoda
210
266
 
211
267
  ```ruby
212
268
  fuck.yoda('Bob', 'Alice')
@@ -7,8 +7,8 @@ module Foaas
7
7
 
8
8
  URL = Addressable::Template.new("http://foaas.com/{method}{/name}/{from}{/other}")
9
9
 
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]
10
+ METHODS_ONE_PARAM = [:because, :bye, :cool, :diabetes, :everyone, :everything, :fascinating, :flying, :life, :pink, :thanks, :this, :what]
11
+ METHODS_TWO_PARAMS = [:bus, :donut, :caniuse, :chainsaw, :king, :linus, :madison, :nugget, :off, :outside, :shakespeare, :you, :xmas, :yoda]
12
12
  METHODS_THREE_PARAMS = [:ballmer, :field]
13
13
 
14
14
  def method_missing(sym, *args, &block)
@@ -25,17 +25,35 @@ module Foaas
25
25
  end
26
26
  end
27
27
 
28
+ def operations
29
+ make_request(URL.expand(method: :operations), nil)
30
+ end
31
+
28
32
  def respond_to?(sym, include_private = false)
29
33
  METHODS_ONE_PARAM.include?(sym) or METHODS_TWO_PARAMS.include?(sym) or sym == :thing or super(sym, include_private)
30
34
  end
31
35
 
36
+ def version(type = nil)
37
+ make_request(URL.expand(method: :version), type)
38
+ end
39
+
32
40
  private
33
41
 
34
42
  def make_request(url, type)
35
- type = :json unless type
36
- type = 'text/plain' if type == :text
37
- response = RestClient.get url.to_s, { accept: type }
38
- response = JSON.parse(response) if type == :json
43
+ url = url.to_s
44
+ accept_type = case type
45
+ when nil
46
+ :json
47
+ when :text
48
+ 'text/plain'
49
+ when :jsonp
50
+ url += '?callback=fuck'
51
+ :json
52
+ else
53
+ type
54
+ end
55
+ response = RestClient.get url, { accept: accept_type }
56
+ response = JSON.parse(response) if type.nil?
39
57
  response
40
58
  end
41
59
 
@@ -1,3 +1,3 @@
1
1
  module Foaas
2
- VERSION = '0.2.0'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -34,6 +34,11 @@ describe Foaas::Client do
34
34
  client.send(method, name, from, other, type)
35
35
  end
36
36
 
37
+
38
+ it 'parses the response into a hash' do
39
+ client.send(method, name, from, other, type).should == { 'message' => '', 'subtitle' => ''}
40
+ end
41
+
37
42
  end
38
43
 
39
44
  context 'is specified' do
@@ -57,8 +62,16 @@ describe Foaas::Client do
57
62
  client.send(method, name, from, other, type)
58
63
  end
59
64
 
60
- it 'parses the response into a hash' do
61
- client.send(method, name, from, other, type).should == { 'message' => '', 'subtitle' => ''}
65
+ end
66
+
67
+ context 'as JSONP' do
68
+
69
+ let(:url) { "http://foaas.com/#{method}/#{name}/#{from}/#{other}?callback=fuck" }
70
+ let(:type) { :jsonp }
71
+ let(:accept) { :json}
72
+
73
+ it 'specifies application/json as the accept type' do
74
+ client.send(method, name, from, other, type)
62
75
  end
63
76
 
64
77
  end
@@ -114,6 +127,10 @@ describe Foaas::Client do
114
127
  client.send(method, name, from, type)
115
128
  end
116
129
 
130
+ it 'parses the response into a hash' do
131
+ client.send(method, name, from, type).should == { 'message' => '', 'subtitle' => ''}
132
+ end
133
+
117
134
  end
118
135
 
119
136
  context 'is specified' do
@@ -137,8 +154,16 @@ describe Foaas::Client do
137
154
  client.send(method, name, from, type)
138
155
  end
139
156
 
140
- it 'parses the response into a hash' do
141
- client.send(method, name, from, type).should == { 'message' => '', 'subtitle' => ''}
157
+ end
158
+
159
+ context 'as JSONP' do
160
+
161
+ let(:url) { "http://foaas.com/#{method}/#{name}/#{from}?callback=fuck" }
162
+ let(:type) { :jsonp }
163
+ let(:accept) { :json}
164
+
165
+ it 'specifies application/json as the accept type' do
166
+ client.send(method, name, from, type)
142
167
  end
143
168
 
144
169
  end
@@ -192,6 +217,10 @@ describe Foaas::Client do
192
217
  client.send(method, from, type)
193
218
  end
194
219
 
220
+ it 'parses the response into a hash' do
221
+ client.send(method, from, type).should == { 'message' => '', 'subtitle' => ''}
222
+ end
223
+
195
224
  end
196
225
 
197
226
  context 'is specified' do
@@ -215,8 +244,16 @@ describe Foaas::Client do
215
244
  client.send(method, from, type)
216
245
  end
217
246
 
218
- it 'parses the response into a hash' do
219
- client.send(method, from, type).should == { 'message' => '', 'subtitle' => ''}
247
+ end
248
+
249
+ context 'as JSONP' do
250
+
251
+ let(:url) { "http://foaas.com/#{method}/#{from}?callback=fuck" }
252
+ let(:type) { :jsonp }
253
+ let(:accept) { :json}
254
+
255
+ it 'specifies application/json as the accept type' do
256
+ client.send(method, from, type)
220
257
  end
221
258
 
222
259
  end
@@ -266,6 +303,11 @@ describe Foaas::Client do
266
303
  it 'defaults to JSON' do
267
304
  client.thing(thing, from, type)
268
305
  end
306
+
307
+ it 'parses the response into a hash' do
308
+ client.thing(thing, from, type).should == { 'message' => '', 'subtitle' => ''}
309
+ end
310
+
269
311
  end
270
312
 
271
313
  context 'is specified' do
@@ -289,10 +331,18 @@ describe Foaas::Client do
289
331
  client.thing(thing, from, type)
290
332
  end
291
333
 
292
- it 'parses the response into a hash' do
293
- client.thing(thing, from, type).should == { 'message' => '', 'subtitle' => ''}
334
+ end
335
+
336
+ context 'as JSONP' do
337
+
338
+ let(:url) { "http://foaas.com/#{thing}/#{from}?callback=fuck" }
339
+ let(:type) { :jsonp }
340
+ let(:accept) { :json}
341
+
342
+ it 'specifies application/json as the accept type' do
343
+ client.thing(thing, from, type)
294
344
  end
295
-
345
+
296
346
  end
297
347
 
298
348
  context 'as text' do
@@ -350,4 +400,102 @@ describe Foaas::Client do
350
400
 
351
401
  end
352
402
 
403
+ describe '#operations' do
404
+
405
+ let(:url) { "http://foaas.com/operations/" }
406
+ let(:accept) { :json }
407
+ let(:response) { '[]' }
408
+
409
+ it 'requests the operations from FOAAS' do
410
+ RestClient.should_receive(:get).with(url, { accept: accept }).and_return(response)
411
+ result = client.operations()
412
+ result.should eq JSON.parse(response)
413
+ end
414
+ end
415
+
416
+ describe '#version' do
417
+
418
+ before do
419
+ RestClient.should_receive(:get).with(url, { accept: accept }).and_return('{ "message" : "", "subtitle" : ""}')
420
+ end
421
+
422
+ let(:url) { "http://foaas.com/#{version}/" }
423
+ let(:version) { 'version' }
424
+ let(:type) { nil }
425
+
426
+ context 'type is' do
427
+
428
+ context 'not specified' do
429
+
430
+ let(:accept) { :json }
431
+
432
+ it 'defaults to JSON' do
433
+ client.version()
434
+ end
435
+
436
+ it 'parses the response into a hash' do
437
+ client.version().should == { 'message' => '', 'subtitle' => ''}
438
+ end
439
+
440
+ end
441
+
442
+ context 'is specified' do
443
+
444
+ context 'as HTML' do
445
+
446
+ let(:type) { :html }
447
+ let(:accept) { :html }
448
+
449
+ it 'specifies text/html as the accept type' do
450
+ client.version(type)
451
+ end
452
+ end
453
+
454
+ context 'as JSON' do
455
+
456
+ let(:type) { :json }
457
+ let(:accept) { :json }
458
+
459
+ it 'specifies application/json as the accept type' do
460
+ client.version(type)
461
+ end
462
+
463
+ end
464
+
465
+ context 'as JSONP' do
466
+
467
+ let(:url) { "http://foaas.com/#{version}/?callback=fuck" }
468
+ let(:type) { :jsonp }
469
+ let(:accept) { :json}
470
+
471
+ it 'specifies application/json as the accept type' do
472
+ client.version(type)
473
+ end
474
+
475
+ end
476
+
477
+ context 'as text' do
478
+
479
+ let(:type) { :text }
480
+ let(:accept) { 'text/plain' }
481
+
482
+ it 'specifies text/plain as the accept type' do
483
+ client.version(type)
484
+ end
485
+ end
486
+
487
+ context 'as xml' do
488
+
489
+ let(:type) { :xml }
490
+ let(:accept) { :xml }
491
+
492
+ it 'specifies application/xml as the accept type' do
493
+ client.version(type)
494
+ end
495
+ end
496
+ end
497
+
498
+ end
499
+ end
500
+
353
501
  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.2.0
4
+ version: 1.0.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: 2014-10-15 00:00:00.000000000 Z
11
+ date: 2015-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -127,4 +127,3 @@ summary: A client for FOAAS
127
127
  test_files:
128
128
  - spec/foaas-client/client_spec.rb
129
129
  - spec/spec_helper.rb
130
- has_rdoc: