drogus-gadgeteer 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -0
- data/README.rdoc +49 -0
- data/Rakefile +42 -0
- data/VERSION.yml +4 -0
- data/bin/gadgeteer +229 -0
- data/javascripts/jquery.form.js +643 -0
- data/javascripts/jquery.gadgeteer.js +372 -0
- data/javascripts/jquery.livequery.js +226 -0
- data/javascripts/opensocial-jquery.js +5588 -0
- data/lib/gadgeteer.rb +107 -0
- data/lib/sinatra/gadgeteer.rb +3 -0
- data/rails/init.rb +3 -0
- data/templates/canvas.haml +24 -0
- data/templates/gadget.haml +11 -0
- data/templates/gadget.js +9 -0
- data/templates/gadget.rb +7 -0
- data/templates/gadget.yml +24 -0
- data/templates/gadgets_controller.rb +6 -0
- data/test/gadgeteer_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +82 -0
data/lib/gadgeteer.rb
ADDED
@@ -0,0 +1,107 @@
|
|
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) ? 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
|
+
class VerificationFailedError < StandardError; end
|
34
|
+
|
35
|
+
module ViewHelpers
|
36
|
+
def gadget_content_tag(view = nil, &block)
|
37
|
+
content = "\n <![CDATA[\n"
|
38
|
+
unless view.nil?
|
39
|
+
partial = if defined?(Rails)
|
40
|
+
render :partial => "#{view}.html"
|
41
|
+
else
|
42
|
+
haml view
|
43
|
+
end
|
44
|
+
partial.strip!.gsub!("\n", "\n ")
|
45
|
+
content << " #{partial}\n"
|
46
|
+
end
|
47
|
+
if block_given?
|
48
|
+
content << " "
|
49
|
+
block_content = defined?(Rails) ? capture(&block) : capture_haml(&block)
|
50
|
+
content << block_content.strip.gsub("\n", "\n ")
|
51
|
+
content << "\n"
|
52
|
+
end
|
53
|
+
content << " ]]>\n"
|
54
|
+
%{<Content type="html"#{%{ view="#{view}"} if view}>#{content}</Content>}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
protected
|
59
|
+
def public_key(key)
|
60
|
+
self.class.public_keys[key || :default]
|
61
|
+
end
|
62
|
+
|
63
|
+
def oauth_secret(key)
|
64
|
+
self.class.oauth_secrets[key || :default]
|
65
|
+
end
|
66
|
+
|
67
|
+
def verify_signature!
|
68
|
+
secret = if key = params[:xoauth_signature_publickey]
|
69
|
+
public_key(key) ||
|
70
|
+
raise(SecretMissingError, "Missing public key for #{key}")
|
71
|
+
else
|
72
|
+
key = params[:oauth_consumer_key]
|
73
|
+
oauth_secret(key) ||
|
74
|
+
raise(SecretMissingError, "Missing oauth secret for #{key}")
|
75
|
+
end
|
76
|
+
|
77
|
+
signature = OAuth::Signature.build(request) do
|
78
|
+
# return the token secret and the consumer secret
|
79
|
+
[nil, secret]
|
80
|
+
end
|
81
|
+
signature.verify || raise(VerificationFailedError, "Signature verification failed")
|
82
|
+
end
|
83
|
+
|
84
|
+
def verify_signature
|
85
|
+
verify_signature!
|
86
|
+
rescue OAuth::Signature::UnknownSignatureMethod, SecretMissingError, VerificationFailedError
|
87
|
+
false
|
88
|
+
end
|
89
|
+
|
90
|
+
def open_social
|
91
|
+
@_open_social ||= params.inject({}) do |h, (k,v)|
|
92
|
+
k =~ /^(open_?social|os)_(.*)$/ ? h.merge($2 => v) : h
|
93
|
+
end.with_indifferent_access
|
94
|
+
end
|
95
|
+
|
96
|
+
def os_viewer
|
97
|
+
@_os_viewer ||= open_social.inject({}) do |h, (k,v)|
|
98
|
+
k =~ /^viewer_(.*)$/ ? h.merge($1 => v) : h
|
99
|
+
end.with_indifferent_access
|
100
|
+
end
|
101
|
+
|
102
|
+
def os_owner
|
103
|
+
@_os_owner ||= open_social.inject({}) do |h, (k,v)|
|
104
|
+
k =~ /^owner_(.*)$/ ? h.merge($1 => v) : h
|
105
|
+
end.with_indifferent_access
|
106
|
+
end
|
107
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
- backend_host = "#{request.scheme}://#{request.host}"
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
- %w{opensocial-jquery jquery.livequery jquery.form jquery.gadgeteer}.each do |jsfile|
|
5
|
+
%script(src="/javascripts/#{jsfile}.js" type="text/javascript")
|
6
|
+
%script(type="text/javascript")
|
7
|
+
== backendHost = "#{backend_host}";
|
8
|
+
%script(src="/javascripts/gadget.js" type="text/javascript")
|
9
|
+
%script(src="/javascripts/<%= @options.singular %>.js"
|
10
|
+
type="text/javascript")
|
11
|
+
|
12
|
+
%script(type="text/os-data"
|
13
|
+
xmlns:os="http://ns.opensocial.org/2008/markup")
|
14
|
+
%os:OwnerRequest(key="owner")
|
15
|
+
%os:ViewerRequest(key="viewer")
|
16
|
+
%os:PersonAppDataRequest(key="ownerData" method="appdata.get"
|
17
|
+
userId="@owner" appId="@app")
|
18
|
+
%os:PersonAppDataRequest(key="viewerData" method="appdata.get"
|
19
|
+
userId="@viewer" appId="@app")
|
20
|
+
%body
|
21
|
+
.container
|
22
|
+
#header
|
23
|
+
%h1 <%= @options.title %>
|
24
|
+
#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 %>
|
data/templates/gadget.js
ADDED
data/templates/gadget.rb
ADDED
@@ -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,24 @@
|
|
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
|
+
- opensocial-data
|
9
|
+
- opensocial-templates
|
10
|
+
- dynamic-height
|
11
|
+
- settitle
|
12
|
+
- views
|
13
|
+
|
14
|
+
development:
|
15
|
+
<<: *defaults
|
16
|
+
appid: 1234567890
|
17
|
+
|
18
|
+
test:
|
19
|
+
<<: *defaults
|
20
|
+
appid: 1234567890
|
21
|
+
|
22
|
+
production:
|
23
|
+
<<: *defaults
|
24
|
+
appid: 1234567890
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: drogus-gadgeteer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Laszlo Bacsi
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2009-09-17 00:00:00 +02:00
|
18
|
+
default_executable: gadgeteer
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Making it easy to develop OpenSocial gadgets with Rails or Sinatra.
|
22
|
+
email: bacsi.laszlo@virgo.hu
|
23
|
+
executables:
|
24
|
+
- gadgeteer
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/gadgeteer.rb
|
31
|
+
- lib/sinatra/gadgeteer.rb
|
32
|
+
- bin/gadgeteer
|
33
|
+
- LICENSE
|
34
|
+
- Rakefile
|
35
|
+
- README.rdoc
|
36
|
+
- VERSION.yml
|
37
|
+
- test/gadgeteer_test.rb
|
38
|
+
- test/test_helper.rb
|
39
|
+
- templates/canvas.haml
|
40
|
+
- templates/gadget.haml
|
41
|
+
- templates/gadget.js
|
42
|
+
- templates/gadget.rb
|
43
|
+
- templates/gadget.yml
|
44
|
+
- templates/gadgets_controller.rb
|
45
|
+
- javascripts/jquery.form.js
|
46
|
+
- javascripts/jquery.gadgeteer.js
|
47
|
+
- javascripts/jquery.livequery.js
|
48
|
+
- javascripts/opensocial-jquery.js
|
49
|
+
- rails/init.rb
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://github.com/virgo/gadgeteer
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options:
|
56
|
+
- --inline-source
|
57
|
+
- --charset=UTF-8
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.3.6
|
78
|
+
signing_key:
|
79
|
+
specification_version: 2
|
80
|
+
summary: Making it easy to develop OpenSocial gadgets with Rails or Sinatra.
|
81
|
+
test_files: []
|
82
|
+
|