mobile_on_rails 0.0.1 → 0.0.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: 468893614c64ce072428d7de06e7ebb6267ab75d
4
- data.tar.gz: 667a17630748e6e5c3a09b4ed74dacbccb7e31c2
3
+ metadata.gz: 1ff4575b3d168b5e3686aa2dd2d40d57378c2e71
4
+ data.tar.gz: 535b3d2689b2c82c16d89010c339cd46fa16f966
5
5
  SHA512:
6
- metadata.gz: a379356096c74411cf5096d416140dfa813a37396d21d9704e279154b4062193233dcfb13991c0aefd6429e4728f552a3afe5bf8c2983545a4fa9d69e326b305
7
- data.tar.gz: fe013e0119caf067504bc7f248afbda8cf43516ab3d006c139c5654deb4f76e937efd2ddc8e32dc581571e2fa35ba352fedce5a5d7f1c9e2bdf5084beb262864
6
+ metadata.gz: d327de7bc80010a7f3564d67dbcee0079ab222594de3466299745642433b5f25cd27a0c5749cdd536ca89d9895a530fe701285ff8d2fdc6758e26fa729e4307b
7
+ data.tar.gz: 82b62199da741db4ce268f845c84cc1cc8273d402de7f1185380598d3c6c5a98fb9512cef9f931fad3d828885fb3eb31679e0ef9539d0fd41582fec857288cbf
@@ -1,5 +1,206 @@
1
1
  require "mobile_on_rails/version"
2
2
 
3
3
  module MobileOnRails
4
- # Your code goes here...
4
+ def self.make_files
5
+ directory = Dir.getwd
6
+ if is_rails_root?(directory)
7
+ # If the migration folder has not yet been created, create it
8
+ Dir.mkdir(directory + "/db/migrate") unless Dir.exist?(directory + "/db/migrate")
9
+
10
+ # Write the migration file
11
+ # NOTE: The user will still need to run rake:db migrate
12
+ time = Time.new
13
+ month = "%02d" % time.month
14
+ day = "%02d" % time.day
15
+ hour = "%02d" % time.hour
16
+ minute = "%02d" % time.min
17
+ second = "%02d" % time.sec
18
+ File.open("#{directory}/db/migrate/#{time.year}#{month}#{day}#{hour}#{minute}#{second}_mobile_on_rails_migration.rb", "w") {|f| f.write(
19
+ %Q{class MobileOnRailsMigration < ActiveRecord::Migration
20
+ def change
21
+ create_table :mor_users do |t|
22
+ t.string :user_name
23
+ t.string :email
24
+ t.string :password_digest
25
+
26
+ t.timestamps
27
+ end
28
+
29
+ create_table :mor_posts do |t|
30
+ t.string :title
31
+ t.text :text
32
+ t.belongs_to :user
33
+
34
+ t.timestamps
35
+ end
36
+
37
+ create_table :mor_tags do |t|
38
+ t.string :name
39
+
40
+ t.timestamps
41
+ end
42
+
43
+ create_table :mor_posts_tags do |t|
44
+ t.belongs_to :post
45
+ t.belongs_to :tag
46
+ end
47
+ end
48
+ end})}
49
+
50
+ # Create the post, tag, and user model files
51
+ File.open("#{directory}/app/models/mor_post.rb", "w") {|f| f.write(
52
+ %Q{class MorPost < ActiveRecord::Base
53
+ belongs_to :user
54
+ has_and_belongs_to_many :mor_tags
55
+ end})}
56
+ File.open("#{directory}/app/models/mor_tag.rb", "w") {|f| f.write(
57
+ %Q{class MorTag < ActiveRecord::Base
58
+ has_and_belongs_to_many :mor_posts
59
+ end})}
60
+ File.open("#{directory}/app/models/mor_user.rb", "w") {|f| f.write(
61
+ %Q{class MorUser < ActiveRecord::Base
62
+ has_secure_password
63
+ validates_presence_of :password, :on => :create
64
+ has_many :mor_posts
65
+ end})}
66
+
67
+ # Create the controller files
68
+ File.open("#{directory}/app/controllers/mor_api_controller.rb", "w") {|f| f.write(
69
+ 'class MorApiController < ApplicationController
70
+ protect_from_forgery except: :receive
71
+ skip_before_filter :verify_authenticity_token
72
+ respond_to :json
73
+
74
+ def receive
75
+ @json_data = JSON.parse(JSON.parse(params.keys.to_s).first)
76
+ key = @json_data.keys[0]
77
+ data = @json_data.values[0]
78
+ case key
79
+ when "newpost"
80
+ save_post(data)
81
+ when "latest"
82
+ get_latest(data["count"].to_i)
83
+ when "edit"
84
+ edit_post(data)
85
+ when "delete"
86
+ delete_post(data)
87
+ when "all"
88
+ all_posts
89
+ else
90
+ puts "Unrecognized value"
91
+ end
92
+ end
93
+
94
+ def save_post(post)
95
+ @post = MorPost.new(post)
96
+ if @post.save
97
+ respond_to do |format|
98
+ msg = { :status => "ok", :message => "Success!", :html => "<b>...</b>" }
99
+ format.json { render :json => msg }
100
+ end
101
+ else
102
+ respond_to do |format|
103
+ msg = { :status => "Error", :message => "Failed", :html => "<b>...</b>" }
104
+ format.json { render :json => msg }
105
+ end
106
+ end
107
+ end
108
+
109
+ def edit_post(post)
110
+ @edit_post = MorPost.find_by(id: post["id"])
111
+ @edit_post.update(title: post["title"], topics: post"topics"], text: post["text"])
112
+ end
113
+
114
+ def delete_post(post)
115
+ @delete_post = MorPost.find_by(id: post["id"])
116
+ @delete_post.destroy
117
+ end
118
+
119
+ def get_latest(count)
120
+ unless count == 0
121
+ @all_posts = MorPost.all
122
+ puts @all_posts.to_json
123
+ render json: @all_posts
124
+ else
125
+ @latest = MorPost.last(count)
126
+ puts @latest.to_json
127
+ render json: @latest
128
+ end
129
+ end
130
+ end')}
131
+ File.open("#{directory}/app/controllers/mor_sessions_controller.rb", "w") {|f| f.write(
132
+ 'class MorSessionsController < ApplicationController
133
+ #protect_from_forgery except: :create
134
+ skip_before_filter :verify_authenticity_token
135
+ respond_to :json
136
+
137
+ def new
138
+ end
139
+
140
+ def create
141
+ @json_data = decode_json(params)
142
+ user = MorUser.find_by_email(@json_data["email"])
143
+ if user && user.authenticate(@json_data["password"])
144
+ session[:user_id] = user.id
145
+ respond_to do |format|
146
+ msg = { :status => "ok", :message => "Logged in!", :user => "#{user.email}" }
147
+ format.json { render :json => msg }
148
+ end
149
+ else
150
+ flash.now.alert = "Invalid email or password!"
151
+ respond_to do |format|
152
+ msg = { :status => "error", :message => "Not Authenticated" }
153
+ format.json { render :json => msg }
154
+ end
155
+ end
156
+ end
157
+
158
+ def destroy
159
+ session[:user_id] = nil
160
+ redirect_to root_url, :notice => "Logged out!"
161
+ end
162
+
163
+ def decode_json(json)
164
+ @json_data = JSON.parse(JSON.parse(json.keys.to_s).first)
165
+ key = @json_data.keys[0]
166
+ data = @json_data.values[0]
167
+ puts data["email"]
168
+ return data
169
+ end
170
+ end')}
171
+ File.open("#{directory}/app/controllers/mor_users_controller.rb", "w") {|f| f.write(
172
+ 'class MorUsersController < ApplicationController
173
+ def new
174
+ @user = MorUser.new
175
+ end
176
+
177
+ def create
178
+ @user = MorUser.new(user_params)
179
+ if @user.save
180
+ redirect_to root_url, :notice => "Signed up!"
181
+ else
182
+ render new
183
+ end
184
+ end
185
+
186
+ private
187
+
188
+ def user_params
189
+ params.require(:user).permit(:email, :password, :password_confirmation)
190
+ end
191
+ end')}
192
+ end
193
+ end
194
+
195
+ def self.is_rails_root?(dir)
196
+ if not Dir.exist?(dir + "/app/models")
197
+ puts "It looks like the directory 'app/models' doesn't exist here! Is this a valid Rails root directory?"
198
+ return false
199
+ elsif not Dir.exists?(dir + "/app/controllers")
200
+ puts "It looks like the directory 'app/controllers' doesn't exist here! Is this a valid Rails root directory?"
201
+ return false
202
+ end
203
+
204
+ true
205
+ end
5
206
  end
@@ -1,3 +1,3 @@
1
1
  module MobileOnRails
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = MobileOnRails::VERSION
9
9
  spec.authors = ["Tyler Standridge"]
10
10
  spec.email = ["tstand90@gmail.com"]
11
- spec.description = "A Rails website with an accompanying iOS and Android app"
11
+ spec.description = "Tyler Standridge's Senior Project for CSU Fresno"
12
12
  spec.summary = "A Rails website with an accompanying iOS and Android app"
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobile_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Standridge
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-16 00:00:00.000000000 Z
11
+ date: 2013-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: A Rails website with an accompanying iOS and Android app
41
+ description: Tyler Standridge's Senior Project for CSU Fresno
42
42
  email:
43
43
  - tstand90@gmail.com
44
44
  executables: []
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  version: '0'
74
74
  requirements: []
75
75
  rubyforge_project:
76
- rubygems_version: 2.1.1
76
+ rubygems_version: 2.0.6
77
77
  signing_key:
78
78
  specification_version: 4
79
79
  summary: A Rails website with an accompanying iOS and Android app