Sha256: e324a3d36fbb4ab5985a63e74ba83aa1c2caf6fa179df558698a15eac44d3f0f

Contents?: true

Size: 1.65 KB

Versions: 5

Compression:

Stored size: 1.65 KB

Contents

class Api::BasicController < ApplicationController

  before_filter :set_yamlrpc

  # Simple hellow world example
  def hello_world
    render :text => 'Hello World!'.to_yaml
  end
  
  # Hello world example with status and message response
  def hello_world_with_status
    render :text => {
      :status  => :ok,
      :message => 'Hello World!'
    }.to_yaml
  end
  
  # Unnamed arguments example, ie: client.unnamed_arguments(1, 2, 'foo', 'bar')
  def unnamed_arguments
    render :text => {
      :response => @yamlrpc.map { |e| "#{e.to_s} in response!" }
    }.to_yaml
  end
  
  # Add two arguments and return result example
  def add_foo_bar
    render :text => (@yamlrpc[:foo] + @yamlrpc[:bar]).to_yaml
  end
  
  # Upload binary image example
  # Uploaded image is saved to #{RAILS_ROOT}/public/images/#{@yamlrpc[:save_as]}
  # Returns:
  # * <tt>:status</tt> :ok on success, :error on error
  # * <tt>:message</tt> Descriptive response message
  def upload_image
    begin
      file = open("#{RAILS_ROOT}/public/images/#{@yamlrpc[:save_as]}", "wb")
      file.write @yamlrpc[:image]
      file.close
      status  = :ok
      message = 'Image uploaded successfully'
    rescue StandardError => ex
      status  = :error
      message = ex.message
    end
    render :text => {
      :status  => status,
      :message => message
    }.to_yaml
  end

  def redirect_to_hello_world
    redirect_to :action => 'hello_world'
  end

  def redirect_twice_to_hello_world
    redirect_to :action => 'redirect_to_hello_world'
  end

protected

  def set_yamlrpc
    if request.post? && params[:yamlrpc]
      @yamlrpc = YAML.load(params[:yamlrpc] || "--- \n")
    end
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
yamlrpc-1.0.0 examples/rails_example/app/controllers/api/basic_controller.rb
yamlrpc-1.0.1 examples/rails_example/app/controllers/api/basic_controller.rb
yamlrpc-1.0.2 examples/rails_example/app/controllers/api/basic_controller.rb
yamlrpc-1.0.3 examples/rails_example/app/controllers/api/basic_controller.rb
yamlrpc-1.0.4 examples/rails_example/app/controllers/api/basic_controller.rb