├── README.rdoc ├── log └── .keep ├── app ├── mailers │ └── .keep ├── models │ ├── .keep │ ├── concerns │ │ └── .keep │ ├── .DS_Store │ ├── mongoid │ │ ├── .DS_Store │ │ ├── soft_delete.rb │ │ └── base_model.rb │ ├── mimi_contact.rb │ ├── mimi_topic.rb │ ├── mimi_topic_reply.rb │ └── mimi_user.rb ├── assets │ ├── images │ │ └── .keep │ ├── stylesheets │ │ ├── index.css.scss │ │ ├── mimis.css.scss │ │ ├── videos.css.scss │ │ ├── courses.css.scss │ │ └── application.css │ └── javascripts │ │ ├── courses.js.coffee │ │ ├── index.js.coffee │ │ ├── mimis.js.coffee │ │ ├── videos.js.coffee │ │ └── application.js ├── controllers │ ├── concerns │ │ └── .keep │ ├── .DS_Store │ ├── application_controller.rb │ └── mimis_controller.rb ├── helpers │ ├── mimis_helper.rb │ ├── application_helper.rb │ └── .DS_Store ├── api │ ├── utils.rb │ ├── api.rb │ ├── entities.rb │ ├── helpers.rb │ └── api_v1.rb └── views │ ├── .DS_Store │ ├── layouts │ └── application.html.erb │ └── mimis │ └── index.html.erb ├── lib ├── assets │ └── .keep └── tasks │ └── .keep ├── public ├── favicon.ico ├── robots.txt ├── 500.html ├── 422.html └── 404.html ├── test ├── helpers │ ├── .keep │ ├── index_helper_test.rb │ ├── mimis_helper_test.rb │ ├── videos_helper_test.rb │ └── courses_helper_test.rb ├── mailers │ └── .keep ├── models │ └── .keep ├── controllers │ ├── .keep │ ├── mimis_controller_test.rb │ ├── courses_controller_test.rb │ ├── index_controller_test.rb │ └── videos_controller_test.rb ├── fixtures │ └── .keep ├── integration │ └── .keep └── test_helper.rb ├── vendor └── assets │ ├── javascripts │ └── .keep │ └── stylesheets │ └── .keep ├── db ├── .DS_Store └── seeds.rb ├── config ├── .DS_Store ├── environment.rb ├── initializers │ ├── session_store.rb │ ├── filter_parameter_logging.rb │ ├── mime_types.rb │ ├── wrap_parameters.rb │ ├── backtrace_silencers.rb │ ├── inflections.rb │ └── secret_token.rb ├── boot.rb ├── locales │ └── en.yml ├── environments │ ├── development.rb │ ├── test.rb │ └── production.rb ├── application.rb ├── routes.rb └── mongoid.yml ├── bin ├── rake ├── bundle └── rails ├── config.ru ├── Rakefile ├── .gitignore ├── Gemfile ├── README.md └── Gemfile.lock /README.rdoc: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /log/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/mailers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/models/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/assets/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/helpers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/mailers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/models/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/assets/images/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/controllers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/integration/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/assets/javascripts/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/assets/stylesheets/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/helpers/mimis_helper.rb: -------------------------------------------------------------------------------- 1 | module MimisHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/api/utils.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | module APIUtils 3 | 4 | 5 | end 6 | -------------------------------------------------------------------------------- /db/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jikexueyuan/mimi_api/HEAD/db/.DS_Store -------------------------------------------------------------------------------- /config/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jikexueyuan/mimi_api/HEAD/config/.DS_Store -------------------------------------------------------------------------------- /app/helpers/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jikexueyuan/mimi_api/HEAD/app/helpers/.DS_Store -------------------------------------------------------------------------------- /app/models/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jikexueyuan/mimi_api/HEAD/app/models/.DS_Store -------------------------------------------------------------------------------- /app/views/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jikexueyuan/mimi_api/HEAD/app/views/.DS_Store -------------------------------------------------------------------------------- /app/controllers/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jikexueyuan/mimi_api/HEAD/app/controllers/.DS_Store -------------------------------------------------------------------------------- /app/models/mongoid/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jikexueyuan/mimi_api/HEAD/app/models/mongoid/.DS_Store -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative '../config/boot' 3 | require 'rake' 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /test/helpers/index_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class IndexHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /test/helpers/mimis_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class MimisHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /test/helpers/videos_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class VideosHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /test/helpers/courses_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class CoursesHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path('../../config/application', __FILE__) 3 | require_relative '../config/boot' 4 | require 'rails/commands' 5 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Rails.application 5 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the Rails application. 5 | JikeXueyuan::Application.initialize! 6 | -------------------------------------------------------------------------------- /config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | JikeXueyuan::Application.config.session_store :cookie_store, key: '_JikeXueyuan_session' 4 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | # Set up gems listed in the Gemfile. 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | 4 | require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) 5 | -------------------------------------------------------------------------------- /test/controllers/mimis_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class MimisControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/courses_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class CoursesControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /app/api/api.rb: -------------------------------------------------------------------------------- 1 | require "entities" 2 | require "helpers" 3 | require "utils" 4 | class Api < Grape::API 5 | prefix "api" 6 | format :json 7 | default_error_formatter :json 8 | 9 | mount Api_v1 10 | 11 | end -------------------------------------------------------------------------------- /app/assets/stylesheets/index.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the index controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/mimis.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the mimis controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/videos.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the videos controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/courses.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the courses controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /app/models/mimi_contact.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | class MimiContact 3 | include Mongoid::Document 4 | include Mongoid::Timestamps 5 | 6 | field :phone_md5 7 | field :u_phone_md5 8 | belongs_to :mimi_user 9 | 10 | 11 | end -------------------------------------------------------------------------------- /test/controllers/index_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class IndexControllerTest < ActionController::TestCase 4 | test "should get index" do 5 | get :index 6 | assert_response :success 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | # Mime::Type.register_alias "text/html", :iphone 6 | -------------------------------------------------------------------------------- /app/assets/javascripts/courses.js.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://coffeescript.org/ 4 | -------------------------------------------------------------------------------- /app/assets/javascripts/index.js.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://coffeescript.org/ 4 | -------------------------------------------------------------------------------- /app/assets/javascripts/mimis.js.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://coffeescript.org/ 4 | -------------------------------------------------------------------------------- /app/assets/javascripts/videos.js.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://coffeescript.org/ 4 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV["RAILS_ENV"] ||= "test" 2 | require File.expand_path('../../config/environment', __FILE__) 3 | require 'rails/test_help' 4 | 5 | class ActiveSupport::TestCase 6 | # Add more helper methods to be used by all tests here... 7 | end 8 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path('../config/application', __FILE__) 5 | 6 | JikeXueyuan::Application.load_tasks 7 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | # Prevent CSRF attacks by raising an exception. 3 | # For APIs, you may want to use :null_session instead. 4 | protect_from_forgery with: :exception 5 | 6 | 7 | 8 | end 9 | -------------------------------------------------------------------------------- /app/api/entities.rb: -------------------------------------------------------------------------------- 1 | require "digest/md5" 2 | 3 | module APIEntities 4 | 5 | 6 | class MimiTopic < Grape::Entity 7 | expose :msg,:msgId,:phone_md5,:created_at 8 | end 9 | 10 | class MimiTopicReply < Grape::Entity 11 | expose :rid,:content,:phone_md5,:created_at 12 | end 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | end 21 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) 7 | # Mayor.create(name: 'Emanuel', city: cities.first) 8 | -------------------------------------------------------------------------------- /app/models/mimi_topic.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | class MimiTopic 3 | include Mongoid::Document 4 | include Mongoid::Timestamps 5 | include Mongoid::BaseModel 6 | 7 | field :msg 8 | field :phone_md5 9 | field :state, :type => Integer, :default => 1 10 | 11 | 12 | belongs_to :mimi_user 13 | 14 | scope :normal, -> { where(:state.gt => 0) } 15 | 16 | def msgId 17 | self.id.to_s 18 | end 19 | end -------------------------------------------------------------------------------- /config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] if respond_to?(:wrap_parameters) 9 | end 10 | -------------------------------------------------------------------------------- /test/controllers/videos_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class VideosControllerTest < ActionController::TestCase 4 | test "should get index" do 5 | get :index 6 | assert_response :success 7 | end 8 | 9 | test "should get upload" do 10 | get :upload 11 | assert_response :success 12 | end 13 | 14 | test "should get edit" do 15 | get :edit 16 | assert_response :success 17 | end 18 | 19 | end 20 | -------------------------------------------------------------------------------- /app/models/mimi_topic_reply.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | class MimiTopicReply 3 | include Mongoid::Document 4 | include Mongoid::Timestamps 5 | 6 | field :content 7 | field :phone_md5 8 | belongs_to :mimi_topic 9 | belongs_to :mimi_user 10 | 11 | 12 | scope :by_msg_id, Proc.new { |t| where(:mimi_topic_id => t) } 13 | scope :normal, -> { where(:state.gt => 0) } 14 | 15 | 16 | def rid 17 | self.id.to_s 18 | end 19 | 20 | end -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /app/controllers/mimis_controller.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | class MimisController < ApplicationController 3 | 4 | def index 5 | @users = MimiUser.paginate(:page => params[:page], :per_page => 1000) 6 | @topics = MimiTopic.paginate(:page => params[:page], :per_page => 1000) 7 | @replies = MimiTopicReply.paginate(:page => params[:page], :per_page => 1000) 8 | @contacts = MimiContact.paginate(:page => params[:page], :per_page => 1000) 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /app/models/mongoid/soft_delete.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | # 软删除 3 | module Mongoid 4 | module SoftDelete 5 | extend ActiveSupport::Concern 6 | 7 | included do 8 | field :deleted_at, :type => DateTime 9 | 10 | default_scope where(:deleted_at => nil) 11 | alias_method :destroy!, :destroy 12 | end 13 | 14 | def destroy 15 | if persisted? 16 | self.update_attribute(:deleted_at,Time.now.utc) 17 | end 18 | 19 | @destroyed = true 20 | freeze 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore the default SQLite database. 11 | /db/*.sqlite3 12 | /db/*.sqlite3-journal 13 | 14 | # Ignore all logfiles and tempfiles. 15 | /log/*.log 16 | /tmp 17 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |If you are the application owner check the logs for more information.
56 | 57 | 58 | -------------------------------------------------------------------------------- /public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |Maybe you tried to change something you didn't have access to.
55 |If you are the application owner check the logs for more information.
57 | 58 | 59 | -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |You may have mistyped the address or the page may have moved.
55 |If you are the application owner check the logs for more information.
57 | 58 | 59 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | JikeXueyuan::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure static asset server for tests with Cache-Control for performance. 16 | config.serve_static_assets = true 17 | config.static_cache_control = "public, max-age=3600" 18 | 19 | # Show full error reports and disable caching. 20 | config.consider_all_requests_local = true 21 | config.action_controller.perform_caching = false 22 | 23 | # Raise exceptions instead of rendering exception templates. 24 | config.action_dispatch.show_exceptions = false 25 | 26 | # Disable request forgery protection in test environment. 27 | config.action_controller.allow_forgery_protection = false 28 | 29 | # Tell Action Mailer not to deliver emails to the real world. 30 | # The :test delivery method accumulates sent emails in the 31 | # ActionMailer::Base.deliveries array. 32 | config.action_mailer.delivery_method = :test 33 | 34 | # Print deprecation notices to the stderr. 35 | config.active_support.deprecation = :stderr 36 | end 37 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | source 'http://ruby.taobao.org' 3 | #source 'https://rubygems.org' 4 | 5 | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 6 | gem 'rails', '4.0.1' 7 | 8 | #new qiniu gems 9 | gem 'qiniu-policy' 10 | gem 'unicorn' 11 | # Mongoid 辅助插件 12 | gem 'mongoid', '~> 4.0.0.beta1', :github => 'mongoid/mongoid' 13 | gem 'will_paginate_mongoid' 14 | gem 'will_paginate' #, '3.0.4' 15 | gem 'will_paginate-bootstrap' 16 | 17 | gem 'execjs' 18 | gem 'therubyracer' 19 | 20 | #ui 21 | gem 'flatui-rails-less' 22 | 23 | #for api 24 | gem 'grape' 25 | gem 'grape-entity' 26 | 27 | gem 'ruby-hmac' 28 | gem 'rest_client' 29 | gem 'json' 30 | 31 | # Use SCSS for stylesheets 32 | gem 'sass-rails', '~> 4.0.0' 33 | 34 | # Use Uglifier as compressor for JavaScript assets 35 | gem 'uglifier', '>= 1.3.0' 36 | 37 | # Use CoffeeScript for .js.coffee assets and views 38 | gem 'coffee-rails', '~> 4.0.0' 39 | 40 | # See https://github.com/sstephenson/execjs#readme for more supported runtimes 41 | # gem 'therubyracer', platforms: :ruby 42 | 43 | # Use jquery as the JavaScript library 44 | gem 'jquery-rails' 45 | 46 | # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks 47 | gem 'turbolinks' 48 | 49 | # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 50 | gem 'jbuilder', '~> 1.2' 51 | 52 | group :doc do 53 | # bundle exec rake doc:rails generates the API under doc/api. 54 | gem 'sdoc', require: false 55 | end 56 | 57 | # Use ActiveModel has_secure_password 58 | # gem 'bcrypt-ruby', '~> 3.1.2' 59 | 60 | # Use unicorn as the app server 61 | # gem 'unicorn' 62 | 63 | # Use Capistrano for deployment 64 | # gem 'capistrano', group: :development 65 | 66 | # Use debugger 67 | # gem 'debugger', group: [:development, :test] 68 | -------------------------------------------------------------------------------- /app/models/mongoid/base_model.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | # 基本 Model,加入一些通用功能 3 | module Mongoid 4 | module BaseModel 5 | extend ActiveSupport::Concern 6 | 7 | included do 8 | # scope :recent, desc(:_id) 9 | # scope :exclude_ids, Proc.new { |ids| where(:_id.nin => ids.map(&:to_i)) } 10 | 11 | delegate :url_helpers, to: 'Rails.application.routes' 12 | end 13 | 14 | def update_last_reply(reply) 15 | # replied_at 用于最新回复的排序,如果贴着创建时间在一个月以前,就不再往前面顶了 16 | self.last_active_mark = Time.now.to_i if self.created_at > 1.month.ago 17 | self.replied_at = Time.now 18 | self.last_reply_id = reply.id 19 | self.last_reply_account_id = reply.account_id 20 | self.last_reply_account_login = reply.account.try(:login) || nil 21 | self.save 22 | end 23 | 24 | module ClassMethods 25 | # like ActiveRecord find_by_id 26 | def find_by_id(id) 27 | if id.is_a?(Integer) or id.is_a?(String) 28 | where(:_id => id.to_i).first 29 | else 30 | nil 31 | end 32 | end 33 | 34 | def find_in_batches(opts = {}) 35 | batch_size = opts[:batch_size] || 1000 36 | start = opts.delete(:start).to_i || 0 37 | objects = self.limit(batch_size).skip(start) 38 | t = Time.new 39 | while objects.any? 40 | yield objects 41 | start += batch_size 42 | # Rails.logger.debug("processed #{start} records in #{Time.new - t} seconds") if Rails.logger.debug? 43 | break if objects.size < batch_size 44 | objects = self.limit(batch_size).skip(start) 45 | end 46 | end 47 | 48 | def delay 49 | Sidekiq::Extensions::Proxy.new(DelayedDocument, self) 50 | end 51 | 52 | end 53 | 54 | def delay 55 | Sidekiq::Extensions::Proxy.new(DelayedDocument, self) 56 | end 57 | 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | JikeXueyuan::Application.routes.draw do 2 | require 'api' 3 | mount Api => "/" 4 | 5 | # The priority is based upon order of creation: first created -> highest priority. 6 | # See how all your routes lay out with "rake routes". 7 | 8 | # You can have the root of your site routed with "root" 9 | # root 'welcome#index' 10 | root 'index#index' 11 | 12 | # Example of regular route: 13 | # get 'products/:id' => 'catalog#view' 14 | 15 | # Example of named route that can be invoked with purchase_url(id: product.id) 16 | # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase 17 | 18 | # Example resource route (maps HTTP verbs to controller actions automatically): 19 | # resources :products 20 | 21 | # Example resource route with options: 22 | # resources :products do 23 | # member do 24 | # get 'short' 25 | # post 'toggle' 26 | # end 27 | # 28 | # collection do 29 | # get 'sold' 30 | # end 31 | # end 32 | 33 | # Example resource route with sub-resources: 34 | # resources :products do 35 | # resources :comments, :sales 36 | # resource :seller 37 | # end 38 | 39 | resources :mimis do 40 | end 41 | 42 | 43 | 44 | 45 | # Example resource route with more complex sub-resources: 46 | # resources :products do 47 | # resources :comments 48 | # resources :sales do 49 | # get 'recent', on: :collection 50 | # end 51 | # end 52 | 53 | # Example resource route with concerns: 54 | # concern :toggleable do 55 | # post 'toggle' 56 | # end 57 | # resources :posts, concerns: :toggleable 58 | # resources :photos, concerns: :toggleable 59 | 60 | # Example resource route within a namespace: 61 | # namespace :admin do 62 | # # Directs /admin/products/* to Admin::ProductsController 63 | # # (app/controllers/admin/products_controller.rb) 64 | # resources :products 65 | # end 66 | end 67 | -------------------------------------------------------------------------------- /app/api/api_v1.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | #Api 3 | #Get(先用get测,测试完成后再换成post) 4 | #入口: http://demo.eoeschool.com/nimings/io?action=xxx 5 | #返回: status-状态;msg-提示信息 6 | #Todo:连发送短信的接口发短信; 7 | class Api_v1 < Grape::API 8 | version 'v1', :using => :path, :format => :json #,:vendor => 'acme' 9 | helpers APIHelpers 10 | 11 | 12 | resource :nimings do 13 | get '/hey' do 14 | "say hey from NiMing " 15 | end 16 | 17 | post '/io' do 18 | act = params[:action] 19 | if act == "send_pass" 20 | MimiUser.send_code(params[:phone]) 21 | elsif act == "login" 22 | code = params[:code] 23 | phone_md5 = params[:phone_md5] 24 | MimiUser.try_login_by_code(phone_md5,code) 25 | else 26 | authenticate! 27 | case act 28 | #上传联系人 29 | when "upload_contacts" 30 | contacts = params[:contacts] 31 | if(current_user.upload_contacts(contacts)) 32 | {:status =>"1", "msg" => "成了~" } 33 | else 34 | {:status =>"0", "msg" => "失败鸟~" } 35 | end 36 | #消息列表 37 | when "timeline" 38 | page = params[:page] || 1 39 | prepage = params[:prepage] || 10 40 | @items = current_user.get_timeline(page,prepage) 41 | present @items, :with => APIEntities::MimiTopic 42 | body( { status: "1", items: body() }) 43 | #获取评论 44 | when "get_comment" 45 | msg_id = params[:msgId] 46 | page = params[:page] || 1 47 | prepage = params[:prepage] || 10 48 | @comments = current_user.get_comment(msg_id,page,prepage) 49 | present @comments, :with => APIEntities::MimiTopicReply 50 | body( { status: "1", items: body() }) 51 | #发布消息 52 | when "publish" 53 | msg = params[:msg] 54 | current_user.publish(msg) 55 | #发布评论 56 | when "pub_comment" 57 | content = params[:content] 58 | msg_id = params[:msgId] 59 | current_user.pub_comment(msg_id,content) 60 | else 61 | end 62 | end 63 | 64 | end 65 | 66 | end 67 | 68 | 69 | 70 | 71 | end #end class -------------------------------------------------------------------------------- /config/mongoid.yml: -------------------------------------------------------------------------------- 1 | development: 2 | # Configure available database sessions. (required) 3 | sessions: 4 | # Defines the default session. (required) 5 | default: 6 | # Defines the name of the default database that Mongoid can connect to. 7 | # (required). 8 | database: mimi 9 | # Provides the hosts the default session can connect to. Must be an array 10 | # of host:port pairs. (required) 11 | hosts: 12 | - localhost:27017 13 | options: 14 | # Change whether the session persists in safe mode by default. 15 | # (default: false) 16 | # safe: false 17 | 18 | # Change the default consistency model to :eventual or :strong. 19 | # :eventual will send reads to secondaries, :strong sends everything 20 | # to master. (default: :eventual) 21 | # consistency: :strong 22 | pool_size: 35 23 | # Configure Mongoid specific options. (optional) 24 | options: 25 | # Configuration for whether or not to allow access to fields that do 26 | # not have a field definition on the model. (default: true) 27 | # allow_dynamic_fields: true 28 | 29 | # Enable the identity map, needed for eager loading. (default: false) 30 | # identity_map_enabled: false 31 | 32 | # Includes the root model name in json serialization. (default: false) 33 | # include_root_in_json: false 34 | 35 | # Include the _type field in serializaion. (default: false) 36 | # include_type_for_serialization: false 37 | 38 | # Preload all models in development, needed when models use 39 | # inheritance. (default: false) 40 | # preload_models: false 41 | 42 | # Protect id and type from mass assignment. (default: true) 43 | # protect_sensitive_fields: true 44 | 45 | # Raise an error when performing a #find and the document is not found. 46 | # (default: true) 47 | # raise_not_found_error: true 48 | 49 | # Raise an error when defining a scope with the same name as an 50 | # existing method. (default: false) 51 | # scope_overwrite_exception: false 52 | 53 | # Skip the database version check, used when connecting to a db without 54 | # admin access. (default: false) 55 | # skip_version_check: false 56 | 57 | # User Active Support's time zone in conversions. (default: true) 58 | # use_activesupport_time_zone: true 59 | 60 | # Ensure all times are UTC in the app side. (default: false) 61 | # use_utc: false 62 | test: 63 | sessions: 64 | default: 65 | database: mimi 66 | hosts: 67 | - localhost:27017 68 | options: 69 | consistency: :strong 70 | #production 71 | production: 72 | sessions: 73 | default: 74 | database: mimi 75 | hosts: 76 | - localhost:27017 77 | options: 78 | # consistency: :strong 79 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 秘密服务器端代码 2 | ================ 3 | 4 | Ruby写的秘密服务器端代码 5 | 6 | 环境: 7 | Ruby + MongoDB + Grape 8 | 9 | 10 | # MiMi_Api的配置部署 11 | 12 | 13 | ## 首先安装Ruby环境 14 | 15 | 首先更新你的服务器,我一般用的是Debian,国际惯例 16 | 17 | `sudo apt-get update && sudo apt-get upgrade` 18 | 19 | 然后用普通用户安装RVM,RVM是一个管理Ruby版本的软件,当然你也可以选择Rbenv,紧紧是个人喜好以及熟悉问题: 20 | 21 | `\curl -sSL https://get.rvm.io | bash -s stable` 22 | 23 | 执行过后,需要再执行这个确保本机配置正确: 24 | 25 | `source ~/.rvm/scripts/rvm` 26 | 27 | 此刻,如果你打出`rvm -v`,终端出现如下字样,那么恭喜你,rvm安装成功 28 | 29 | `rvm 1.25.29 (stable) by Wayne E. Seguin