cowsapi 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0440400cc32f301435994217c362c4638ed4368e
4
+ data.tar.gz: de0836a88867f8fdc00c24ba9cf464c77f35c428
5
+ SHA512:
6
+ metadata.gz: 107b298e87e38ab0d883d0b0471ba04199d0e2481d222ae477842c1d9cdce50b478cfc8b069d09f99fbb90e45346d649af495754ec9c6b082d33542766172987
7
+ data.tar.gz: b5d6e248ddfd886b60ab191a9df5970f1a42beb674e103e4c1132bbd138043c7cda887330623b2eb4739dd050b1684b24643e1a80a5fed6d9df96aec5981eba9
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cowsapi.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 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,63 @@
1
+ # Cowsapi
2
+
3
+ Runs an HTTP API that exposes cowsay operations.
4
+ Make cows say things, just like you always wanted to - over the internets!
5
+
6
+ ## Features
7
+ * Make cows say things!
8
+ * Supports both text and images of cows!
9
+
10
+ ## Installation
11
+ To install cowsapi:
12
+ ```
13
+ gem install cowsapi
14
+ ```
15
+
16
+ ## Usage
17
+ To launch cowsapi:
18
+ ```
19
+ cowsapi
20
+ ```
21
+
22
+ This will launch cowsapi on port 9292.
23
+
24
+ ### API Guide
25
+
26
+ #### List cows:
27
+ ```bash
28
+ curl -O http://localhost
29
+ ```
30
+
31
+ #### Make a cow say stuff:
32
+ ```bash
33
+ curl -O http://localhost/somecow/stuff%20to%20say
34
+ ```
35
+
36
+ #### Get a an image of a cow saying stuff:
37
+ ```bash
38
+ curl -o curl -O http://sheax0r.ca/cow/stuff?format\=png > cowstuff.png
39
+ ```
40
+
41
+ ### Extra stuff
42
+ You can also make your docker-cowsay container run cowsay directly, rather than launching an api, like so:
43
+
44
+ ```
45
+ docker run -t cowsay i can haz cows?
46
+
47
+ _________________
48
+ < i can haz cows? >
49
+ -----------------
50
+ \ ^__^
51
+ \ (oo)\_______
52
+ (__)\ )\/\
53
+ ||----w |
54
+ || ||
55
+ ```
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it ( https://github.com/[my-github-username]/cowsapi/fork )
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'rspec/core/rake_task'
2
+ RSpec::Core::RakeTask.new('spec')
3
+
4
+ task :default => :spec
data/bin/cowsapi ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ Dir.chdir "#{__dir__}/.."
3
+ exec "bundle exec rackup -s thin"
data/config.ru ADDED
@@ -0,0 +1,3 @@
1
+ $: << "{__dir__}/lib"
2
+ require 'cowsapi/app'
3
+ run Cowsapi::App.new
data/cowsapi.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cowsapi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cowsapi"
8
+ spec.version = Cowsapi::VERSION
9
+ spec.authors = ["Michael Shea"]
10
+ spec.email = ["mike.shea@gmail.com"]
11
+ spec.summary = %q{Cowsay API}
12
+ spec.homepage = "https://github.com/sheax0r/cowsapi"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec", "~> 3.1"
23
+ spec.add_dependency 'sinatra', '~> 1.4'
24
+ spec.add_dependency 'thin', '~> 1.6'
25
+ end
@@ -0,0 +1,62 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+ require 'cowsapi'
3
+ require 'cowsapi/cow'
4
+ require 'sinatra'
5
+ require 'shellwords'
6
+
7
+ module Cowsapi
8
+ class App < Sinatra::Base
9
+
10
+ before do
11
+ content_type 'text/plain'
12
+ end
13
+
14
+ get '/' do
15
+ "".tap do |str|
16
+ Cow.all.each{|c| str << "#{c.name}\n"}
17
+ end
18
+ end
19
+
20
+ get '/:name/:say' do
21
+ cow = Cow.get(params[:name])
22
+ convert(cow ? cow.say(params[:say]) : halt(404, "No such cow: #{params[:name]}"), params)
23
+ end
24
+
25
+ get '/fb/:name/:say' do
26
+ content_type 'text/html'
27
+ <<-eos
28
+ <html>
29
+ <body>
30
+ <img style="padding-left:30px" src="#{request.scheme}://#{request.host}/#{params[:name]}/#{params[:say]}?format=png" />
31
+ </body>
32
+ </html>
33
+ eos
34
+ end
35
+
36
+ def convert (string, params)
37
+ format = params[:format]
38
+ if format
39
+ if %w'jpg gif png'.include?(format)
40
+ content_type "image/#{format}"
41
+ f = Tempfile.new('cow')
42
+ begin
43
+ f.write(string)
44
+ f.rewind
45
+ `convert -font Courier #{dimensions(params)} label:@#{f.path} #{format}:-`
46
+ ensure
47
+ f.close
48
+ f.unlink
49
+ end
50
+ end
51
+ else
52
+ string
53
+ end
54
+ end
55
+
56
+ def dimensions(params)
57
+ x = params[:x].nil? ? 320 : params[:x]
58
+ y = params[:y].nil? ? 240 : params[:y]
59
+ "-size #{x}x#{y}"
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,46 @@
1
+ require 'shellwords'
2
+ require 'cowsapi'
3
+
4
+ module Cowsapi
5
+
6
+ class Cow
7
+ class << self
8
+ def all
9
+ puts "getting all cows"
10
+ lines = `cowsay -l`.split("\n")
11
+ [DefaultCow.new].tap do |cows|
12
+ lines[1..-1].each do |line|
13
+ line.split.each do |c|
14
+ cows << Cow.new(c)
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ def get(name)
21
+ all.detect{|cow|
22
+ cow.name == name
23
+ }
24
+ end
25
+ end
26
+
27
+ attr_reader :name
28
+ def initialize(name)
29
+ @name = name
30
+ end
31
+
32
+ def say(string)
33
+ `cowsay -f #{name} #{Shellwords.escape(string)}`
34
+ end
35
+ end
36
+
37
+ class DefaultCow
38
+ def name
39
+ 'cow'
40
+ end
41
+
42
+ def say(string)
43
+ `cowsay #{Shellwords.escape(string)}`
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Cowsapi
2
+ VERSION = "0.0.1"
3
+ end
data/lib/cowsapi.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "cowsapi/version"
2
+
3
+ module Cowsapi
4
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cowsapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Shea
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sinatra
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thin
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.6'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.6'
83
+ description:
84
+ email:
85
+ - mike.shea@gmail.com
86
+ executables:
87
+ - cowsapi
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/cowsapi
97
+ - config.ru
98
+ - cowsapi.gemspec
99
+ - lib/cowsapi.rb
100
+ - lib/cowsapi/app.rb
101
+ - lib/cowsapi/cow.rb
102
+ - lib/cowsapi/version.rb
103
+ homepage: https://github.com/sheax0r/cowsapi
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.2.2
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Cowsay API
127
+ test_files: []