Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Farmer committed Jun 14, 2010
0 parents commit 6828df7
Show file tree
Hide file tree
Showing 165 changed files with 80,443 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
log/*.log
tmp/**/*
config/appbuilder.yml
db/*.sqlite3
39 changes: 39 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
== Welcome to Kynetx AppBuilder

== Request Oauth Tokens
Send an email to oss [at] kynetx [dot] com to request your Oauth Consumer Key and Secret. We will send you an appbuilder.yml file that you can drop into the RAILS_ROOT/config directory that will have development and production keys. When sending the email please include the following for both your production and test/development environments:

1. Name of your application
2. URL of your application
3. Callback URL. (This is the url in your application that the user will be sent to after they have allowed access)
4. Support URL (optional)

== Installation
Make sure you have Rails 2.3.5 installed with Ruby 1.8.7. Copy the code down and run the Rails webserver of your choice. Next, update your config/database.yml file to match your environment. AppBuilder uses a very small table for user management and oauth tokens. Finally, run a rake db:migrate to create the database.

== Contributing
Please feel free to fork the code and make your contributions. We will watch the Fork Queue and bring in the changes.


== License
The MIT License

Copyright (c) 2010 Kynetx Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require(File.join(File.dirname(__FILE__), 'config', 'boot'))

require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

require 'tasks/rails'
38 changes: 38 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details

# Scrub sensitive parameters from your log
filter_parameter_logging :password

helper_method :current_user_session, :current_user, :logged_in, :is_authorized, :current_application

private

def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
end

def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.user.kynetx_user
end

def current_application
@current_user_api ||= current_user.find_application(:application_id => params[:id], :version => "development")
end

def logged_in
unless (current_user)
redirect_to root_url
end
end

def is_authorized
return current_user && (!current_user.access_token.blank?)
end
end
62 changes: 62 additions & 0 deletions app/controllers/applications_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
class ApplicationsController < ApplicationController
before_filter :logged_in

def index
@applications = current_user.applications
end

def edit
begin
@application = current_application
rescue
render :status => 500, :text => "We are sorry, there appears to be a problem accessing the Kynetx API. Please try again later."
end
end

def update
begin
if params[:krl]
response = (current_application.krl = params[:krl])
render :text => response
end
rescue => e
render :status => 400, :text => e
end
end

def create

if params[:name]
@application = current_user.create_application(params[:name], params[:description])
end

next_page = root_url
if @application

next_page = {:action => "edit", :id => @application.application_id}

else
flash[:error] = "Couldn't create your application. #{$!}"
end

redirect_to next_page
end

def new
# TODO: create a new application
end

def destroy
current_application.delete
redirect_to :action => "index"
end

def lame
begin
@application = current_application
rescue
render :status => 500, :text => "We are sorry, there appears to be a problem accessing the Kynetx API. Please try again later."
end
end

end
82 changes: 82 additions & 0 deletions app/controllers/applist_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
require "kynetx_am_api"

class ApplistController < ApplicationController

before_filter :logged_in, :except => [:oauth_connect, :index, :authorize]

def index
# If they are logged in the root is their application list.
redirect_to applications_path() if is_authorized
end

def oauth_connect
new_page = root_url
begin
api = KynetxAmApi::DirectApi.new
new_page = api.get_authorize_url
request_token = api.get_request_token
session[:request_token] = {:request_token => request_token.token,
:request_secret => request_token.secret}
rescue Exception => e
puts e.message
puts e.backtrace().join("\n")
flash[:error] = "There was a problem logging you in."
end

redirect_to new_page
end

def authorize
new_page = applications_path();

begin
raise "Unknown Oauth Request Token" unless session[:request_token]

rt = session[:request_token]

api = KynetxAmApi::DirectApi.new(rt.merge({:oauth_verifier => params[:oauth_verifier]}))
oauth_user = api.get_user_info

# Remove any expired users
User.delete_all ["userid = ? AND expires < ?", oauth_user.userid, Time.now.to_i ]

Rails.logger.debug { "Cookie: #{cookies[:user_credentials]}" }

existing_user = User.find :first, :conditions => ["userid = ? AND persistence_token = ?", oauth_user.userid, cookies[:user_credentials]]

Rails.logger.debug { "FOUND USER: #{existing_user.name}\n#{existing_user.persistence_token}" } if existing_user


@user = existing_user ||
User.create({:password => 'KYNETX ROCKS!',
:password_confirmation => "KYNETX ROCKS!",
:request_token => oauth_user.request_token,
:request_secret => oauth_user.request_secret,
:access_token => oauth_user.access_token,
:access_secret => oauth_user.access_secret,
:username => oauth_user.username,
:userid => oauth_user.userid,
:name => oauth_user.name,
:expires => (Time.now + 2.weeks).to_i})

@user_session = UserSession.create(@user, true)

rescue Exception => e
Rails.logger.debug e.message
Rails.logger.debug e.backtrace.join("\n")

Rails.logger.debug { "Unable to authorize: #{$!}" }
flash[:error] = "Not Authorized. Our bad."
new_page = root_url
end

redirect_to new_page
end

def ping
@response = @apps = current_user.api.ping
end



end
39 changes: 39 additions & 0 deletions app/controllers/deploy_app_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class DeployAppController < ApplicationController
before_filter :logged_in

def index
# tmp_app_info = {"production"=>{"format"=>"json", "KynetxUserID"=>8, "version"=>4, "note"=>nil, "created"=>"2009-12-09 22:56:15 UTC"}, "valid"=>true, "versions"=>[{"format"=>"json", "KynetxUserID"=>18, "version"=>0, "note"=>nil, "created"=>"2009-11-20 23:12:07 UTC"}, {"format"=>"json", "KynetxUserID"=>18, "version"=>1, "note"=>nil, "created"=>"2009-11-20 23:20:43 UTC"}, {"format"=>"json", "KynetxUserID"=>18, "version"=>2, "note"=>nil, "created"=>"2009-11-20 23:39:14 UTC"}, {"format"=>"json", "KynetxUserID"=>18, "version"=>3, "note"=>nil, "created"=>"2009-11-20 23:41:24 UTC"}, {"format"=>"json", "KynetxUserID"=>8, "version"=>4, "note"=>nil, "created"=>"2009-12-09 22:56:15 UTC"}], "development"=>{"format"=>"json", "KynetxUserID"=>8, "version"=>4, "note"=>nil, "created"=>"2009-12-09 22:56:15 UTC"}, "appid"=>"a18x8"}
#
# @prod_version = tmp_app_info["production"]["version"]
# @versions = tmp_app_info["versions"]

@ruleset_id = params[:id]
@app = current_application
@versions = @app.versions
@prod_version = @app.production_version
end

def version_note
current_application.set_version_note(params[:version], params[:note])
redirect_to :action => "index", :id => params[:id]
end

def deploy_version
@ruleset_id = params[:id]
current_application.production_version = params[:version]
redirect_to :action => "index", :id => @ruleset_id
end

def version_source
@ruleset_id = params[:id]
@version = params[:version]
begin
@source = current_application.krl(@version)
rescue
render :status => 500
end
render :layout => false
end


end
88 changes: 88 additions & 0 deletions app/controllers/distribute_app_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
require "base64"
class DistributeAppController < ApplicationController
before_filter :logged_in

def index
end

def extension

end

def gen_extension
ext = ""
extension_type = ""
if params[:ff]
extension_type = "firefox"
elsif params[:cr]
extension_type = "chrome"
elsif params[:ie]
extension_type = "ie"
end

ext = current_application.extension(extension_type, params[:name].to_s, params[:author].to_s, params[:description].to_s)

if ext["errors"].empty?
return send_data Base64.decode64(ext["data"]), :filename => ext["file_name"], :type => ext["content_type"]
end

render :text => ext
end

def infocard

end

def gen_infocard
next_page = ""

if params[:name].blank?
flash[:error] = "Please provide a name for your card."
else
env = params[:env] ? params[:env] : "prod"
card = current_application.infocard(params[:name], params[:datasets], env)
puts card.inspect
return send_data Base64.decode64(card["data"]), :filename => card["file_name"], :type => card["content_type"]
end
redirect_to :action => "infocard"
end


def tags

end

def bookmarklet
@bookmarklet = current_application.bookmarklet
end

def marketplace
@listing = HTTParty.get(MARKETPLACE_URL + "/api/0.1/listingDetail", :query => {:ruleset_id => current_application.application_id})
@found = @listing["found"]
@price = @listing["price"] if @found
@mp_user = HTTParty.get(MARKETPLACE_URL + "/api/0.1/userDetail", :query => {:kynetxuserid => current_user.userid})
@mp_user_found = @mp_user["found"]
end

def list_app

query = {
:ruleset_id => current_application.application_id,
:name => current_application.name,
:kynetxuserid => current_user.userid}
query[:image] = current_application.image_url(:normal) unless current_application.image_url.include?("missing")


response = HTTParty.get(MARKETPLACE_URL + "/api/0.1/listApp",
:query => query)
next_page = {:action => "marketplace", :id => current_application.application_id}
if response["success"]
next_page = response["callback_url"]
else
flash[:error] = response["error"] || "Unable to create the Marketplace listing."
end
redirect_to next_page
end


end
Loading

0 comments on commit 6828df7

Please sign in to comment.