Sha256: b7328dd6411dea8ce922c2d30f6a6fb79e25d727476179bbc25978520ff64123

Contents?: true

Size: 1.53 KB

Versions: 16

Compression:

Stored size: 1.53 KB

Contents

require "bundler/setup"
require "sinatra/base"
require "roar/representer/json"

class FakeServer < Sinatra::Base
  set :raise_errors, false

  module BandRepresenter
    include Roar::Representer::JSON

    property :name
    property :label
  end

  class Band
    attr_reader :name, :label

    def name=(value)
      @name = value.upcase
    end

    def label=(value)
      @label = value.upcase
    end
  end

  def consume_band
    Band.new.extend(BandRepresenter).from_json(request.body.string)
  end

  get "/method" do
    "<method>get</method>"
  end

  post "/method" do
    "<method>post - #{request.body.read}</method>"
  end

  put "/method" do
    "<method>put - #{request.body.read}</method>"
  end

  delete "/method" do
    "<method>delete</method>"
  end

  patch "/method" do
    "<method>patch - #{request.body.read}</method>"
  end

  get '/deliberate-error' do
    raise 'this error was deliberate'
  end

  post "/bands" do
    #if request.content_type =~ /xml/
    body consume_band.to_json

    status 201
  end

  put "/bands/strungout" do
    # DISCUSS: as long as we don't agree on what to return in PUT/PATCH, let's return an updated document.
    body consume_band.to_json
    #status 204
  end

  patch '/bands/strungout' do
    # DISCUSS: as long as we don't agree on what to return in PUT/PATCH, let's return an updated document.
    body consume_band.to_json
    #status 204
  end

  get "/bands/slayer" do
    {:name => "Slayer", :label => "Canadian Maple"}.to_json
  end

  delete '/banks/metallica' do
    status 204
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
roar-0.12.0 test/fake_server.rb
roar-0.11.19 test/fake_server.rb
roar-0.11.18 test/fake_server.rb
roar-0.11.17 test/fake_server.rb
roar-0.11.16 test/fake_server.rb
roar-0.11.15 test/fake_server.rb
roar-0.11.14 test/fake_server.rb
roar-0.11.13 test/fake_server.rb
roar-0.11.12 test/fake_server.rb
roar-0.11.11 test/fake_server.rb
roar-0.11.10 test/fake_server.rb
roar-0.11.9 test/fake_server.rb
roar-0.11.8 test/fake_server.rb
roar-0.11.7 test/fake_server.rb
roar-0.11.6 test/fake_server.rb
roar-0.11.5 test/fake_server.rb