Skip to content

Commit

Permalink
server to return data as json via rest api
Browse files Browse the repository at this point in the history
  • Loading branch information
robmckinnon committed Nov 21, 2008
1 parent 335c946 commit 3e25c01
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Manifest
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions bin/rugalytics
@@ -0,0 +1,5 @@
require 'rugalytics'

puts 'rugalytics ' + Rugalytics::VERSION

Rugalytics::Server.new
1 change: 1 addition & 0 deletions lib/rugalytics.rb
Expand Up @@ -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
33 changes: 33 additions & 0 deletions lib/rugalytics/server.rb
@@ -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.