stackmob 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,16 +1,24 @@
1
1
  # StackMob
2
2
 
3
- This gem is meant to be used along with the StackMob add-on for Heroku. Using this gem you can run your StackMob application's custom code on Heroku using Rails 3 & Sinatra (Rails 2.3.x Support Coming Soon).
3
+ This gem is meant to be used along with the StackMob add-on for Heroku. Using this gem you can extend your StackMob REST API using a Rails 3 or Sinatra application (Rails 2.3.x Support Coming Soon) deployed on Heroku.
4
+
5
+ When you deploy your application your routes will become available via the production version of your StackMob API. StackMob will proxy any API call of the form `http://[SUBDOMAIN].mob2.stackmob.com/api/[VERSION]/[APPNAME]/heroku/proxy/[ROUTE]` to your Heroku application.
4
6
 
5
7
  ## Adding StackMob to your Rails 3 Application
6
8
 
7
9
  Add the following to your Gemfile and run `bundle install`:
8
10
 
9
11
  gem "stackmob", :require => "stackmob/rails"
12
+
13
+ Additionally, you will want to include some helpful methods in your controllers. Add the line below to the `ApplicationController`. Check out "Interacting With Your API in Your Application" for more details about the methods provided by StackMob::Helpers.
14
+
15
+ include StackMob::Helpers
16
+
17
+ ## Configuring Your Application (For Local Development)
18
+
19
+ This section only pertains to setting up your Rails or Sinatra application for development & testing. If you wish solely to deploy to Heroku you can skip this section.
10
20
 
11
- ## Configuring Your Application
12
-
13
- The gem requires a few configuration details that need to be added to the file `config/stackmob.yml`. You will need the name of the application you created, as well as your public and private keys for both development (sandbox) and production from the StackMob add-on dashboard. When specifying your Heroku hostname, if your application is available under the herokuapp.com domain as well as heroku.com, use the herokuapp.com domain otherwise, use heroku.com.
21
+ For local development, a few configuration details need to be set in the file `config/stackmob.yml`. You will need your subdomain, the name of the application you created, as well as your public and private keys for both development (sandbox) and production from the StackMob add-on dashboard. When specifying your Heroku hostname, if your application is available under the herokuapp.com domain as well as heroku.com, use the herokuapp.com domain otherwise, use heroku.com.
14
22
 
15
23
  # example config/stackmob.yml
16
24
  sm_app_name: StackMob App Name
@@ -24,10 +32,8 @@ The gem requires a few configuration details that need to be added to the file `
24
32
  production:
25
33
  key: Your StackMob Production Public Key
26
34
  secret: Your StackMob Production Private Key
27
-
28
- Additionally, you will want to include some helpful methods in your controllers. Add the line below to the `ApplicationController`. Check out "Interacting With Your API in Your Application" for more details about the methods provided by StackMob::Helpers.
29
-
30
- include StackMob::Helpers
35
+
36
+ The railtie provided with this gem adds a simple oauth provider into the middleware stack. When making requests to your Rails or Sinatra application while its running locally you can either use the oauth gem, installed as a dependency to this one, with your public/private development keys in `config/stackmob.yml` or add the line `no_oauth: true` under the development section of the same config file. Adding the `no_oauth: true` line to `config/stackmob.yml` will only prevent verification of oauth keys locally. It will not turn off the middleware in production even if the option is specified under the production section of the config file.
31
37
 
32
38
  ## Interacting with CRUD from the Console
33
39
 
@@ -175,7 +181,7 @@ You can then proxy requests to your application using the `StackMob::Client#requ
175
181
 
176
182
  ## Running your Application Locally in Development
177
183
 
178
- The railtie provided with this gem adds a simple oauth provider into the middleware stack. When making requests to your Rails or Sinatra application while its running locally you can either use the oauth gem, installed as a dependency to this one, with your public/private development keys in `config/stackmob.yml` or add the line `no_oauth: true` under the development section of the same config file. Adding the `no_oauth: true` line to `config/stackmob.yml` will only prevent verification of oauth keys locally. It will not turn off the middleware in production even if the option is specified under the production section of the config file.
184
+
179
185
 
180
186
  ## Contributing to stackmob gem
181
187
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/lib/stackmob.rb CHANGED
@@ -32,19 +32,19 @@ module StackMob
32
32
  end
33
33
 
34
34
  def self.secret
35
- StackMob.config[sm_env_str]['secret']
35
+ ENV[sm_env_key_str(:private_key)] || StackMob.config[sm_env_str]['secret']
36
36
  end
37
37
 
38
38
  def self.key
39
- StackMob.config[sm_env_str]['key']
39
+ ENV[sm_env_key_str(:public_key)] || StackMob.config[sm_env_str]['key']
40
40
  end
41
41
 
42
42
  def self.app_name
43
- StackMob.config['sm_app_name']
43
+ ENV['STACKMOB_APP_NAME'] || StackMob.config['sm_app_name']
44
44
  end
45
45
 
46
46
  def self.client_name
47
- StackMob.config['sm_client_name']
47
+ ENV['STACKMOB_CLIENT_NAME'] || StackMob.config['sm_client_name']
48
48
  end
49
49
 
50
50
  def self.dev_url
@@ -63,5 +63,9 @@ module StackMob
63
63
  ENV["RACK_ENV"] == "production"
64
64
  end
65
65
 
66
+ def self.sm_env_key_str(suffix)
67
+ "STACKMOB_" + ((is_production?) ? "PROD" : "SAND") + "_#{suffix.upcase}"
68
+ end
69
+
66
70
 
67
71
  end
data/stackmob.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{stackmob}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{StackMob}]
12
- s.date = %q{2011-08-29}
12
+ s.date = %q{2011-09-12}
13
13
  s.description = %q{Support Gem for StackMob Heroku Add-On}
14
14
  s.email = %q{jordan@stackmob.com}
15
15
  s.extra_rdoc_files = [
@@ -46,7 +46,8 @@ Gem::Specification.new do |s|
46
46
  "test/unit/stackmob/test_client.rb",
47
47
  "test/unit/stackmob/test_data_store.rb",
48
48
  "test/unit/stackmob/test_deployer.rb",
49
- "test/unit/stackmob/test_push.rb"
49
+ "test/unit/stackmob/test_push.rb",
50
+ "test/unit/test_stackmob.rb"
50
51
  ]
51
52
  s.homepage = %q{http://github.com/stackmob/stackmob-ruby}
52
53
  s.licenses = [%q{MIT}]
@@ -0,0 +1,129 @@
1
+ require 'helper'
2
+
3
+ class StackMobTestCase < MiniTest::Unit::TestCase
4
+
5
+ def setup
6
+ @config_dev_key = "config_dev_key"
7
+ @config_dev_secret = "config_dev_secret"
8
+ @config_prod_key = "config_prod_key"
9
+ @config_prod_secret = "config_prod_secret"
10
+ @config_app_name = "config_app_name"
11
+ @config_client_name = "config_client_name"
12
+
13
+ @env_dev_key = "env_dev_key"
14
+ @env_dev_secret = "env_dev_secret"
15
+ @env_prod_key = "env_prod_key"
16
+ @env_prod_secret = "env_prod_secret"
17
+ @env_app_name = "env_app_name"
18
+ @env_client_name = "env_client_name"
19
+
20
+ StackMob.stubs(:config).returns("sm_client_name" => @config_client_name, "sm_app_name" => @config_app_name,
21
+ "development" => {"key" => @config_dev_key, "secret" => @config_dev_secret}, "production" => {"key" => @config_prod_key, "secret" => @config_prod_secret})
22
+ end
23
+
24
+ def test_fetch_app_name_when_no_env_key_exists
25
+ assert_equal @config_app_name, StackMob.app_name
26
+ end
27
+
28
+ def test_fetch_app_name_when_env_key_exists
29
+ ENV["STACKMOB_APP_NAME"] = @env_app_name
30
+
31
+ assert_equal @env_app_name, StackMob.app_name
32
+
33
+ ENV["STACKMOB_APP_NAME"] = nil
34
+ end
35
+
36
+ def test_fetch_client_name_when_no_env_key_exists
37
+ assert_equal @config_client_name, StackMob.client_name
38
+ end
39
+
40
+ def test_fetch_client_name_when_env_key_exists
41
+ ENV["STACKMOB_CLIENT_NAME"] = @env_client_name
42
+
43
+ assert_equal @env_client_name, StackMob.client_name
44
+
45
+ ENV["STACKMOB_CLIENT_NAME"] = nil
46
+ end
47
+
48
+ def test_fetch_dev_key_when_no_env_key_exists
49
+ previous_rack_env = ENV["RACK_ENV"]
50
+ ENV["RACK_ENV"] = "development"
51
+
52
+ assert_equal @config_dev_key, StackMob.key
53
+
54
+ ENV["RACK_ENV"] = previous_rack_env
55
+ end
56
+
57
+ def test_fetch_dev_secret_when_no_env_secret_exists
58
+ previous_rack_env = ENV["RACK_ENV"]
59
+ ENV["RACK_ENV"] = "development"
60
+
61
+ assert_equal @config_dev_secret, StackMob.secret
62
+
63
+ ENV["RACK_ENV"] = previous_rack_env
64
+ end
65
+
66
+ def test_fetch_prod_key_when_no_env_key_exists
67
+ previous_rack_env = ENV["RACK_ENV"]
68
+ ENV["RACK_ENV"] = "production"
69
+
70
+ assert_equal @config_prod_key, StackMob.key
71
+
72
+ ENV["RACK_ENV"] = previous_rack_env
73
+ end
74
+
75
+ def test_fetch_prod_secret_when_no_env_secret_exists
76
+ previous_rack_env = ENV["RACK_ENV"]
77
+ ENV["RACK_ENV"] = "production"
78
+
79
+ assert_equal @config_prod_secret, StackMob.secret
80
+
81
+ ENV["RACK_ENV"] = previous_rack_env
82
+ end
83
+
84
+ def test_fetches_dev_key_from_env_when_exists
85
+ previous_rack_env = ENV["RACK_ENV"]
86
+ ENV["RACK_ENV"] = "development"
87
+ ENV["STACKMOB_SAND_PUBLIC_KEY"] = @env_dev_key
88
+
89
+ assert_equal @env_dev_key, StackMob.key
90
+
91
+ ENV["STACKMOB_SAND_PUBLIC_KEY"] = nil
92
+ ENV["RACK_ENV"] = previous_rack_env
93
+ end
94
+
95
+ def test_fetches_dev_secret_from_env_when_exists
96
+ previous_rack_env = ENV["RACK_ENV"]
97
+ ENV["RACK_ENV"] = "development"
98
+ ENV["STACKMOB_SAND_PRIVATE_KEY"] = @env_dev_secret
99
+
100
+ assert_equal @env_dev_secret, StackMob.secret
101
+
102
+ ENV["STACKMOB_SAND_PRIVATE_KEY"] = nil
103
+ ENV["RACK_ENV"] = previous_rack_env
104
+ end
105
+
106
+ def test_fetches_prod_key_from_env_when_exists
107
+ previous_rack_env = ENV["RACK_ENV"]
108
+ ENV["RACK_ENV"] = "production"
109
+ ENV["STACKMOB_PROD_PUBLIC_KEY"] = @env_prod_key
110
+
111
+ assert_equal @env_prod_key, StackMob.key
112
+
113
+ ENV["RACK_ENV"] = previous_rack_env
114
+ ENV["STACKMOB_PROD_PUBLIC_KEY"] = nil
115
+ end
116
+
117
+ def test_fetches_prod_secret_from_env_when_exists
118
+ previous_rack_env = ENV["RACK_ENV"]
119
+ ENV["RACK_ENV"] = "production"
120
+ ENV["STACKMOB_PROD_PRIVATE_KEY"] = @env_prod_secret
121
+
122
+ assert_equal @env_prod_secret, StackMob.secret
123
+
124
+ ENV["RACK_ENV"] = previous_rack_env
125
+ ENV["STACKMOB_PROD_PRIVATE_KEY"] = nil
126
+ end
127
+
128
+
129
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackmob
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - StackMob
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-29 00:00:00 Z
18
+ date: 2011-09-12 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :runtime
@@ -221,6 +221,7 @@ files:
221
221
  - test/unit/stackmob/test_data_store.rb
222
222
  - test/unit/stackmob/test_deployer.rb
223
223
  - test/unit/stackmob/test_push.rb
224
+ - test/unit/test_stackmob.rb
224
225
  homepage: http://github.com/stackmob/stackmob-ruby
225
226
  licenses:
226
227
  - MIT