virgo-gadgeteer 0.2.2

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/lib/gadgeteer.rb ADDED
@@ -0,0 +1,106 @@
1
+ require 'openssl'
2
+ require 'oauth'
3
+ require 'oauth/consumer'
4
+ require 'oauth/request_proxy/action_controller_request'
5
+ require 'oauth/request_proxy/rack_request'
6
+ # require supported signature methods since they wouldn't be autoloaded
7
+ %w{
8
+ hmac-md5 hmac-rmd160 hmac-sha1
9
+ md5 plaintext rsa-sha1 sha1
10
+ }.each do |method|
11
+ require "oauth/signature/#{method.tr('-', '/')}"
12
+ end
13
+
14
+ module Gadgeteer
15
+ def self.included(base)
16
+ root = defined?(RAILS_ROOT) ? RAILS_ROOT : Sinatra::Application.root
17
+ if base.is_a?(Class)
18
+ base.class_eval do
19
+ @@public_keys = Hash[*Dir[File.join(root, 'config', 'certs', '*.cert')].map {|file| [File.basename(file)[0..-6], File.read(file)]}.flatten]
20
+ @@oauth_secrets = YAML.load_file(File.join(root, 'config', 'oauth_secrets.yml')) rescue {}
21
+ cattr_accessor :public_keys, :oauth_secrets
22
+ end
23
+ end
24
+ if base.respond_to?(:helper_method)
25
+ base.helper_method :open_social, :os_viewer, :os_owner
26
+ base.helper Gadgeteer::ViewHelpers
27
+ else
28
+ base.send :include, Gadgeteer::ViewHelpers
29
+ end
30
+ end
31
+
32
+ class SecretMissingError < StandardError; end
33
+
34
+ module ViewHelpers
35
+ def gadget_content_tag(view = nil, &block)
36
+ content = "\n <![CDATA[\n"
37
+ unless view.nil?
38
+ partial = if defined?(Rails)
39
+ render :partial => "#{view}.html"
40
+ else
41
+ haml view
42
+ end
43
+ partial.strip!.gsub!("\n", "\n ")
44
+ content << " #{partial}\n"
45
+ end
46
+ if block_given?
47
+ content << " "
48
+ block_content = defined?(Rails) ? capture(&block) : capture_haml(&block)
49
+ content << block_content.strip.gsub("\n", "\n ")
50
+ content << "\n"
51
+ end
52
+ content << " ]]>\n"
53
+ %{<Content type="html"#{%{ view="#{view}"} if view}>#{content}</Content>}
54
+ end
55
+ end
56
+
57
+ protected
58
+ def public_key(key)
59
+ @@public_keys[key || :default]
60
+ end
61
+
62
+ def oauth_secret(key)
63
+ @@oauth_secrets[key || :default]
64
+ end
65
+
66
+ def verify_signature!
67
+ secret = if key = params[:xoauth_signature_publickey]
68
+ public_key(key) ||
69
+ raise(SecretMissingError, "Missing public key for #{key}")
70
+ else
71
+ key = params[:oauth_consumer_key]
72
+ oauth_secret(key) ||
73
+ raise(SecretMissingError, "Missing oauth secret for #{key}")
74
+ end
75
+
76
+ signature = OAuth::Signature.build(request) do
77
+ # return the token secret and the consumer secret
78
+ [nil, secret]
79
+ end
80
+ pass = signature.verify
81
+ end
82
+
83
+ def verify_signature
84
+ verify_signature!
85
+ rescue OAuth::Signature::UnknownSignatureMethod, SecretMissingError
86
+ false
87
+ end
88
+
89
+ def open_social
90
+ @_open_social ||= params.inject({}) do |h, (k,v)|
91
+ k =~ /^(open_?social|os)_(.*)$/ ? h.merge($2 => v) : h
92
+ end.with_indifferent_access
93
+ end
94
+
95
+ def os_viewer
96
+ @_os_viewer ||= open_social.inject({}) do |h, (k,v)|
97
+ k =~ /^viewer_(.*)$/ ? h.merge($1 => v) : h
98
+ end.with_indifferent_access
99
+ end
100
+
101
+ def os_owner
102
+ @_os_owner ||= open_social.inject({}) do |h, (k,v)|
103
+ k =~ /^owner_(.*)$/ ? h.merge($1 => v) : h
104
+ end.with_indifferent_access
105
+ end
106
+ end
@@ -0,0 +1,3 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'gadgeteer')
2
+
3
+ Sinatra::Base.send :include, Gadgeteer
data/rails/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'gadgeteer')
2
+
3
+ ActionController::Base.send :include, Gadgeteer
@@ -0,0 +1,16 @@
1
+ %html
2
+ %head
3
+ - %w{opensocial-jquery jquery.livequery jquery.gadgeteer}.each do |jsfile|
4
+ %script{:src => "/javascripts/#{jsfile}.js", :type => "text/javascript"}
5
+ %script{:type => "text/javascript"}
6
+ <% if @options.sinatra %>
7
+ == backendHost = "#{request.scheme}://#{request.host}";
8
+ <% else %>
9
+ == backendHost = "#{request.protocol}#{request.host_with_port}";
10
+ <% end %>
11
+ %script{:src => "/javascripts/<%= @options.singular %>.js", :type => "text/javascript"}
12
+ %body
13
+ .container
14
+ #header
15
+ %h1 <%= @options.title %>
16
+ #page
@@ -0,0 +1,11 @@
1
+ !!! XML
2
+ %Module
3
+ %ModulePrefs{<%= @options.model %>.module_prefs}
4
+ - <%= @options.model %>.requires.each do |r|
5
+ %Require{:feature => r}/
6
+ = gadget_content_tag do
7
+ <% if @options.sinatra %>
8
+ = haml :canvas
9
+ <% else %>
10
+ = render :partial => 'canvas.html.haml'
11
+ <% end %>
@@ -0,0 +1,9 @@
1
+ var <%= @options.model %> = {
2
+ host: backendHost,
3
+
4
+ init: function() {
5
+ // Do your own initialization here
6
+ }
7
+ }
8
+
9
+ $.gadgeteer(<%= @options.model %>.init, {host: <%= @options.model %>.host});
@@ -0,0 +1,7 @@
1
+ require 'ostruct'
2
+
3
+ <% if @options.sinatra %>
4
+ <%= @options.model %> = OpenStruct.new(YAML.load_file(File.join(Sinatra::Application.root, 'config', '<%= @options.singular %>.yml'))[Sinatra::Application.environment.to_s])
5
+ <% else %>
6
+ <%= @options.model %> = OpenStruct.new(YAML.load_file(File.join(RAILS_ROOT, 'config', '<%= @options.singular %>.yml'))[Rails.env])
7
+ <% end %>
@@ -0,0 +1,23 @@
1
+ defaults: &defaults
2
+ module_prefs:
3
+ title: "<%= @options.title %>"
4
+ author: "<%= @options.author %>"
5
+ author_email: "<%= @options.email %>"
6
+ requires:
7
+ - opensocial-0.8
8
+ - dynamic-height
9
+ - settitle
10
+ - views
11
+ - setprefs
12
+
13
+ development:
14
+ <<: *defaults
15
+ appid: 1234567890
16
+
17
+ test:
18
+ <<: *defaults
19
+ appid: 1234567890
20
+
21
+ production:
22
+ <<: *defaults
23
+ appid: 1234567890
@@ -0,0 +1,6 @@
1
+ class <%= @options.plural.capitalize %>Controller < ApplicationController
2
+ def show
3
+ @<%= @options.singular %> = <%= @options.model %>
4
+ respond_to :xml
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class GadgeteerTest < Test::Unit::TestCase
4
+ should "haven't decided yet how to test" do
5
+ assert true
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'mocha'
5
+
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'gadgeteer'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: virgo-gadgeteer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Laszlo Bacsi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-20 00:00:00 -07:00
13
+ default_executable: gadgeteer
14
+ dependencies: []
15
+
16
+ description: Making it easy to develop OpenSocial gadgets with Rails or Sinatra.
17
+ email: bacsi.laszlo@virgo.hu
18
+ executables:
19
+ - gadgeteer
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/gadgeteer.rb
26
+ - lib/sinatra/gadgeteer.rb
27
+ - bin/gadgeteer
28
+ - LICENSE
29
+ - Rakefile
30
+ - README.rdoc
31
+ - VERSION.yml
32
+ - test/gadgeteer_test.rb
33
+ - test/test_helper.rb
34
+ - templates/canvas.haml
35
+ - templates/gadget.haml
36
+ - templates/gadget.js
37
+ - templates/gadget.rb
38
+ - templates/gadget.yml
39
+ - templates/gadgets_controller.rb
40
+ - javascripts/jquery.gadgeteer.js
41
+ - javascripts/jquery.livequery.js
42
+ - javascripts/opensocial-jquery.js
43
+ - rails/init.rb
44
+ has_rdoc: true
45
+ homepage: http://github.com/virgo/gadgeteer
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --inline-source
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.2.0
68
+ signing_key:
69
+ specification_version: 2
70
+ summary: Making it easy to develop OpenSocial gadgets with Rails or Sinatra.
71
+ test_files: []
72
+