foaas-client 0.0.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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in foaas.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,109 @@
1
+
2
+ # Foaas Client
3
+
4
+ [![Build Status](https://travis-ci.org/petedmarsh/foaas-client.png)](https://travis-ci.org/petedmarsh/foaas-client)
5
+ [![Code Climate](https://codeclimate.com/github/petedmarsh/foaas-client.png)](https://codeclimate.com/github/petedmarsh/foaas-client)
6
+
7
+ A client for [FOAAS](http://foaas.com).
8
+
9
+ ## API Version
10
+
11
+ Version `0.0.2` of the FOAAS API is supported.
12
+
13
+ ## Usage
14
+
15
+ ### Basic Example
16
+
17
+ require 'foaas-client'
18
+
19
+ fuck = Foaas::Client.new
20
+ fuck.off('Bob', 'Alice')
21
+ #=> { 'message' => 'Fuck off, Bob.' 'subtitle' => '- Alice'}
22
+
23
+ ### Response Types
24
+
25
+ fuck.off('Bob', 'Alice', :json)
26
+ #=> { 'message' => 'Fuck off, Bob.' 'subtitle' => '- Alice'}
27
+
28
+ fuck.off('Bob', 'Alice', :text)
29
+ #=> 'Fuck off, Bob. - Alice'
30
+
31
+ fuck.off('Bob', 'Alice', :html)
32
+ #=> '<html>...</html>'
33
+
34
+ ### Methods
35
+
36
+ #### Everyone
37
+
38
+ fuck.everyone('Alice')
39
+ #=> { 'message' => 'Everyone can go and fuck off.', 'subtitle' => '- Alice'}
40
+
41
+ #### Everything
42
+
43
+ fuck.everything('Alice')
44
+ #=> { 'message' => 'Fuck everything.', 'subtitle' => '- Alice'}
45
+
46
+ #### Life
47
+
48
+ fuck.donut('Alice')
49
+ #=> { 'message' => 'Fuck my life.', 'subtitle' => '- Alice'}
50
+
51
+ #### Pink
52
+
53
+ fuck.donut('Alice')
54
+ #=> { 'message' => 'Well, Fuck me pink.', 'subtitle' => '- Alice'}
55
+
56
+ #### That
57
+
58
+ fuck.that('Alice')
59
+ #=> { 'message' => 'Fuck that', 'subtitle' => '- Alice'}
60
+
61
+ #### This
62
+
63
+ fuck.this('Alice')
64
+ #=> { 'message' => 'Fuck this.', 'subtitle' => '- Alice'}
65
+
66
+ #### Chainsaw
67
+
68
+ fuck.chainsaw('Bob', 'Alice')
69
+ #=> { 'message' => 'Fuck me gently with a chainsaw, Bob. Do I look like Mother Teresa?', 'subtitle' => '- Alice'}
70
+
71
+ #### Donut
72
+
73
+ fuck.donut('Bob', 'Alice')
74
+ #=> { 'message' => 'Bob, go and take a flying fuck at a rolling donut.', 'subtitle' => '- Alice'}
75
+
76
+ #### King
77
+
78
+ fuck.king('Bob', 'Alice')
79
+ #=> { 'message' => 'Oh fuck off, just really fuck off you total dickface. Christ Bob, you are fucking thick.', 'subtitle' => '- Alice'}
80
+
81
+ #### Linus
82
+
83
+ fuck.linus('Bob', 'Alice')
84
+ #=> { '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'}
85
+
86
+ #### Off
87
+
88
+ fuck.off('Bob', 'Alice')
89
+ #=> { 'message' => 'Fuck off, Bob.', 'subtitle' => '- Alice'}
90
+
91
+ #### Shakespeare
92
+
93
+ fuck.shakespeare('Bob', 'Alice')
94
+ #=> { 'message' => 'Thou clay-brained guts, thou knotty-pated fool, thou whoreson obscene greasy tallow-catch!', 'subtitle' => '- Alice'}
95
+
96
+ #### Thanks
97
+
98
+ fuck.thanks('Bob', 'Alice')
99
+ #=> { 'message' => 'Fuck you very much', 'subtitle' => '- Alice'}
100
+
101
+ #### You
102
+
103
+ fuck.you('Bob', 'Alice')
104
+ #=> { 'message' => 'Fuck you, Bob.', 'subtitle' => '- Alice'}
105
+
106
+ #### Thing
107
+
108
+ fuck.thing('it', 'Alice')
109
+ #=> { 'message' => 'Fuck it.', 'subtitle' => '- Alice'}
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'foaas-client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'foaas-client'
8
+ spec.version = Foaas::VERSION
9
+ spec.authors = ['Peter Marsh']
10
+ spec.email = ['pete.d.marsh@gmail.com']
11
+ spec.description = %q{A client for FOAAS}
12
+ spec.summary = spec.description
13
+ spec.homepage = 'http://github.com/petedmarsh/foaas-client'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'rest-client', '~> 1.6.7'
22
+ spec.add_dependency 'addressable', '~> 2.3.5'
23
+ spec.add_development_dependency 'rspec', '~> 2.12.0'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.3'
26
+ spec.add_development_dependency 'rake', '~> 10.1.0'
27
+ end
@@ -0,0 +1 @@
1
+ require_relative 'foaas-client/client'
@@ -0,0 +1,32 @@
1
+ require 'addressable/template'
2
+ require 'rest-client'
3
+ require 'json'
4
+
5
+ module Foaas
6
+ class Client
7
+
8
+ URL = Addressable::Template.new("http://foaas.com/{method}{/name}/{from}")
9
+
10
+ def method_missing(sym, *args)
11
+ case sym
12
+ when :off, :you, :donut, :shakespeare, :linus, :king, :chainsaw
13
+ make_request(URL.expand(method: sym, name: args[0], from: args[1]), args[2])
14
+ when :this, :everything, :everyone, :pink, :life, :thanks, :flying
15
+ make_request(URL.expand(method: sym, from: args[0]), args[1])
16
+ when :thing
17
+ make_request(URL.expand(method: args[0], from: args[1]), args[2])
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def make_request(url, type)
24
+ type = :json unless type
25
+ type = 'text/plain' if type == :text
26
+ response = RestClient.get url.to_s, { accept: type }
27
+ response = JSON.parse(response) if type == :json
28
+ response
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module Foaas
2
+ VERSION = '0.0.0'
3
+ end
@@ -0,0 +1,203 @@
1
+ require 'spec_helper'
2
+
3
+ require 'foaas-client/client'
4
+
5
+ describe Foaas::Client do
6
+
7
+ let(:client) { Foaas::Client.new }
8
+
9
+ before do
10
+ RestClient.should_receive(:get).with(url, { accept: accept }).and_return('{ "message" : "", "subtitle" : ""}')
11
+ end
12
+
13
+ [:off, :you, :donut, :shakespeare, :linus, :king, :chainsaw].each do |method|
14
+ describe "##{method}" do
15
+
16
+ let(:name) { 'name' }
17
+ let(:from) { 'from' }
18
+ let(:type) { nil }
19
+
20
+ let(:url) { "http://foaas.com/#{method}/#{name}/#{from}" }
21
+
22
+ context 'type is' do
23
+
24
+ context 'not specified' do
25
+
26
+ let(:accept) { :json }
27
+
28
+ it 'defaults to JSON' do
29
+ client.send(method, name, from, type)
30
+ end
31
+
32
+ end
33
+
34
+ context 'is specified' do
35
+
36
+ context 'as HTML' do
37
+
38
+ let(:type) { :html }
39
+ let(:accept) { :html }
40
+
41
+ it 'specifies text/html as the accept type' do
42
+ client.send(method, name, from, type)
43
+ end
44
+ end
45
+
46
+ context 'as JSON' do
47
+
48
+ let(:type) { :json }
49
+ let(:accept) { :json}
50
+
51
+ it 'specifies application/json as the accept type' do
52
+ client.send(method, name, from, type)
53
+ end
54
+
55
+ it 'parses the response into a hash' do
56
+ client.send(method, name, from, type).should == { 'message' => '', 'subtitle' => ''}
57
+ end
58
+
59
+ end
60
+
61
+ context 'as text' do
62
+
63
+ let(:type) { :text }
64
+ let(:accept) { 'text/plain' }
65
+
66
+ it 'specifies application/json as the accept type' do
67
+ client.send(method, name, from, type)
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
75
+ end
76
+ end
77
+
78
+
79
+ [:this, :everything, :everyone, :pink, :life, :thanks, :flying].each do |method|
80
+ describe "##{method}" do
81
+
82
+ let(:url) { "http://foaas.com/#{method}/#{from}" }
83
+ let(:from) { 'from' }
84
+ let(:type) { nil }
85
+
86
+ context 'type is' do
87
+
88
+ context 'not specified' do
89
+
90
+ let(:accept) { :json }
91
+
92
+ it 'defaults to JSON' do
93
+ client.send(method, from, type)
94
+ end
95
+
96
+ end
97
+
98
+ context 'is specified' do
99
+
100
+ context 'as HTML' do
101
+
102
+ let(:type) { :html }
103
+ let(:accept) { :html }
104
+
105
+ it 'specifies text/html as the accept type' do
106
+ client.send(method, from, type)
107
+ end
108
+ end
109
+
110
+ context 'as JSON' do
111
+
112
+ let(:type) { :json }
113
+ let(:accept) { :json }
114
+
115
+ it 'specifies application/json as the accept type' do
116
+ client.send(method, from, type)
117
+ end
118
+
119
+ it 'parses the response into a hash' do
120
+ client.send(method, from, type).should == { 'message' => '', 'subtitle' => ''}
121
+ end
122
+
123
+ end
124
+
125
+ context 'as text' do
126
+
127
+ let(:type) { :text }
128
+ let(:accept) { 'text/plain'}
129
+
130
+ it 'specifies application/json as the accept type' do
131
+ client.send(method, from, type)
132
+ end
133
+ end
134
+
135
+ end
136
+
137
+ end
138
+
139
+ end
140
+ end
141
+
142
+ describe '#thing' do
143
+
144
+ let(:url) { "http://foaas.com/#{thing}/#{from}" }
145
+ let(:thing) { 'thing' }
146
+ let(:from) { 'from' }
147
+ let(:type) { nil }
148
+
149
+ context 'type is' do
150
+
151
+ context 'not specified' do
152
+
153
+ let(:accept) { :json }
154
+
155
+ it 'defaults to JSON' do
156
+ client.thing(thing, from, type)
157
+ end
158
+ end
159
+
160
+ context 'is specified' do
161
+
162
+ context 'as HTML' do
163
+
164
+ let(:type) { :html }
165
+ let(:accept) { :html }
166
+
167
+ it 'specifies text/html as the accept type' do
168
+ client.thing(thing, from, type)
169
+ end
170
+ end
171
+
172
+ context 'as JSON' do
173
+
174
+ let(:type) { :json }
175
+ let(:accept) { :json }
176
+
177
+ it 'specifies application/json as the accept type' do
178
+ client.thing(thing, from, type)
179
+ end
180
+
181
+ it 'parses the response into a hash' do
182
+ client.thing(thing, from, type).should == { 'message' => '', 'subtitle' => ''}
183
+ end
184
+
185
+ end
186
+
187
+ context 'as text' do
188
+
189
+ let(:type) { :text }
190
+ let(:accept) { 'text/plain' }
191
+
192
+ it 'specifies application/json as the accept type' do
193
+ client.thing(thing, from, type)
194
+ end
195
+ end
196
+
197
+ end
198
+
199
+ end
200
+
201
+ end
202
+
203
+ end
File without changes
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foaas-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Peter Marsh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.6.7
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.6.7
30
+ - !ruby/object:Gem::Dependency
31
+ name: addressable
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.3.5
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.3.5
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.12.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.12.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.3'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 10.1.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 10.1.0
94
+ description: A client for FOAAS
95
+ email:
96
+ - pete.d.marsh@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - .travis.yml
103
+ - Gemfile
104
+ - LICENSE
105
+ - README.md
106
+ - Rakefile
107
+ - foaas-client.gemspec
108
+ - lib/foaas-client.rb
109
+ - lib/foaas-client/client.rb
110
+ - lib/foaas-client/version.rb
111
+ - spec/foaas-client/client_spec.rb
112
+ - spec/spec_helper.rb
113
+ homepage: http://github.com/petedmarsh/foaas-client
114
+ licenses:
115
+ - MIT
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ segments:
127
+ - 0
128
+ hash: 1217615916135071898
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ segments:
136
+ - 0
137
+ hash: 1217615916135071898
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 1.8.24
141
+ signing_key:
142
+ specification_version: 3
143
+ summary: A client for FOAAS
144
+ test_files:
145
+ - spec/foaas-client/client_spec.rb
146
+ - spec/spec_helper.rb