smoke-rack 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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ben Schwarz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # smoke-rack
2
+
3
+ Smoke::Rack allows you to expose Smoke sources and transcode them into JSON, XML or YAML.
4
+
5
+ ## What are the benefits?
6
+
7
+ * Pluggable caching, cache remote web services and rely on your own infrastructure
8
+ * Join Smoke sources together, reinterpret them, then offer them as a simple web service
9
+
10
+ Smoke::Rack gives you a bunch of HTML screens (found at `/smoke`) that outline the Smoke sources that are found within your current environment.
11
+ ![Smoke-rack home screen](http://farm3.static.flickr.com/2627/3964835379_5d245a98e2.jpg)
12
+
13
+ From there, you'll be able to see the formats that you can get the stream in, or if they require any additional query strings.
14
+ ![Twitter source details](http://farm3.static.flickr.com/2566/3964835179_f543c25681.jpg)
15
+
16
+
17
+ ## Smoke?
18
+
19
+ Smoke allows you to take single serve sources from around the web. Then it does a bunch of smart stuff like automagically transferring as gzip, request caching and understands the content that it gets back. YQL, Atom / RSS feeds, json and xml are all converted to ruby arrays.
20
+
21
+ Smoke-rack allows you to transcode that information and provide an API like layer of your own.
22
+
23
+
24
+ ## How do I include it in my project?
25
+
26
+ # config.ru
27
+ require 'rubygems'
28
+
29
+ # Ensure your app has some Smoke sources
30
+ require 'your-app'
31
+
32
+ require 'smoke-rack'
33
+ use Smoke::Rack
34
+
35
+ run Sinatra::Application
36
+
37
+
38
+ ## Note on Patches/Pull Requests
39
+
40
+ * Fork the project.
41
+ * Make your feature addition or bug fix.
42
+ * Add tests for it. This is important so I don't break it in a
43
+ future version unintentionally.
44
+ * Commit, do not mess with rakefile, version, or history.
45
+ (if you want to have your own version, that is fine but
46
+ bump version in a commit by itself I can ignore when I pull)
47
+ * Send me a pull request. Bonus points for topic branches.
48
+
49
+ ## Copyright
50
+
51
+ Copyright (c) 2009 Ben Schwarz. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "smoke-rack"
8
+ gem.summary = %Q{Expose Smoke sources and transcode them into JSON, XML or YAML}
9
+ gem.description = %Q{Expose Smoke sources and transcode them into JSON, XML or YAML}
10
+ gem.email = "ben.schwarz@gmail.com"
11
+ gem.homepage = "http://github.com/benschwarz/smoke-rack"
12
+ gem.authors = ["Ben Schwarz"]
13
+ gem.rubyforge_project = "smoke-rack"
14
+ gem.add_development_dependency "rspec"
15
+ gem.add_dependency "smoke", "0.5.16"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ Jeweler::RubyforgeTasks.new do |rubyforge|
20
+ rubyforge.doc_task = "rdoc"
21
+ end
22
+ rescue LoadError
23
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
24
+ end
25
+
26
+ require 'spec/rake/spectask'
27
+ Spec::Rake::SpecTask.new(:spec) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.spec_files = FileList['spec/**/*_spec.rb']
30
+ end
31
+
32
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
33
+ spec.libs << 'lib' << 'spec'
34
+ spec.pattern = 'spec/**/*_spec.rb'
35
+ spec.rcov = true
36
+ end
37
+
38
+ task :spec => :check_dependencies
39
+
40
+ task :default => :spec
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION')
45
+ version = File.read('VERSION')
46
+ else
47
+ version = ""
48
+ end
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "smoke-rack #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/config.ru ADDED
@@ -0,0 +1,11 @@
1
+ # Just here to test easily
2
+
3
+ # Ensure your sources (and smoke) are required before smoke-rack
4
+ require 'examples/smoke-source'
5
+ require 'lib/smoke-rack'
6
+ use Smoke::Rack
7
+
8
+ run Sinatra::Application
9
+ get '/' do
10
+ "XYZ"
11
+ end
@@ -0,0 +1,60 @@
1
+ # Pinched from github.com/benschwarz/benschwarz-site
2
+
3
+ require 'smoke'
4
+ require 'digest/sha1'
5
+
6
+ Smoke.configure do |c|
7
+ c[:cache][:enabled] = true
8
+ c[:cache][:store] = :memory
9
+ c[:cache][:expire_in] = 1800
10
+ end
11
+
12
+ Smoke.yql(:flickr) do
13
+ select :all
14
+ from 'flickr.photos.search'
15
+ where :user_id, "36821533@N00"
16
+ where :tags, "germanforblack-site"
17
+
18
+ path :query, :results, :photo
19
+ end
20
+
21
+ Smoke.data(:twitter) do
22
+ prepare :require => :username do
23
+ url "http://twitter.com/users/show.json?screen_name=#{username}", :format => :json
24
+ end
25
+ end
26
+
27
+ Smoke.feed(:delicious) do
28
+ url "http://feeds.delicious.com/v2/rss/bschwarz?count=5"
29
+ end
30
+
31
+ Smoke.data(:upcoming) do
32
+ url "http://upcoming.yahooapis.com/services/rest/?method=user.getWatchlist&api_key=7c06afe3f8&user_id=908522&show=upcoming&format=json"
33
+ path :rsp, :event
34
+
35
+ emit do
36
+ keep :status, /attend/
37
+ truncate 1
38
+ end
39
+ end
40
+
41
+ Smoke.data(:github) do
42
+ url "http://github.com/api/v2/json/repos/show/benschwarz"
43
+ path :repositories
44
+
45
+ emit do
46
+ sort :watchers
47
+ reverse
48
+ truncate 5
49
+ end
50
+ end
51
+
52
+ Smoke.data(:slideshare) do
53
+ prepare do
54
+ timestamp = Time.now.to_i
55
+ hash = Digest::SHA1.hexdigest("FeXBxg0G#{timestamp}")
56
+ url "http://www.slideshare.net/api/2/get_slideshows_by_user?username_for=benschwarz&api_key=uQqJ57cz&ts=#{timestamp}&hash=#{hash}"
57
+ end
58
+
59
+ path :User, :Slideshow
60
+ end
data/lib/smoke-rack.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'sinatra'
2
+
3
+ module Smoke
4
+ class Rack < Sinatra::Base
5
+ set :public, File.join(File.dirname(__FILE__), '..', 'public')
6
+ set :haml, {:format => :html5, :attr_wrapper => '"'}
7
+ enable :static
8
+
9
+ mime :xml, "application/xml"
10
+ mime :json, "application/json"
11
+ mime :yaml, "application/x-yaml"
12
+
13
+ get '/smoke' do
14
+ @sources = Smoke.active_sources.keys
15
+ haml :index
16
+ end
17
+
18
+ Smoke.active_sources.keys.each do |source|
19
+ get "/smoke/#{source.to_s}" do
20
+ @source = source
21
+ haml :usage
22
+ end
23
+
24
+ get "/smoke/#{source.to_s}.:format" do
25
+ format = params[:format].to_sym
26
+
27
+ content_type format
28
+ Smoke.send(source).output(format)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,24 @@
1
+ body { font-family: Helvetica, Arial; }
2
+ #container { width: 550px; margin: 0 auto; }
3
+
4
+ h1 { font-size: 3em; text-transform: lowercase; margin-bottom: 1.5em; }
5
+ h2 { font-size: 1.3em; }
6
+ h1 + h2 { margin-top : -3em; font-style: italic; font-weight: normal; font-size: 0.9em; color: #999;}
7
+
8
+ header { margin: 4em 0; }
9
+
10
+ p { margin: 1em 0; }
11
+ li { margin: 0.3em 0; }
12
+ pre { display: inline-block; margin: 2em 0; }
13
+ code { font-size: 1em; background-color: #eee; padding: 0.6em; }
14
+ a { color: #666; }
15
+ a.back { margin-left: -10em; margin-top: 1.8em; position: absolute; }
16
+
17
+ footer { clear: left; text-align: right; border-top: 1px solid #ccc; padding-top: 0.5em; margin: 2em 0; }
18
+ footer a { color: #999; font-size: 0.7em; font-style: italic; }
19
+ footer a:hover { color: #666; }
20
+
21
+ #sources { margin-top: 2em; }
22
+ #sources li { font-size: 2em; background-color: #eee; padding: 0.6em; }
23
+ #sources li:hover { background-color: #ccc; }
24
+ #sources li:hover a { color: black;}
@@ -0,0 +1,58 @@
1
+ /* http://meyerweb.com/eric/tools/css/reset/ */
2
+ /* v1.0 | 20080212 */
3
+
4
+ html, body, div, span, applet, object, iframe,
5
+ h1, h2, h3, h4, h5, h6, p, blockquote, pre,
6
+ a, abbr, acronym, address, big, cite, code,
7
+ del, dfn, em, font, img, ins, kbd, q, s, samp,
8
+ small, strike, strong, sub, sup, tt, var,
9
+ b, u, i, center,
10
+ dl, dt, dd, ol, ul, li,
11
+ fieldset, form, label, legend,
12
+ table, caption, tbody, tfoot, thead, tr, th, td,
13
+ nav, aside, figure, header, article {
14
+ margin: 0;
15
+ padding: 0;
16
+ border: 0;
17
+ outline: 0;
18
+ font-size: 100%;
19
+ vertical-align: baseline;
20
+ background: transparent;
21
+ }
22
+ body {
23
+ line-height: 1;
24
+ }
25
+ ol, ul {
26
+ list-style: none;
27
+ }
28
+ blockquote, q {
29
+ quotes: none;
30
+ }
31
+ blockquote:before, blockquote:after,
32
+ q:before, q:after {
33
+ content: '';
34
+ content: none;
35
+ }
36
+
37
+ /* remember to define focus styles! */
38
+ :focus {
39
+ outline: 0;
40
+ }
41
+
42
+ /* remember to highlight inserts somehow! */
43
+ ins {
44
+ text-decoration: none;
45
+ }
46
+ del {
47
+ text-decoration: line-through;
48
+ }
49
+
50
+ /* tables still need 'cellspacing="0"' in the markup */
51
+ table {
52
+ border-collapse: collapse;
53
+ border-spacing: 0;
54
+ }
55
+
56
+
57
+ /* Makes HTML5 structural elements structural */
58
+ article, aside, footer, header, nav, section {display: block;}
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{smoke-rack}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ben Schwarz"]
12
+ s.date = %q{2009-10-21}
13
+ s.description = %q{Expose Smoke sources and transcode them into JSON, XML or YAML}
14
+ s.email = %q{ben.schwarz@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.md",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "config.ru",
27
+ "examples/smoke-source.rb",
28
+ "lib/smoke-rack.rb",
29
+ "public/css/base.css",
30
+ "public/css/reset.css",
31
+ "smoke-rack.gemspec",
32
+ "spec/smoke-rack_spec.rb",
33
+ "spec/spec_helper.rb",
34
+ "spec/support/source.rb",
35
+ "views/index.haml",
36
+ "views/layout.haml",
37
+ "views/usage.haml"
38
+ ]
39
+ s.homepage = %q{http://github.com/benschwarz/smoke-rack}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib"]
42
+ s.rubyforge_project = %q{smoke-rack}
43
+ s.rubygems_version = %q{1.3.5}
44
+ s.summary = %q{Expose Smoke sources and transcode them into JSON, XML or YAML}
45
+ s.test_files = [
46
+ "spec/smoke-rack_spec.rb",
47
+ "spec/spec_helper.rb",
48
+ "spec/support/source.rb",
49
+ "examples/smoke-source.rb"
50
+ ]
51
+
52
+ if s.respond_to? :specification_version then
53
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
57
+ s.add_development_dependency(%q<rspec>, [">= 0"])
58
+ s.add_runtime_dependency(%q<smoke>, ["= 0.5.16"])
59
+ else
60
+ s.add_dependency(%q<rspec>, [">= 0"])
61
+ s.add_dependency(%q<smoke>, ["= 0.5.16"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<rspec>, [">= 0"])
65
+ s.add_dependency(%q<smoke>, ["= 0.5.16"])
66
+ end
67
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "SmokeRack" do
4
+ include Rack::Test::Methods
5
+
6
+ def app
7
+ Smoke::Rack
8
+ end
9
+
10
+ it "renders the index" do
11
+ get '/smoke'
12
+ last_response.should be_ok
13
+ end
14
+
15
+ it "should list the sources" do
16
+ get '/smoke'
17
+ last_response.body.should include "<a href=\"/smoke/github\">github</a>"
18
+ end
19
+
20
+ describe "github source" do
21
+ it "should be okay" do
22
+ get '/smoke/github'
23
+ last_response.should be_ok
24
+ end
25
+
26
+ describe "formats" do
27
+ %w(json yaml xml).each do |format|
28
+ it "should be okay serving #{format}" do
29
+ get "/smoke/github.#{format}"
30
+ last_response.should be_ok
31
+ end
32
+
33
+ it "should serve using the correct content_type" do
34
+ get "/smoke/github.#{format}"
35
+ last_response.content_type.should include(format)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+ require 'rack/test'
7
+
8
+ gem 'smoke', '>= 0.5.16'
9
+ require 'smoke'
10
+ require 'support/source'
11
+ require 'smoke-rack'
12
+
13
+ set :environment, :test
14
+
15
+ Spec::Runner.configure do |config|
16
+
17
+ end
@@ -0,0 +1,16 @@
1
+ Smoke.configure do |c|
2
+ c[:cache][:enabled] = true
3
+ c[:cache][:store] = :memory
4
+ c[:cache][:expire_in] = 1800
5
+ end
6
+
7
+ Smoke.data(:github) do
8
+ url "http://github.com/api/v2/json/repos/show/benschwarz"
9
+ path :repositories
10
+
11
+ emit do
12
+ sort :watchers
13
+ reverse
14
+ truncate 5
15
+ end
16
+ end
data/views/index.haml ADDED
@@ -0,0 +1,18 @@
1
+ %header
2
+ %h1 smoke-rack
3
+ %h2 Put more smoke in the air than the chinese at new years
4
+
5
+ %p Smoke::Rack allows you to expose Smoke sources and transcode them into JSON, XML or YAML.
6
+
7
+ %section#sources
8
+ - if @sources.empty?
9
+ %p
10
+ You don't have any sources specified yet, maybe checkout the
11
+ %a{:href => "http://github.com/benschwarz/smoke"} Smoke readme
12
+ to get started
13
+ - else
14
+ %ul
15
+ - @sources.each do |source|
16
+ %li
17
+ %a{:href => "/smoke/#{source}"}= source
18
+ %h2
data/views/layout.haml ADDED
@@ -0,0 +1,20 @@
1
+ !!!
2
+ %html{:lang => "en"}
3
+ %head
4
+ %meta{"http-equiv" => 'Content-Type', :content => 'text/html; charset=utf-8'}
5
+ %meta{:name => "author", :content => "Ben Schwarz"}
6
+
7
+ /[if IE]
8
+ %script{:src => " http://html5shiv.googlecode.com/svn/trunk/html5.js"}
9
+
10
+ %title Smoke::Rack
11
+ %link{:rel => "stylesheet", :href => "/css/reset.css", :type => "text/css", :media => "screen"}
12
+ %link{:rel => "stylesheet", :href => "/css/base.css", :type => "text/css", :media => "screen"}
13
+
14
+ %body
15
+ %section#container
16
+ = yield
17
+
18
+ %footer
19
+ %a{:href => "http://github.com/benschwarz/smoke-rack", :title => "Smoke::Rack on Github"} Smoke::Rack on Github
20
+
data/views/usage.haml ADDED
@@ -0,0 +1,22 @@
1
+ %header
2
+ %a.back{:href => "/smoke"} &laquo; Back to docs
3
+ %h1= @source
4
+ %h2 Try these neat examples in your console
5
+
6
+ - %w(json yaml xml).each do |format|
7
+ %h2= "In #{format.upcase}"
8
+ %pre
9
+ %code= "curl -i http://#{env["HTTP_HOST"]}/smoke/#{@source}.#{format}"
10
+ - if Smoke.send(@source).requirements.any?
11
+ %h2 Requirements
12
+ %p
13
+ You must set these properties before calling
14
+ %code output.
15
+ This can be done by adding query strings to your get requests.
16
+ - Smoke.send(@source).requirements.each do |requirement|
17
+ %li
18
+ = requirement.to_s
19
+ %pre
20
+ %code= "http://#{env["HTTP_HOST"]}/smoke/#{@source}.(json|yaml|xml)?#{requirement}=string"
21
+
22
+
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smoke-rack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ben Schwarz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-21 00:00:00 +11:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: smoke
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.5.16
34
+ version:
35
+ description: Expose Smoke sources and transcode them into JSON, XML or YAML
36
+ email: ben.schwarz@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.md
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.md
49
+ - Rakefile
50
+ - VERSION
51
+ - config.ru
52
+ - examples/smoke-source.rb
53
+ - lib/smoke-rack.rb
54
+ - public/css/base.css
55
+ - public/css/reset.css
56
+ - smoke-rack.gemspec
57
+ - spec/smoke-rack_spec.rb
58
+ - spec/spec_helper.rb
59
+ - spec/support/source.rb
60
+ - views/index.haml
61
+ - views/layout.haml
62
+ - views/usage.haml
63
+ has_rdoc: true
64
+ homepage: http://github.com/benschwarz/smoke-rack
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options:
69
+ - --charset=UTF-8
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ version:
84
+ requirements: []
85
+
86
+ rubyforge_project: smoke-rack
87
+ rubygems_version: 1.3.5
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Expose Smoke sources and transcode them into JSON, XML or YAML
91
+ test_files:
92
+ - spec/smoke-rack_spec.rb
93
+ - spec/spec_helper.rb
94
+ - spec/support/source.rb
95
+ - examples/smoke-source.rb