Permalink
Browse files

server to return data as json via rest api

  • Loading branch information...
robmckinnon committed Nov 21, 2008
1 parent 335c946 commit 3e25c01bd4edf0d66d086d3f41317e0fe4fe731c
Showing with 42 additions and 0 deletions.
  1. +2 −0 Manifest
  2. +1 −0 Rakefile
  3. +5 −0 bin/rugalytics
  4. +1 −0 lib/rugalytics.rb
  5. +33 −0 lib/rugalytics/server.rb
View
@@ -5,11 +5,13 @@ lib/rugalytics/graph.rb
lib/rugalytics/item.rb
lib/rugalytics/profile.rb
lib/rugalytics/report.rb
+lib/rugalytics/server.rb
lib/rugalytics.rb
LICENSE
Manifest
README
README.rdoc
+bin/rugalytics
rugalytics.yml.example
spec/fixtures/analytics_account_find_all.html
spec/fixtures/analytics_profile_find_all.html
View
@@ -11,6 +11,7 @@ begin
m.rdoc_options << '--inline-source'
m.rdoc_pattern = ["README", "CHANGELOG", "LICENSE"]
m.dependencies = ["hpricot >=0.6", "activesupport >=2.0.2", "googlebase >=0.2.0", "morph >=0.2.0"]
+ m.executable_pattern = 'bin/rugalytics'
end
rescue LoadError
View
@@ -0,0 +1,5 @@
+require 'rugalytics'
+
+puts 'rugalytics ' + Rugalytics::VERSION
+
+Rugalytics::Server.new
View
@@ -100,5 +100,6 @@ def i18n_date_parse text
require File.dirname(__FILE__) + '/rugalytics/report'
require File.dirname(__FILE__) + '/rugalytics/item'
require File.dirname(__FILE__) + '/rugalytics/graph'
+require File.dirname(__FILE__) + '/rugalytics/server'
# Rugalytics.config_setup(RAILS_ROOT) if defined?(RAILS_ROOT) && RAILS_ROOT
View
@@ -0,0 +1,33 @@
+require 'yaml'
+require 'webrick'
+include WEBrick
+
+module Rugalytics
+
+ class Servlet < HTTPServlet::AbstractServlet
+ def do_GET(req, res)
+ res.body = "<HTML>hello, world.</HTML>"
+ res['Content-Type'] = "text/html"
+ end
+ end
+
+ class Server
+ def initialize
+ @profile = Rugalytics.default_profile
+
+ server = HTTPServer.new :Port => 8888
+
+ server.mount("/", Rugalytics::Servlet)
+
+ server.mount_proc("/top_content_detail_keywords") {|request, response|
+ url = request.query['url']
+ report = @profile.top_content_detail_keywords_report(:url => url)
+ response.body = [url, report.name, report.items.to_yaml].join("\n")
+ response['Content-Type'] = "text/plain"
+ }
+
+ trap("INT"){ server.shutdown }
+ server.start
+ end
+ end
+end

0 comments on commit 3e25c01

Please sign in to comment.