stagehand 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -9
- data/lib/stagehand.rb +16 -7
- data/lib/stagehand/railtie.rb +14 -0
- data/lib/stagehand/version.rb +1 -1
- data/spec/stagehand_spec.rb +7 -6
- metadata +6 -5
data/README.md
CHANGED
@@ -6,14 +6,12 @@ Stagehand is a client-side library for manipulating RESTful resources provided b
|
|
6
6
|
Usage
|
7
7
|
=====
|
8
8
|
|
9
|
-
|
10
|
-
stagehand =
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
})
|
16
|
-
end
|
9
|
+
YourApp::Application.configure do
|
10
|
+
config.stagehand.client_id = 'YOUR_APP_CLIENT_ID',
|
11
|
+
config.stagehand.client_secret = 'YOUR_APP_CLIENT_SECRET',
|
12
|
+
config.stagehand.resource_host = 'YOUR_APP_RESOURCE_HOST',
|
13
|
+
config.stagehand.client_host = 'YOUR_APP_HOST_WITH_PORT'
|
14
|
+
end
|
17
15
|
|
18
16
|
class SessionsController < ApplicationController
|
19
17
|
# stagehand.authorize_url is an OAuth 2.0 url created by the
|
@@ -22,7 +20,7 @@ Usage
|
|
22
20
|
# a callback setting the session[:access_token] and redirects
|
23
21
|
# to the client app's root_url.
|
24
22
|
def new
|
25
|
-
redirect_to
|
23
|
+
redirect_to Stagehand.authorize_url
|
26
24
|
end
|
27
25
|
|
28
26
|
# Destroy the access_token (but leave the OAuth host cookie intact)
|
data/lib/stagehand.rb
CHANGED
@@ -1,16 +1,25 @@
|
|
1
1
|
require 'yajl'
|
2
2
|
require 'stagehand/version'
|
3
|
+
require 'stagehand/railtie' if defined? ::Rails::Railtie
|
4
|
+
|
5
|
+
module Stagehand
|
6
|
+
class Config
|
7
|
+
attr_accessor :client_id, :client_secret, :client_host, :resource_host
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.config
|
11
|
+
@@config ||= Config.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure
|
15
|
+
yield self.config
|
16
|
+
end
|
3
17
|
|
4
|
-
class Stagehand::Client
|
5
18
|
def initialize(attributes)
|
6
19
|
@attributes = attributes
|
7
|
-
@client_id = @attributes[:client_id]
|
8
|
-
@client_secret = @attributes[:client_secret]
|
9
|
-
@resource_host = @attributes[:resource_host]
|
10
|
-
@client_host = @attributes[:client_host]
|
11
20
|
end
|
12
21
|
|
13
|
-
def authorize_url
|
14
|
-
|
22
|
+
def self.authorize_url
|
23
|
+
config.resource_host + "/oauth/authorize?client_id=#{config.client_id}&client_secret=#{config.client_secret}&redirect_uri=#{config.client_host}/callback"
|
15
24
|
end
|
16
25
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
class Stagehand::Railtie < Rails::Railtie
|
4
|
+
config.stagehand = ActiveSupport::OrderedOptions.new
|
5
|
+
|
6
|
+
initializer "staghand.configure" do |app|
|
7
|
+
Stagehand.configure do |config|
|
8
|
+
config.client_id = app.config.stagehand[:client_id]
|
9
|
+
config.client_secret = app.config.stagehand[:client_secret]
|
10
|
+
config.resource_host = app.config.stagehand[:resource_host]
|
11
|
+
config.client_host = app.config.stagehand[:client_host]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/stagehand/version.rb
CHANGED
data/spec/stagehand_spec.rb
CHANGED
@@ -3,12 +3,13 @@ require 'spec_helper'
|
|
3
3
|
describe Stagehand do
|
4
4
|
describe "initialization" do
|
5
5
|
it "creates an OAuth 2.0 authorize url" do
|
6
|
-
Stagehand
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
Stagehand.configure do |config|
|
7
|
+
config.client_id = 'test_app'
|
8
|
+
config.client_secret = 'abcdef123456'
|
9
|
+
config.resource_host = 'http://0.0.0.0:3000'
|
10
|
+
config.client_host = 'http://0.0.0.0:4000'
|
11
|
+
end
|
12
|
+
Stagehand.authorize_url.should == "http://0.0.0.0:3000/oauth/authorize?client_id=test_app&client_secret=abcdef123456&redirect_uri=http://0.0.0.0:4000/callback"
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stagehand
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-10-24 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &74656340 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.7.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *74656340
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: yajl-ruby
|
27
|
-
requirement: &
|
27
|
+
requirement: &74656090 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 1.0.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *74656090
|
36
36
|
description: Client-side library for manipulating RESTful resources provided by Personas,
|
37
37
|
a Rails + Backbone user managment service
|
38
38
|
email:
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- README.md
|
47
47
|
- Rakefile
|
48
48
|
- lib/stagehand.rb
|
49
|
+
- lib/stagehand/railtie.rb
|
49
50
|
- lib/stagehand/version.rb
|
50
51
|
- spec/spec_helper.rb
|
51
52
|
- spec/stagehand_spec.rb
|