stackmob 0.0.0
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 +5 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +175 -0
- data/README.md +210 -0
- data/Rakefile +59 -0
- data/VERSION +1 -0
- data/lib/stackmob.rb +67 -0
- data/lib/stackmob/client.rb +90 -0
- data/lib/stackmob/data_store.rb +74 -0
- data/lib/stackmob/deployer.rb +37 -0
- data/lib/stackmob/helpers.rb +63 -0
- data/lib/stackmob/push.rb +63 -0
- data/lib/stackmob/rack/simple_oauth_provider.rb +59 -0
- data/lib/stackmob/rails.rb +15 -0
- data/lib/stackmob/railtie.rb +38 -0
- data/lib/stackmob/sinatra.rb +5 -0
- data/lib/stackmob/tasks.rb +40 -0
- data/stackmob.gemspec +99 -0
- data/test/helper.rb +22 -0
- data/test/integration/test_client.rb +45 -0
- data/test/integration/test_data_store.rb +31 -0
- data/test/integration/test_deployer.rb +23 -0
- data/test/integration/test_push.rb +24 -0
- data/test/integration_helper.rb +46 -0
- data/test/unit/stackmob/rack/test_simple_oauth_provider.rb +52 -0
- data/test/unit/stackmob/test_client.rb +105 -0
- data/test/unit/stackmob/test_data_store.rb +83 -0
- data/test/unit/stackmob/test_deployer.rb +21 -0
- data/test/unit/stackmob/test_push.rb +133 -0
- metadata +258 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
# Copyright 2011 StackMob
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'oauth'
|
16
|
+
require 'oauth/request_proxy/rack_request'
|
17
|
+
|
18
|
+
module StackMob
|
19
|
+
module Rack
|
20
|
+
class SimpleOAuthProvider
|
21
|
+
|
22
|
+
def initialize(app)
|
23
|
+
@app = app
|
24
|
+
end
|
25
|
+
|
26
|
+
def call(env)
|
27
|
+
request = ::Rack::Request.new(env)
|
28
|
+
signature = OAuth::Signature.build(request, :token_secret => "", :consumer_secret => StackMob.secret)
|
29
|
+
if signature.verify
|
30
|
+
authorized(env)
|
31
|
+
else
|
32
|
+
auth_failed(env)
|
33
|
+
end
|
34
|
+
rescue OAuth::Signature::UnknownSignatureMethod
|
35
|
+
auth_failed(env)
|
36
|
+
end
|
37
|
+
|
38
|
+
def authorized(env)
|
39
|
+
@app.call(env)
|
40
|
+
end
|
41
|
+
private :authorized
|
42
|
+
|
43
|
+
def auth_failed(env)
|
44
|
+
if pass_through?
|
45
|
+
authorized(env)
|
46
|
+
else
|
47
|
+
[401, {}, "Not Authorized\n"]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
private :auth_failed
|
51
|
+
|
52
|
+
def pass_through?
|
53
|
+
!StackMob.is_production? && StackMob.config['development']['no_oauth']
|
54
|
+
end
|
55
|
+
private :pass_through?
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Copyright 2011 StackMob
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'stackmob/railtie' if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Copyright 2011 StackMob
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'stackmob'
|
16
|
+
require 'rails'
|
17
|
+
|
18
|
+
module StackMob
|
19
|
+
class Railtie < Rails::Railtie
|
20
|
+
|
21
|
+
rake_tasks do
|
22
|
+
load "stackmob/tasks.rb"
|
23
|
+
end
|
24
|
+
|
25
|
+
initializer "warn of missing config file" do
|
26
|
+
config.after_initialize do
|
27
|
+
unless Rails.root.join("config", "stackmob.yml").file?
|
28
|
+
puts "\nStackmob Config (config/stackmob.yml) not found\n"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
initializer "setup middleware" do |app|
|
34
|
+
app.config.middleware.use StackMob::Rack::SimpleOAuthProvider
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright 2011 StackMob
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'stackmob/deployer'
|
16
|
+
|
17
|
+
namespace :stackmob do
|
18
|
+
|
19
|
+
desc "Notify StackMob of a New Deploy"
|
20
|
+
task :deploy do
|
21
|
+
|
22
|
+
app_name = StackMob.config['heroku_app_name']
|
23
|
+
exit("No Heroku App Name Found in StackMob Config") if app_name.blank?
|
24
|
+
exit("No Client Name Found in StackMob Config") if StackMob.client_name.blank?
|
25
|
+
|
26
|
+
hostname = "#{app_name}.herokuapp.com"
|
27
|
+
client = StackMob::Client.new("http://#{StackMob.client_name}.mob2.stackmob.com", StackMob.app_name, StackMob::SANDBOX, StackMob.config['development']['key'], StackMob.config['development']['key'])
|
28
|
+
deployer = StackMob::Deployer.new(client)
|
29
|
+
|
30
|
+
begin
|
31
|
+
deployer.register(hostname)
|
32
|
+
|
33
|
+
puts "Registered"
|
34
|
+
puts deployer.fetch
|
35
|
+
rescue StackMob::Client::RequestError
|
36
|
+
puts "Failed to register application. Unable to Communicate with stackmob.com or Authenticate. Please check your keys in config/stackmob.yml and try again"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/stackmob.gemspec
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
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{stackmob}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{StackMob}]
|
12
|
+
s.date = %q{2011-08-24}
|
13
|
+
s.description = %q{Support Gem for StackMob Heroku Add-On}
|
14
|
+
s.email = %q{jordan@stackmob.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/stackmob.rb",
|
28
|
+
"lib/stackmob/client.rb",
|
29
|
+
"lib/stackmob/data_store.rb",
|
30
|
+
"lib/stackmob/deployer.rb",
|
31
|
+
"lib/stackmob/helpers.rb",
|
32
|
+
"lib/stackmob/push.rb",
|
33
|
+
"lib/stackmob/rack/simple_oauth_provider.rb",
|
34
|
+
"lib/stackmob/rails.rb",
|
35
|
+
"lib/stackmob/railtie.rb",
|
36
|
+
"lib/stackmob/sinatra.rb",
|
37
|
+
"lib/stackmob/tasks.rb",
|
38
|
+
"stackmob.gemspec",
|
39
|
+
"test/helper.rb",
|
40
|
+
"test/integration/test_client.rb",
|
41
|
+
"test/integration/test_data_store.rb",
|
42
|
+
"test/integration/test_deployer.rb",
|
43
|
+
"test/integration/test_push.rb",
|
44
|
+
"test/integration_helper.rb",
|
45
|
+
"test/unit/stackmob/rack/test_simple_oauth_provider.rb",
|
46
|
+
"test/unit/stackmob/test_client.rb",
|
47
|
+
"test/unit/stackmob/test_data_store.rb",
|
48
|
+
"test/unit/stackmob/test_deployer.rb",
|
49
|
+
"test/unit/stackmob/test_push.rb"
|
50
|
+
]
|
51
|
+
s.homepage = %q{http://github.com/stackmob/stackmob-ruby}
|
52
|
+
s.licenses = [%q{MIT}]
|
53
|
+
s.require_paths = [%q{lib}]
|
54
|
+
s.rubygems_version = %q{1.8.6}
|
55
|
+
s.summary = %q{Support Gem for StackMob Heroku Add-On}
|
56
|
+
|
57
|
+
if s.respond_to? :specification_version then
|
58
|
+
s.specification_version = 3
|
59
|
+
|
60
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
61
|
+
s.add_runtime_dependency(%q<oauth>, ["~> 0.4.5"])
|
62
|
+
s.add_runtime_dependency(%q<yajl-ruby>, ["~> 0.8.2"])
|
63
|
+
s.add_development_dependency(%q<minitest>, [">= 0"])
|
64
|
+
s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
|
65
|
+
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
66
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
67
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
68
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
69
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
70
|
+
s.add_development_dependency(%q<rack-test>, [">= 0"])
|
71
|
+
s.add_development_dependency(%q<bluecloth>, [">= 0"])
|
72
|
+
else
|
73
|
+
s.add_dependency(%q<oauth>, ["~> 0.4.5"])
|
74
|
+
s.add_dependency(%q<yajl-ruby>, ["~> 0.8.2"])
|
75
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
76
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
77
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
78
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
79
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
80
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
81
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
82
|
+
s.add_dependency(%q<rack-test>, [">= 0"])
|
83
|
+
s.add_dependency(%q<bluecloth>, [">= 0"])
|
84
|
+
end
|
85
|
+
else
|
86
|
+
s.add_dependency(%q<oauth>, ["~> 0.4.5"])
|
87
|
+
s.add_dependency(%q<yajl-ruby>, ["~> 0.8.2"])
|
88
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
89
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
90
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
91
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
92
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
93
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
94
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
95
|
+
s.add_dependency(%q<rack-test>, [">= 0"])
|
96
|
+
s.add_dependency(%q<bluecloth>, [">= 0"])
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'minitest/unit'
|
11
|
+
require 'mocha'
|
12
|
+
require 'yajl'
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
+
require 'stackmob'
|
17
|
+
require 'stackmob/deployer' # include deployer explicitly for testing purposes since its not required by default
|
18
|
+
|
19
|
+
class MiniTest::Unit::TestCase
|
20
|
+
end
|
21
|
+
|
22
|
+
MiniTest::Unit.autorun
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'integration_helper'
|
2
|
+
|
3
|
+
# this test suite assumes that the Sandbox API
|
4
|
+
# deployed at ENV['STACKMOB_TEST_URL'] has an object
|
5
|
+
# model created of type "user", with a single string field
|
6
|
+
# "name". The application name must be "test"
|
7
|
+
|
8
|
+
class ClientIntegrationTest < StackMobIntegrationTest
|
9
|
+
|
10
|
+
def setup
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_valid_get_path
|
15
|
+
api_result_hash = valid_client.request(:get, :api, "/listapi")
|
16
|
+
assert api_result_hash.has_key?("user")
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_get_path_without_prepending_slash
|
20
|
+
res = valid_client.request(:get, :api, "listapi")
|
21
|
+
assert res.has_key?("user")
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_invalid_get_path_raises_error
|
25
|
+
assert_raises StackMob::Client::RequestError do
|
26
|
+
valid_client.request(:get, :api, "/dne")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_user_object_lifecycle
|
31
|
+
username = "123"
|
32
|
+
name = "StackMob Test"
|
33
|
+
|
34
|
+
valid_client.request(:delete, :api, "/user", :username => username) # delete the object in case it exists already
|
35
|
+
|
36
|
+
valid_client.request(:post, :api, "/user", :username => username, :name => name)
|
37
|
+
|
38
|
+
assert_equal name, valid_client.request(:get, :api, "/user", :username => username).first['name']
|
39
|
+
|
40
|
+
valid_client.request(:put, :api, "/user", :username => username, :name => name + "updated")
|
41
|
+
|
42
|
+
assert_equal (name + "updated"), valid_client.request(:get, :api, "/user", :username => username).first['name']
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'integration_helper'
|
2
|
+
|
3
|
+
class DataStoreIntegrationTest < StackMobIntegrationTest
|
4
|
+
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
|
8
|
+
@ds = StackMob::DataStore.new(valid_client)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_list_api
|
12
|
+
assert @ds.api_schema.has_key? "user"
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_user_object_lifecycle
|
16
|
+
username = "456"
|
17
|
+
name = "StackMob Test"
|
18
|
+
updated_name = "updated name"
|
19
|
+
|
20
|
+
@ds.delete(:user, :username => username)
|
21
|
+
|
22
|
+
@ds.create(:user, :username => username, :name => name)
|
23
|
+
|
24
|
+
assert_equal name, @ds.get(:user, :username => username).first['name']
|
25
|
+
|
26
|
+
@ds.update(:user, username, :name => updated_name)
|
27
|
+
|
28
|
+
assert_equal updated_name, @ds.get_one(:user, :username => username)['name']
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'integration_helper'
|
2
|
+
|
3
|
+
class DeployerIntegrationTest < StackMobIntegrationTest
|
4
|
+
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
|
8
|
+
@deployer = StackMob::Deployer.new(valid_client)
|
9
|
+
@hostname1 = "test.localhost"
|
10
|
+
@hostname2 = "test.localhost.2"
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_register_and_fetch_app
|
14
|
+
@deployer.register(@hostname1)
|
15
|
+
|
16
|
+
assert_equal @hostname1, @deployer.fetch['hostname']
|
17
|
+
|
18
|
+
@deployer.register(@hostname2)
|
19
|
+
|
20
|
+
assert_equal @hostname2, @deployer.fetch['hostname']
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'integration_helper'
|
2
|
+
|
3
|
+
class PushIntegrationTest < StackMobIntegrationTest
|
4
|
+
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
|
8
|
+
@user_id = "push_user"
|
9
|
+
@device_token = "1b9cc1e947889c47f83bab981f0b5349a38903578c40cca519b1c22796c5eadf"
|
10
|
+
|
11
|
+
@push = StackMob::Push.new(valid_client)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_register_broadcast_push
|
15
|
+
@push.register(@user_id, @device_token)
|
16
|
+
|
17
|
+
@push.broadcast(:badge => 1, :sound => "audiofile.mpg", :alert => "My Push Message to all")
|
18
|
+
|
19
|
+
@push.send_message(@user_id, :sound => "anotherfile.mpg", :alert => "Ruby Gem Says: hi #{@user_id}", :badge => 2, :recipients_are_users => true)
|
20
|
+
|
21
|
+
@push.send_message(@device_token, :alert => "Ruby Gem: This is a message for token: #{@device_token}")
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class StackMobIntegrationTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
attr_reader :sm_url, :sm_key, :sm_secret, :valid_client
|
6
|
+
|
7
|
+
MISSING_URL_ERR_MSG = "!! ABORTED: You must define the STACKMOB_TEST_URL environment variable in order to run this suite"
|
8
|
+
|
9
|
+
def sm_app_vsn
|
10
|
+
0
|
11
|
+
end
|
12
|
+
|
13
|
+
def sm_app_name
|
14
|
+
"angrybirds3"
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup
|
18
|
+
set_sm_url!
|
19
|
+
set_sm_consumer_key
|
20
|
+
set_sm_consumer_secret
|
21
|
+
|
22
|
+
@valid_client = StackMob::Client.new(sm_url, sm_app_name, sm_app_vsn, sm_key, sm_secret)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def set_sm_url!
|
28
|
+
if !(@sm_url = ENV['STACKMOB_TEST_URL']) then
|
29
|
+
puts MISSING_URL_ERR_MSG
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# SHOULD WE FORCE THESE TO BE ENVIRONMENT VARIABLES AS WELL?
|
35
|
+
# IT WOULD PREVENT THIS SUITE FROM BEING RUN WITH MOST LIKELY
|
36
|
+
# BAD CREDENTIALS, BUT WONT PREVENT IT ALTOGETHER
|
37
|
+
def set_sm_consumer_key
|
38
|
+
@sm_key = ENV['STACKMOB_TEST_KEY'] || "b0b4b19e-2901-4b3b-b8a7-67338d2b5cb3"
|
39
|
+
end
|
40
|
+
|
41
|
+
def set_sm_consumer_secret
|
42
|
+
@sm_secret = ENV['STACKMOB_TEST_SECRET'] || "b3764a11-cdcb-4750-9aad-cee0b6201d0c"
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
end
|