updates from Production version

This commit is contained in:
Lee Lawlor 2014-05-15 16:42:47 -04:00
parent f7b4a3fcce
commit c240b89ed0
10 changed files with 151 additions and 101 deletions

View File

@ -31,7 +31,8 @@ gem 'newrelic_rpm'
gem 'actionpack-xml_parser' gem 'actionpack-xml_parser'
gem 'activeadmin', github: 'gregbell/active_admin' gem 'activeadmin', github: 'gregbell/active_admin'
gem 'chronic' gem 'chronic'
gem "non-stupid-digest-assets" gem 'non-stupid-digest-assets'
gem 'em-http-request'
# to use debugger # to use debugger
# gem 'ruby-debug' # gem 'ruby-debug'

View File

@ -355,6 +355,7 @@ DEPENDENCIES
database_cleaner (~> 1.2.0) database_cleaner (~> 1.2.0)
devise devise
dynamic_form dynamic_form
em-http-request
exception_notification exception_notification
factory_girl_rails factory_girl_rails
faker faker

View File

@ -1,11 +1,19 @@
class ChannelsController < ApplicationController class ChannelsController < ApplicationController
include ChannelsHelper, ApiKeys include ChannelsHelper, ApiKeys
before_filter :require_user, :except => [ :show, :post_data, :social_show, :social_feed, :public] before_filter :require_user, :except => [:realtime, :realtime_update, :show, :post_data, :social_show, :social_feed, :public]
before_filter :set_channels_menu before_filter :set_channels_menu
layout 'application', :except => [:social_show, :social_feed] layout 'application', :except => [:social_show, :social_feed]
protect_from_forgery :except => [:post_data, :create, :destroy, :clear] protect_from_forgery :except => [:realtime, :realtime_update, :post_data, :create, :destroy, :clear]
require 'csv' require 'csv'
# get list of all realtime channels
def realtime
# error if no key
respond_with_error(:error_auth_required) and return if params[:realtime_key] != REALTIME_DAEMON_KEY
channels = Channel.where("realtime_io_serial_number IS NOT NULL")
render :json => channels.to_json(:root => false, :only => [:id, :realtime_io_serial_number])
end
# view list of watched channels # view list of watched channels
def watched def watched
@channels = current_user.watched_channels @channels = current_user.watched_channels
@ -235,6 +243,33 @@ class ChannelsController < ApplicationController
end end
end end
# post from realtime.io daemon
def realtime_update
# exit if not authenticated
respond_with_error(:error_auth_required) and return if params[:realtime_key] != REALTIME_DAEMON_KEY
# set feed and channel
feed = Feed.new
channel = Channel.find(params[:id])
# update entry_id for channel and feed
entry_id = channel.next_entry_id
channel.last_entry_id = entry_id
feed.entry_id = entry_id
# set user agent
channel.user_agent = 'realtime.io'
# set feed details
feed.channel_id = channel.id
feed.status = params[:status]
# save channel and feed
channel.save
feed.save
render :nothing => true
end
# response is '0' if failure, 'entry_id' if success # response is '0' if failure, 'entry_id' if success
def post_data def post_data

View File

@ -54,11 +54,11 @@ class StreamController < ApplicationController
def stream_example def stream_example
# get the channel # get the channel
channel = Channel.find(params[:channel_id]) #channel = Channel.find(params[:channel_id])
# stream the response # stream the response
response.headers['Content-Type'] = 'text/csv' #response.headers['Content-Type'] = 'text/csv'
response.headers['Content-Disposition'] = 'attachment; filename=feeds.csv' #response.headers['Content-Disposition'] = 'attachment; filename=feeds.csv'
20.times { 20.times {
response.stream.write "hello world\n" response.stream.write "hello world\n"
sleep 1 sleep 1

View File

@ -46,6 +46,7 @@
# clearing :boolean default(FALSE), not null # clearing :boolean default(FALSE), not null
# ranking :integer # ranking :integer
# user_agent :string(255) # user_agent :string(255)
# realtime_io_serial_number :string(36)
# #
class Channel < ActiveRecord::Base class Channel < ActiveRecord::Base

View File

@ -27,7 +27,7 @@
<li><b>yaxis</b> (string) Chart's y-axis label, default: field name (optional)</li> <li><b>yaxis</b> (string) Chart's y-axis label, default: field name (optional)</li>
<li><b>color</b> (string) Line color, default: red (optional)</li> <li><b>color</b> (string) Line color, default: red (optional)</li>
<li><b>bgcolor</b> (string) Background color, default: white (optional)</li> <li><b>bgcolor</b> (string) Background color, default: white (optional)</li>
<li><b>type</b> (line/bar/column) Type of chart, default: line (optional)</li> <li><b>type</b> (line/bar/column/spline) Type of chart, default: line (optional)</li>
<li><b>width</b> (integer) Chart width in pixels, iframe width will be 20px larger, default chart width: 400. Set to <i>auto</i> to automatically adjust chart size based on its parent container. (optional)</li> <li><b>width</b> (integer) Chart width in pixels, iframe width will be 20px larger, default chart width: 400. Set to <i>auto</i> to automatically adjust chart size based on its parent container. (optional)</li>
<li><b>height</b> (integer) Chart height in pixels, iframe height will be 20px larger, default chart height: 200. Set to <i>auto</i> to automatically adjust chart size based on its parent container. (optional)</li> <li><b>height</b> (integer) Chart height in pixels, iframe height will be 20px larger, default chart height: 200. Set to <i>auto</i> to automatically adjust chart size based on its parent container. (optional)</li>
<li><b>dynamic</b> (true/false) Make chart update automatically every 15 seconds, default: false (optional)</li> <li><b>dynamic</b> (true/false) Make chart update automatically every 15 seconds, default: false (optional)</li>

View File

@ -80,12 +80,14 @@ Thingspeak::Application.routes.draw do
collection do collection do
get :public get :public
get :watched get :watched
get :realtime
end end
member do member do
get :import get :import
post :upload post :upload
post :clear post :clear
put :watch put :watch
post :realtime_update
end end
resources :feed resources :feed

View File

@ -0,0 +1,7 @@
class AddRealtimeIoSerialNumberToChannels < ActiveRecord::Migration
def change
add_column :channels, :realtime_io_serial_number, :string, :limit => 36
add_index :channels, :realtime_io_serial_number
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140410174033) do ActiveRecord::Schema.define(version: 20140515161337) do
create_table "active_admin_comments", force: true do |t| create_table "active_admin_comments", force: true do |t|
t.string "namespace" t.string "namespace"
@ -103,10 +103,12 @@ ActiveRecord::Schema.define(version: 20140410174033) do
t.boolean "clearing", default: false, null: false t.boolean "clearing", default: false, null: false
t.integer "ranking" t.integer "ranking"
t.string "user_agent" t.string "user_agent"
t.string "realtime_io_serial_number", limit: 36
end end
add_index "channels", ["public_flag", "last_entry_id", "updated_at"], name: "channels_public_viewable", using: :btree add_index "channels", ["public_flag", "last_entry_id", "updated_at"], name: "channels_public_viewable", using: :btree
add_index "channels", ["ranking"], name: "index_channels_on_ranking", using: :btree add_index "channels", ["ranking"], name: "index_channels_on_ranking", using: :btree
add_index "channels", ["realtime_io_serial_number"], name: "index_channels_on_realtime_io_serial_number", using: :btree
add_index "channels", ["slug"], name: "index_channels_on_slug", using: :btree add_index "channels", ["slug"], name: "index_channels_on_slug", using: :btree
add_index "channels", ["user_id"], name: "index_channels_on_user_id", using: :btree add_index "channels", ["user_id"], name: "index_channels_on_user_id", using: :btree

View File

@ -47,6 +47,7 @@
# clearing :boolean default(FALSE), not null # clearing :boolean default(FALSE), not null
# ranking :integer # ranking :integer
# user_agent :string(255) # user_agent :string(255)
# realtime_io_serial_number :string(36)
# #
require 'spec_helper' require 'spec_helper'