cowsapi 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.components +9 -0
- data/.gitignore +8 -15
- data/Gemfile.lock +114 -0
- data/README.md +11 -3
- data/Rakefile +4 -2
- data/app/app.rb +52 -0
- data/config/apps.rb +36 -0
- data/config/boot.rb +46 -0
- data/config.ru +10 -3
- data/cowsapi.gemspec +2 -0
- data/lib/cowsapi/version.rb +1 -1
- data/public/favicon.ico +0 -0
- metadata +36 -3
- data/lib/cowsapi/app.rb +0 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 914f5c04f36b939776bc742e13f598dcff6cf3b4
|
4
|
+
data.tar.gz: 4d5d3f1e955e89663d0caefbfe93ae6f7cd926bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3caf5c89b7c658bae7fe4967bacfce85b0315397d95d57c6925c05a511b9a2cf513655de4c40b7eee785e19d2c4c445c0cb1794425a1b22b5ce2cebbb26fd856
|
7
|
+
data.tar.gz: db1cea255fb2d8903461edaf56d666b3714f261ee3c44c7c052c6ac3330ece293653ad71163149f65a0af0275de58300e161ea38f4b879e8608323c91b36b970
|
data/.components
ADDED
data/.gitignore
CHANGED
@@ -1,15 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
/
|
5
|
-
/
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
/tmp/
|
10
|
-
*.bundle
|
11
|
-
*.so
|
12
|
-
*.o
|
13
|
-
*.a
|
14
|
-
mkmf.log
|
15
|
-
*.gem
|
1
|
+
.DS_Store
|
2
|
+
log/**/*
|
3
|
+
tmp/**/*
|
4
|
+
vendor/gems/*
|
5
|
+
!vendor/gems/cache/
|
6
|
+
.sass-cache/*
|
7
|
+
db/*.db
|
8
|
+
.*.sw*
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cowsapi (0.0.4)
|
5
|
+
padrino (~> 0.12)
|
6
|
+
sinatra (~> 1.4)
|
7
|
+
slim (~> 2.1.0)
|
8
|
+
thin (~> 1.6)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
activesupport (4.1.8)
|
14
|
+
i18n (~> 0.6, >= 0.6.9)
|
15
|
+
json (~> 1.7, >= 1.7.7)
|
16
|
+
minitest (~> 5.1)
|
17
|
+
thread_safe (~> 0.1)
|
18
|
+
tzinfo (~> 1.1)
|
19
|
+
daemons (1.1.9)
|
20
|
+
diff-lcs (1.2.5)
|
21
|
+
eventmachine (1.0.3)
|
22
|
+
http_router (0.11.1)
|
23
|
+
rack (>= 1.0.0)
|
24
|
+
url_mount (~> 0.2.1)
|
25
|
+
i18n (0.6.11)
|
26
|
+
json (1.8.1)
|
27
|
+
mail (2.5.4)
|
28
|
+
mime-types (~> 1.16)
|
29
|
+
treetop (~> 1.4.8)
|
30
|
+
mime-types (1.25.1)
|
31
|
+
minitest (5.4.3)
|
32
|
+
moneta (0.7.20)
|
33
|
+
padrino (0.12.4)
|
34
|
+
padrino-admin (= 0.12.4)
|
35
|
+
padrino-cache (= 0.12.4)
|
36
|
+
padrino-core (= 0.12.4)
|
37
|
+
padrino-gen (= 0.12.4)
|
38
|
+
padrino-helpers (= 0.12.4)
|
39
|
+
padrino-mailer (= 0.12.4)
|
40
|
+
padrino-support (= 0.12.4)
|
41
|
+
padrino-admin (0.12.4)
|
42
|
+
padrino-core (= 0.12.4)
|
43
|
+
padrino-helpers (= 0.12.4)
|
44
|
+
padrino-cache (0.12.4)
|
45
|
+
moneta (~> 0.7.0)
|
46
|
+
padrino-core (= 0.12.4)
|
47
|
+
padrino-helpers (= 0.12.4)
|
48
|
+
padrino-core (0.12.4)
|
49
|
+
activesupport (>= 3.1)
|
50
|
+
http_router (~> 0.11.0)
|
51
|
+
padrino-support (= 0.12.4)
|
52
|
+
rack-protection (>= 1.5.0)
|
53
|
+
sinatra (~> 1.4.2)
|
54
|
+
thor (~> 0.18)
|
55
|
+
padrino-gen (0.12.4)
|
56
|
+
bundler (~> 1.0)
|
57
|
+
padrino-core (= 0.12.4)
|
58
|
+
padrino-helpers (0.12.4)
|
59
|
+
i18n (~> 0.6, >= 0.6.7)
|
60
|
+
padrino-support (= 0.12.4)
|
61
|
+
tilt (~> 1.4.1)
|
62
|
+
padrino-mailer (0.12.4)
|
63
|
+
mail (~> 2.5.3)
|
64
|
+
padrino-core (= 0.12.4)
|
65
|
+
padrino-support (0.12.4)
|
66
|
+
activesupport (>= 3.1)
|
67
|
+
polyglot (0.3.5)
|
68
|
+
rack (1.5.2)
|
69
|
+
rack-protection (1.5.3)
|
70
|
+
rack
|
71
|
+
rake (10.4.0)
|
72
|
+
rspec (3.1.0)
|
73
|
+
rspec-core (~> 3.1.0)
|
74
|
+
rspec-expectations (~> 3.1.0)
|
75
|
+
rspec-mocks (~> 3.1.0)
|
76
|
+
rspec-core (3.1.7)
|
77
|
+
rspec-support (~> 3.1.0)
|
78
|
+
rspec-expectations (3.1.2)
|
79
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
80
|
+
rspec-support (~> 3.1.0)
|
81
|
+
rspec-mocks (3.1.3)
|
82
|
+
rspec-support (~> 3.1.0)
|
83
|
+
rspec-support (3.1.2)
|
84
|
+
sinatra (1.4.5)
|
85
|
+
rack (~> 1.4)
|
86
|
+
rack-protection (~> 1.4)
|
87
|
+
tilt (~> 1.3, >= 1.3.4)
|
88
|
+
slim (2.1.0)
|
89
|
+
temple (~> 0.6.9)
|
90
|
+
tilt (>= 1.3.3, < 2.1)
|
91
|
+
temple (0.6.10)
|
92
|
+
thin (1.6.3)
|
93
|
+
daemons (~> 1.0, >= 1.0.9)
|
94
|
+
eventmachine (~> 1.0)
|
95
|
+
rack (~> 1.0)
|
96
|
+
thor (0.19.1)
|
97
|
+
thread_safe (0.3.4)
|
98
|
+
tilt (1.4.1)
|
99
|
+
treetop (1.4.15)
|
100
|
+
polyglot
|
101
|
+
polyglot (>= 0.3.1)
|
102
|
+
tzinfo (1.2.2)
|
103
|
+
thread_safe (~> 0.1)
|
104
|
+
url_mount (0.2.1)
|
105
|
+
rack
|
106
|
+
|
107
|
+
PLATFORMS
|
108
|
+
ruby
|
109
|
+
|
110
|
+
DEPENDENCIES
|
111
|
+
bundler (~> 1.7)
|
112
|
+
cowsapi!
|
113
|
+
rake (~> 10.0)
|
114
|
+
rspec (~> 3.1)
|
data/README.md
CHANGED
@@ -7,16 +7,24 @@ Make cows say things, just like you always wanted to - over the internets!
|
|
7
7
|
* Make cows say things!
|
8
8
|
* Supports both text and images of cows!
|
9
9
|
|
10
|
+
## Preqrequisites
|
11
|
+
You need some software installed in order to run cowsapi successfully.
|
12
|
+
Here are instructions for install stuff on OSX:
|
13
|
+
```bash
|
14
|
+
brew install ImageMagick ghostscript
|
15
|
+
|
16
|
+
```
|
17
|
+
|
10
18
|
## Installation
|
11
19
|
To install cowsapi:
|
12
|
-
```
|
20
|
+
```bash
|
13
21
|
gem install cowsapi
|
14
22
|
```
|
15
23
|
|
16
24
|
## Usage
|
17
25
|
To launch cowsapi:
|
18
|
-
```
|
19
|
-
cowsapi
|
26
|
+
```bash
|
27
|
+
port=9292 cowsapi
|
20
28
|
```
|
21
29
|
|
22
30
|
This will launch cowsapi on port 9292.
|
data/Rakefile
CHANGED
data/app/app.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'cowsapi/cow'
|
2
|
+
|
3
|
+
module Cowsapi
|
4
|
+
class App < Padrino::Application
|
5
|
+
register Padrino::Mailer
|
6
|
+
register Padrino::Helpers
|
7
|
+
|
8
|
+
enable :sessions
|
9
|
+
|
10
|
+
get :index do
|
11
|
+
"".tap do |str|
|
12
|
+
Cow.all.each{|c| str << "#{c.name}\n"}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
get :index, :with=> [:name, :say], :provides=> [:html, :txt, :jpg, :png, :gif] do
|
17
|
+
cow = Cow.get(params[:name])
|
18
|
+
convert(cow ? cow.say(params[:say]) : halt(404, "No such cow: #{params[:name]}"), params)
|
19
|
+
end
|
20
|
+
|
21
|
+
def convert (string, params)
|
22
|
+
case content_type
|
23
|
+
when *[:jpg, :gif, :png]
|
24
|
+
f = Tempfile.new('cow')
|
25
|
+
begin
|
26
|
+
f.write(string)
|
27
|
+
f.rewind
|
28
|
+
`convert -font Courier #{dimensions} label:@#{f.path} #{content_type}:-`
|
29
|
+
ensure
|
30
|
+
f.close
|
31
|
+
f.unlink
|
32
|
+
end
|
33
|
+
when :html
|
34
|
+
<<-eos
|
35
|
+
<html>
|
36
|
+
<body>
|
37
|
+
<img style="padding-left:30px" src="#{request.scheme}://#{request.host}/#{params[:name]}/#{params[:say]}.png" />
|
38
|
+
</body>
|
39
|
+
</html>
|
40
|
+
eos
|
41
|
+
else
|
42
|
+
string
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def dimensions
|
47
|
+
x = params[:x].nil? ? 320 : params[:x]
|
48
|
+
y = params[:y].nil? ? 240 : params[:y]
|
49
|
+
"-size #{x}x#{y}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/config/apps.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
##
|
2
|
+
# This file mounts each app in the Padrino project to a specified sub-uri.
|
3
|
+
# You can mount additional applications using any of these commands below:
|
4
|
+
#
|
5
|
+
# Padrino.mount('blog').to('/blog')
|
6
|
+
# Padrino.mount('blog', :app_class => 'BlogApp').to('/blog')
|
7
|
+
# Padrino.mount('blog', :app_file => 'path/to/blog/app.rb').to('/blog')
|
8
|
+
#
|
9
|
+
# You can also map apps to a specified host:
|
10
|
+
#
|
11
|
+
# Padrino.mount('Admin').host('admin.example.org')
|
12
|
+
# Padrino.mount('WebSite').host(/.*\.?example.org/)
|
13
|
+
# Padrino.mount('Foo').to('/foo').host('bar.example.org')
|
14
|
+
#
|
15
|
+
# Note 1: Mounted apps (by default) should be placed into the project root at '/app_name'.
|
16
|
+
# Note 2: If you use the host matching remember to respect the order of the rules.
|
17
|
+
#
|
18
|
+
# By default, this file mounts the primary app which was generated with this project.
|
19
|
+
# However, the mounted app can be modified as needed:
|
20
|
+
#
|
21
|
+
# Padrino.mount('AppName', :app_file => 'path/to/file', :app_class => 'BlogApp').to('/')
|
22
|
+
#
|
23
|
+
|
24
|
+
##
|
25
|
+
# Setup global project settings for your apps. These settings are inherited by every subapp. You can
|
26
|
+
# override these settings in the subapps as needed.
|
27
|
+
#
|
28
|
+
Padrino.configure_apps do
|
29
|
+
# enable :sessions
|
30
|
+
set :session_secret, '8f44d9cd2a5bd39ade0b855df3ae063942850e766d298e9c9245027c1bee5682'
|
31
|
+
set :protection, :except => :path_traversal
|
32
|
+
set :protect_from_csrf, true
|
33
|
+
end
|
34
|
+
|
35
|
+
# Mounts the core application for this project
|
36
|
+
Padrino.mount('Cowsapi::App', :app_file => Padrino.root('app/app.rb')).to('/')
|
data/config/boot.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Defines our constants
|
2
|
+
RACK_ENV = ENV['RACK_ENV'] ||= 'development' unless defined?(RACK_ENV)
|
3
|
+
PADRINO_ROOT = File.expand_path('../..', __FILE__) unless defined?(PADRINO_ROOT)
|
4
|
+
|
5
|
+
# Load our dependencies
|
6
|
+
require 'rubygems' unless defined?(Gem)
|
7
|
+
require 'bundler/setup'
|
8
|
+
Bundler.require(:default, RACK_ENV)
|
9
|
+
|
10
|
+
##
|
11
|
+
# ## Enable devel logging
|
12
|
+
#
|
13
|
+
# Padrino::Logger::Config[:development][:log_level] = :devel
|
14
|
+
# Padrino::Logger::Config[:development][:log_static] = true
|
15
|
+
#
|
16
|
+
# ## Configure your I18n
|
17
|
+
#
|
18
|
+
# I18n.default_locale = :en
|
19
|
+
# I18n.enforce_available_locales = false
|
20
|
+
#
|
21
|
+
# ## Configure your HTML5 data helpers
|
22
|
+
#
|
23
|
+
# Padrino::Helpers::TagHelpers::DATA_ATTRIBUTES.push(:dialog)
|
24
|
+
# text_field :foo, :dialog => true
|
25
|
+
# Generates: <input type="text" data-dialog="true" name="foo" />
|
26
|
+
#
|
27
|
+
# ## Add helpers to mailer
|
28
|
+
#
|
29
|
+
# Mail::Message.class_eval do
|
30
|
+
# include Padrino::Helpers::NumberHelpers
|
31
|
+
# include Padrino::Helpers::TranslationHelpers
|
32
|
+
# end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Add your before (RE)load hooks here
|
36
|
+
#
|
37
|
+
Padrino.before_load do
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Add your after (RE)load hooks here
|
42
|
+
#
|
43
|
+
Padrino.after_load do
|
44
|
+
end
|
45
|
+
|
46
|
+
Padrino.load!
|
data/config.ru
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
-
|
2
|
-
require '
|
3
|
-
|
1
|
+
#!/usr/bin/env rackup
|
2
|
+
require 'padrino'
|
3
|
+
# encoding: utf-8
|
4
|
+
|
5
|
+
# This file can be used to start Padrino,
|
6
|
+
# just execute it from the command line.
|
7
|
+
|
8
|
+
require File.expand_path("../config/boot.rb", __FILE__)
|
9
|
+
|
10
|
+
run Padrino.application
|
data/cowsapi.gemspec
CHANGED
data/lib/cowsapi/version.rb
CHANGED
data/public/favicon.ico
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cowsapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Shea
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.6'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: padrino
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.12'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.12'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: slim
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.1.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.1.0
|
83
111
|
description:
|
84
112
|
email:
|
85
113
|
- mike.shea@gmail.com
|
@@ -88,18 +116,23 @@ executables:
|
|
88
116
|
extensions: []
|
89
117
|
extra_rdoc_files: []
|
90
118
|
files:
|
119
|
+
- ".components"
|
91
120
|
- ".gitignore"
|
92
121
|
- Gemfile
|
122
|
+
- Gemfile.lock
|
93
123
|
- LICENSE.txt
|
94
124
|
- README.md
|
95
125
|
- Rakefile
|
126
|
+
- app/app.rb
|
96
127
|
- bin/cowsapi
|
97
128
|
- config.ru
|
129
|
+
- config/apps.rb
|
130
|
+
- config/boot.rb
|
98
131
|
- cowsapi.gemspec
|
99
132
|
- lib/cowsapi.rb
|
100
|
-
- lib/cowsapi/app.rb
|
101
133
|
- lib/cowsapi/cow.rb
|
102
134
|
- lib/cowsapi/version.rb
|
135
|
+
- public/favicon.ico
|
103
136
|
homepage: https://github.com/sheax0r/cowsapi
|
104
137
|
licenses:
|
105
138
|
- MIT
|
data/lib/cowsapi/app.rb
DELETED
@@ -1,62 +0,0 @@
|
|
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
|