Skip to content

Instantly share code, notes, and snippets.

require 'nokogiri'
app = proc do |env|
doc = Nokogiri::HTML('<html><head></head><body><div id="hello">Hello World</div></body></html>')
body = doc.css('#hello').content
[body, 200, { 'Content-Type' => 'text/plain', 'Content-Length' => body.size.to_s }]
end
run app
app = proc do |env|
body = Hash[ENV].merge(env).map {|k,v| k.inspect + " => " + v.inspect }.join("\n")
response = Rack::Response.new([body], 200, { 'Content-Type' => 'text/plain', 'Content-Length' => body.size.to_s})
response.finish
end
run app
BareTest.new_component :datamapper do
require 'dm-core'
DataMapper.auto_migrate!
setup do
DataMapper.repository do |r|
transaction = DataMapper::Transaction.new(r)
transaction.begin
r.adapter.push_transaction(transaction)
$LOAD_PATH.unshift(File.expand_path("#{__FILE__}/../../lib")) # Add PROJECT/lib to $LOAD_PATH
require 'stylist'
Jede URL, die der Bot aufruft, fängt immer mit "/api/<key>/<user key>/<user name>" an. Nachher kann dieselbe URL wie immer im Webinterface benutzt werden. Die grundlegenden wären:
* PUT /leave (leavt das aktuelle game)
* PUT /games/<id>/join (joint das gewählte game)
* POST /league/new_game [type, default Random]
CaptainGame: nur challenger wenn anonymous challenge
noch challenged wenn direkte challenge
* PUT /accept_challenge (um eine challenge zu akzeptieren)
* PUT /deny_challenge (sehe oben)
* PUT /vote (wobei vote abort, sentinel_wins, scourge_wins sein kann)
module Presenters
class Game
include Presenter
def initialize(game)
@game = game
self
end
def prepare
generate_messages
setup :method, "#member" do
@method = :member
end
setup :method, "#collection" do
@method = :collection
end
setup :stem, "stem" do
@stem = Stem.allocate
require 'rango/mixins/rendering'
class Application < Merb::Controller
include Rango::ExplicitRendering
def scope
super.tap do |scope|
scope.extend ResourceHelper
scope.instance_variable_set("@params", self.request.params)
scope.extend Merb::Helpers
scope.extend Merb::AssetsMixin
require 'rango/mixins/rendering'
class Application < Merb::Controller
include Rango::ExplicitRendering
def scope
super.extend(ResourceHelper)
end
def context
@context ||= super.merge(params: self.request.params)