json_voorhees 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 603192b4fe8aa21892159a4e72b2aacb9cd9aa8c
4
- data.tar.gz: c79b6b8ccf9fc8acc22d0fe42f45e371f5e7822f
3
+ metadata.gz: 85db652f4df886f9e564573f69313155cc208c09
4
+ data.tar.gz: 5c34d2f12abcff0f7619146d7b3f49b75de9d5db
5
5
  SHA512:
6
- metadata.gz: 3ce4c588efd0acde009e6b09984f496571152bb765ea4561706e0ed76062d7a21a90380daae6fbb5ec22839c55d8c203aec1fc6ef1d3e34de4ee1ab4cc394629
7
- data.tar.gz: 97697e505ab8e34a4cbbdd50def3420125bdfbcf54c7abce66779396d7f8c8e064da03a1c9525eb58ffff84822103e7367df2769488462f2ff5ab1cd457e92c9
6
+ metadata.gz: d53425a719f8ee49b347cd07f9ab52bd99febbec580557986f64b33110c4056ff92c6763240801fe0a201b57b758dff9a6f0fe070587aa4ed7fe0e5b6de2a9e7
7
+ data.tar.gz: 709fa8e55311d4f7d4f09252f0348072ee8a902cb706824d7a932cf5251bd7c711c3790fa7c0551764e232b72a4d91fe8453d12dfc1258db10ffa7fb91a3528e
data/README.md CHANGED
@@ -1,24 +1,11 @@
1
- # JsonVoorhees 1.3.0
1
+ # JsonVoorhees 1.4.2
2
2
 
3
3
  ## Introduction
4
4
 
5
- I frequently take on projects that involve some kind of an api and it was a nightmare
6
- repeating all of the boilerplate code to get the backend in a useable state.
7
- I abstracted away all of the code that I typically use into a series of generators
8
- namespaced under json_voorhees. Not only does it set your project up, it also
9
- helps build the project if you follow the conventions.
10
-
11
- The standards that I set up for my APIs are those that separate all resources into engines and
12
- version everything. The benefits are seen immediately when versioning a controller etc but
13
- when versioning a model not so. Versioning a model into classes like so, People::User,
14
- People::V1::User and People::V2::User allow you to separate the model that contains the admin
15
- display details (People::User) and the model that follows the rules of the api. In addition,
16
- to avoid polluting controllers, authorizations are handled by the main app in a gem. Every
17
- action is before_filtered to a function in the authorization gem and handed the current_user,
18
- the current_resource and a couple auxillary variables. Tests are also handled in the
19
- main app. The scaffolds will take care of the tedious work, just know where everything is
20
- when you need it. Once you are accustomed to the location of everything, it will be very
21
- easy to speed through the backends development.
5
+ JsonVoorhees is an api builder that encapsulates all of it's generated code
6
+ inside of engines. It's essentially an opinionated framework built with rails
7
+ generators. It comes with common gems, a user model and other common functionality
8
+ such as token authentication.
22
9
 
23
10
  ## Scaffold Use
24
11
 
@@ -65,35 +52,28 @@ rails g json_voorhees:massive_scaffold chat message 1 user_id:integer message:te
65
52
  5. (in main_app root) Copy migrations to main app and run db migrations in main app like so. "rake railties:install:migrations && rake db:migrate RAILS_ENV=development && rake db:migrate RAILS_ENV=test"
66
53
  6. (in main_app root) Run "rspec" to check for errors
67
54
 
68
- I usually set the app up, and then design the database. I make a list of all the models I need, then separate them into engines. Then I run 20 or so massive scaffolds using "&&". The result is a modular functioning backend that only needs the model relationships wired together. The default tests get you pretty far.
69
-
70
- ## Versioning
71
-
72
- This generator is strongly tied in with versioning. As so every
73
- model, controller, serializer, test and factory created with this tool are
74
- versioned. The main app hosts the application controllers and test suite. Everything
75
- else resides in engines for good modularity.
55
+ I usually set the app up, and then design the database. I make a list of all the models I need, then separate them into engines. Then I run 20 or so massive scaffolds using "&&". The result is a modular functioning backend that only needs the model relationships wired together. The default tests get you pretty far. It's a pretty good idea to create a script file that contains all of the scaffolds. It's essentially a schema for how to recreate your backend.
76
56
 
77
57
  ## Gotchas and Reminders
78
58
 
79
59
  1. Make sure the version of Rails is the same in both engine and app.
80
60
  2. The mailer doesn't need to be set up. For test and development it is set so this doesn't have to be the case but change the environment config file to make it work.
81
- 3. To user the mailer, make sure to export GMAIL_USERNAME and GMAIL_PASSWORD to your environment. Or you can just overwrite the values in the environment config file.
61
+ 3. To use the mailer, make sure to export GMAIL_USERNAME and GMAIL_PASSWORD to your environment. Or you can just overwrite the values in the environment config file.
82
62
  4. To use gmail, your account needs to have an app_password. That is the password that should go on file.
83
63
  5. Account mailer in the people engine needs to be updated with the correct domain as well the host in application.rb config file for production.
84
64
  6. The account controller isn't under the api, forgotten_passwords etc should be implemented on the server.
85
- 7. To run the generators, sometimes spring will get in your way. If it hands run "spring stop"
65
+ 7. To run the generators, sometimes spring will get in your way. If it hangs, run "spring stop"
86
66
  8. Cors may not work the same on all machines and rails versions. If it is acting up in production, if serve static assets is false, it wont find the Rails Static middleware to insert before and it will throw an error.
87
67
  9. For fbonly, make sure you go to the facebook folder and look at the file. You need to set the environment variables FB_APPID1 and FB_SECRET1.
88
68
 
89
- Does not work with Rails 4.2 yet. Byebug is added by default and this generator tries to add it twice.
69
+ Does not work with Rails 4.2 yet. Byebug is added by default and this generator tries to add it twice so it fails.
90
70
 
91
71
  ##Future
92
72
 
93
73
  1. Sidekiq
94
74
  2. Paperclip
95
75
  3. Websockets
96
- 4. Facebook support
76
+ 4. App tokens
97
77
 
98
78
  Emails are sent synchronously for now. I'm waiting for ActiveJob in Rails 4.2 so I can
99
79
  implement that interface and user the sidekiq adapter.
@@ -3,6 +3,7 @@ module JsonVoorhees
3
3
  source_root File.expand_path('../templates', __FILE__)
4
4
 
5
5
  def sprint
6
+ createSettings
6
7
  createDev
7
8
  createTest
8
9
  createPro
@@ -11,6 +12,13 @@ module JsonVoorhees
11
12
 
12
13
  private
13
14
 
15
+ def createSettings
16
+ run "rails g rails_config:install"
17
+ prepend_to_file 'config/settings.yml' do
18
+ "token_header: \"Auth_Token\"\napi_header: \"Api_Token\"\n"
19
+ end
20
+ end
21
+
14
22
  def addToApplication
15
23
  inject_into_file 'config/application.rb', after: "class Application < Rails::Application\n" do <<-'RUBY'
16
24
 
@@ -29,6 +37,7 @@ module JsonVoorhees
29
37
  end
30
38
 
31
39
  def createDev
40
+ ::Settings.reload!
32
41
  gsub_file "config/environments/development.rb", "config.action_mailer.raise_delivery_errors = false\n", "#config.action_mailer.raise_delivery_errors = false\n"
33
42
  inject_into_file 'config/environments/development.rb', after: "configure do\n" do <<-'RUBY'
34
43
 
@@ -44,12 +53,16 @@ module JsonVoorhees
44
53
  password: ENV['GMAIL_PASSWORD'],
45
54
  authentication: 'plain',
46
55
  enable_starttls_auto: true }
47
-
56
+ ::Paperclip.options[:command_path] = "/usr/bin/"
57
+ #Set Paperclip defaults here
58
+ #Paperclip::Attachment.default_options[:storage] = :fog
59
+
48
60
  RUBY
49
61
  end
50
62
  end
51
63
 
52
64
  def createTest
65
+ ::Settings.reload!
53
66
  gsub_file "config/environments/test.rb", "config.action_mailer.delivery_method = :test\n", "#config.action_mailer.delivery_method = :test\n"
54
67
  inject_into_file 'config/environments/test.rb', after: "configure do\n" do <<-'RUBY'
55
68
 
@@ -66,12 +79,16 @@ module JsonVoorhees
66
79
  password: 'testing123',
67
80
  authentication: 'plain',
68
81
  enable_starttls_auto: true }
69
-
82
+ ::Paperclip.options[:command_path] = "/usr/bin/"
83
+ #Set Paperclip defaults here
84
+ #Paperclip::Attachment.default_options[:storage] = :fog
85
+
70
86
  RUBY
71
87
  end
72
88
  end
73
89
 
74
90
  def createPro
91
+ ::Settings.reload!
75
92
  inject_into_file 'config/environments/production.rb', after: "configure do\n" do <<-'RUBY'
76
93
 
77
94
  config.action_mailer.perform_deliveries = true
@@ -86,7 +103,8 @@ module JsonVoorhees
86
103
  password: ENV['GMAIL_PASSWORD'],
87
104
  authentication: 'plain',
88
105
  enable_starttls_auto: true }
89
-
106
+ #May need to set Paperclip defaults here
107
+
90
108
  RUBY
91
109
  end
92
110
  end
@@ -6,7 +6,7 @@ RSpec.describe ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>
6
6
  before(:example) do
7
7
  @user = FactoryGirl.create(:fbuser_user_1)
8
8
  token = @user.tokens[0].auth_token
9
- @header = {"Auth-Token" => token}
9
+ @header = {::Settings.token_header => token}
10
10
  end
11
11
  # get /api/<%= api_version %>/<%= resource_plural %>
12
12
  it "Gets all of the <%= resource_singular %>s" do
@@ -23,7 +23,7 @@ RSpec.describe ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>
23
23
  before(:example) do
24
24
  @user = FactoryGirl.create(:fbuser_user_1)
25
25
  token = @user.tokens[0].auth_token
26
- @header = {"Auth-Token" => token}
26
+ @header = {::Settings.token_header => token}
27
27
  end
28
28
  # get /api/<%= api_version %>/<%= resource_plural %>/1
29
29
  it "Gets a <%= resource_singular %> by id" do
@@ -38,7 +38,7 @@ RSpec.describe ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>
38
38
  before(:example) do
39
39
  @user = FactoryGirl.create(:fbuser_user_1)
40
40
  token = @user.tokens[0].auth_token
41
- @header = {"Auth-Token" => token}
41
+ @header = {::Settings.token_header => token}
42
42
  end
43
43
  # post /api/<%= api_version %>/<%= resource_plural %>
44
44
  it "Creates <%= resource_singular %>" do
@@ -55,7 +55,7 @@ RSpec.describe ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>
55
55
  before(:example) do
56
56
  @user = FactoryGirl.create(:fbuser_user_1)
57
57
  token = @user.tokens[0].auth_token
58
- @header = {"Auth-Token" => token}
58
+ @header = {::Settings.token_header => token}
59
59
  end
60
60
  # patch/put /api/<%= api_version %>/<%= resource_plural %>/1
61
61
  it "Updates <%= resource_singular %>" do
@@ -74,7 +74,7 @@ RSpec.describe ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>
74
74
  before(:example) do
75
75
  @user = FactoryGirl.create(:fbuser_user_1)
76
76
  token = @user.tokens[0].auth_token
77
- @header = {"Auth-Token" => token}
77
+ @header = {::Settings.token_header => token}
78
78
  end
79
79
  # delete /api/<%= api_version %>/<%= resource_plural %>/1
80
80
  it "Deletes <%= resource_singular %>" do
@@ -97,7 +97,7 @@ RSpec.describe ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>
97
97
  before(:example) do
98
98
  @user = FactoryGirl.create(:fbuser_user_1)
99
99
  token = @user.tokens[0].auth_token
100
- @header = {"Auth-Token" => token}
100
+ @header = {::Settings.token_header => token}
101
101
  end
102
102
  # get /api/1/collection
103
103
  it "checks response of a collection route" do
@@ -111,7 +111,7 @@ RSpec.describe ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>
111
111
  before(:example) do
112
112
  @user = FactoryGirl.create(:fbuser_user_1)
113
113
  token = @user.tokens[0].auth_token
114
- @header = {"Auth-Token" => token}
114
+ @header = {::Settings.token_header => token}
115
115
  end
116
116
  it "checks the index json sent back" do
117
117
 
@@ -124,7 +124,7 @@ RSpec.describe ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>
124
124
  before(:example) do
125
125
  @user = FactoryGirl.create(:fbuser_user_1)
126
126
  token = @user.tokens[0].auth_token
127
- @header = {"Auth-Token" => token}
127
+ @header = {::Settings.token_header => token}
128
128
  end
129
129
  # get /api/<%= api_version %>/<%= resource_plural %>/1
130
130
  it "checks for a 404" do
@@ -6,7 +6,7 @@ RSpec.describe ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>
6
6
  before(:example) do
7
7
  @user = FactoryGirl.create(:people_user_1)
8
8
  token = @user.tokens[0].auth_token
9
- @header = {"Auth-Token" => token, "Email" => @user.email}
9
+ @header = {::Settings.token_header => token, "Email" => @user.email}
10
10
  end
11
11
  # get /api/<%= api_version %>/<%= resource_plural %>
12
12
  it "Gets all of the <%= resource_singular %>s" do
@@ -23,7 +23,7 @@ RSpec.describe ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>
23
23
  before(:example) do
24
24
  @user = FactoryGirl.create(:people_user_1)
25
25
  token = @user.tokens[0].auth_token
26
- @header = {"Auth-Token" => token, "Email" => @user.email}
26
+ @header = {::Settings.token_header => token, "Email" => @user.email}
27
27
  end
28
28
  # get /api/<%= api_version %>/<%= resource_plural %>/1
29
29
  it "Gets a <%= resource_singular %> by id" do
@@ -38,7 +38,7 @@ RSpec.describe ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>
38
38
  before(:example) do
39
39
  @user = FactoryGirl.create(:people_user_1)
40
40
  token = @user.tokens[0].auth_token
41
- @header = {"Auth-Token" => token, "Email" => @user.email}
41
+ @header = {::Settings.token_header => token, "Email" => @user.email}
42
42
  end
43
43
  # post /api/<%= api_version %>/<%= resource_plural %>
44
44
  it "Creates <%= resource_singular %>" do
@@ -55,7 +55,7 @@ RSpec.describe ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>
55
55
  before(:example) do
56
56
  @user = FactoryGirl.create(:people_user_1)
57
57
  token = @user.tokens[0].auth_token
58
- @header = {"Auth-Token" => token, "Email" => @user.email}
58
+ @header = {::Settings.token_header => token, "Email" => @user.email}
59
59
  end
60
60
  # patch/put /api/<%= api_version %>/<%= resource_plural %>/1
61
61
  it "Updates <%= resource_singular %>" do
@@ -74,7 +74,7 @@ RSpec.describe ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>
74
74
  before(:example) do
75
75
  @user = FactoryGirl.create(:people_user_1)
76
76
  token = @user.tokens[0].auth_token
77
- @header = {"Auth-Token" => token, "Email" => @user.email}
77
+ @header = {::Settings.token_header => token, "Email" => @user.email}
78
78
  end
79
79
  # delete /api/<%= api_version %>/<%= resource_plural %>/1
80
80
  it "Deletes <%= resource_singular %>" do
@@ -97,7 +97,7 @@ RSpec.describe ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>
97
97
  before(:example) do
98
98
  @user = FactoryGirl.create(:people_user_1)
99
99
  token = @user.tokens[0].auth_token
100
- @header = {"Auth-Token" => token, "Email" => @user.email}
100
+ @header = {::Settings.token_header => token, "Email" => @user.email}
101
101
  end
102
102
  # get /api/1/collection
103
103
  it "checks response of a collection route" do
@@ -111,7 +111,7 @@ RSpec.describe ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>
111
111
  before(:example) do
112
112
  @user = FactoryGirl.create(:people_user_1)
113
113
  token = @user.tokens[0].auth_token
114
- @header = {"Auth-Token" => token, "Email" => @user.email}
114
+ @header = {::Settings.token_header => token, "Email" => @user.email}
115
115
  end
116
116
  it "checks the index json sent back" do
117
117
 
@@ -124,7 +124,7 @@ RSpec.describe ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>
124
124
  before(:example) do
125
125
  @user = FactoryGirl.create(:people_user_1)
126
126
  token = @user.tokens[0].auth_token
127
- @header = {"Auth-Token" => token, "Email" => @user.email}
127
+ @header = {::Settings.token_header => token, "Email" => @user.email}
128
128
  end
129
129
  # get /api/<%= api_version %>/<%= resource_plural %>/1
130
130
  it "checks for a 404" do
@@ -124,18 +124,18 @@ module JsonVoorhees
124
124
  gem 'annotate', ">=2.6.0"
125
125
  gem 'rspec-rails', '~> 3.0.0'
126
126
  gem 'byebug', '~> 3.2.0'
127
- gem "factory_girl_rails", "~> 4.0"
128
- gem "database_cleaner", '~> 1.3.0'
127
+ gem 'factory_girl_rails', '~> 4.0'
128
+ gem 'database_cleaner', '~> 1.3.0'
129
129
  end
130
130
  gem_group :development do
131
- gem "better_errors", '~> 1.1.0'
132
- gem "binding_of_caller", "~> 0.7.1" # needed by better_errors or variable inspection
131
+ gem 'better_errors', '~> 1.1.0'
132
+ gem 'binding_of_caller', '~> 0.7.1' # needed by better_errors or variable inspection
133
133
  end
134
134
  # Other gems
135
135
  # This ties in nicely with Ember, 0.8.0 is the stable version
136
- gem "active_model_serializers", "~> 0.8.0"
136
+ gem 'active_model_serializers', '~> 0.8.0'
137
137
  # This is the api of choice now
138
- gem "rails-api"
138
+ gem 'rails-api'
139
139
  gem 'kaminari'
140
140
  gem 'bcrypt', '~> 3.1.7'
141
141
  gem 'type_cartographer'
@@ -149,6 +149,9 @@ module JsonVoorhees
149
149
  gem 'whenever', :require => false
150
150
  gem 'rack-cors', :require => 'rack/cors'
151
151
  gem 'httparty'
152
+ gem 'paperclip', '~> 4.2'
153
+ gem 'aws-sdk', '~> 1.5.7'
154
+ gem 'rails_config', '~> 0.4.2'
152
155
  #gem 'websocket-rails'
153
156
  end
154
157
 
@@ -1,13 +1,20 @@
1
1
  class Api::V1::ApiController < ::ActionController::API
2
2
 
3
+ #before_action :authenticate_app
3
4
  before_action :authenticate_user
4
5
 
5
6
  private
6
7
 
8
+ #def authenticate_app
9
+ #end
10
+
7
11
  def authenticate_user
8
12
  set_hash
9
13
  if @instance_hash.nil?
14
+ response.headers["Logged-In-Status"] = "false"
10
15
  render :json => {errors: "User is not logged in, register or log in"} , status: :unauthorized
16
+ else
17
+ response.headers["Logged-In-Status"] = "true"
11
18
  end
12
19
  end
13
20
 
@@ -26,8 +33,8 @@ class Api::V1::ApiController < ::ActionController::API
26
33
 
27
34
  def set_hash
28
35
  #["current_owner","current_token"] Make this true to check for email also
29
- @instance_hash = ::Arcadex::Authentication.get_instance(params,request,"Auth-Token")
30
- #@instance_hash = ::Arcadex::Authentication.authenticate_owner_with_index(params,request,"Auth-Token","Email","email",true)
36
+ @instance_hash = ::Arcadex::Authentication.get_instance(params,request,::Settings.token_header)
37
+ #@instance_hash = ::Arcadex::Authentication.authenticate_owner_with_index(params,request,"::Settings.token_header,"Email","email",true)
31
38
  #Ignore the token if the user's account is locked
32
39
  <% if !options.fbonly? %>
33
40
  if !current_user.nil? && current_user.locked
@@ -1,3 +1,3 @@
1
1
  module JsonVoorhees
2
- VERSION = "1.4.1"
2
+ VERSION = "1.4.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_voorhees
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cleophus Robinson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-05 00:00:00.000000000 Z
11
+ date: 2014-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails