Forum: Ruby on Rails ActionWebService for many APIs in rails?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
474216d84e3b5381cba84cd04a3a3b35?d=identicon&s=25 joaz (Guest)
on 2007-06-19 17:05
Hi,

We've a pretty large rails application and we are currently deciding
moving a part of the application front-end to a desktop GUI.

For communication between application and GUI we decided to use an API.
So basically what I need is a way to have our models functionality
accessible by the GUI.

The basic idea:

Rails app provides API for models <-> HTTPS Connection <-> GUI can
access models with correct authentication

I took a look to ActionWebservice, but I'm not sure if this is the best
solution.

My concern: The application has currently about 90 models. If I
understood AWS correctly, I need to create an API class for every model
and a 'service' for every model I want to serve?

Is there an automation script for this or is there a more direct
approach to my problem ?

Thanks!
4317d685bafaae74c9a2dd64c545b98d?d=identicon&s=25 claudio (Guest)
on 2007-06-19 17:26
(Received via mailing list)
You create just one class API

dir: RAILS_ROOT/app/apis/myserver_api.rb
class MyserverApi < ActionWebService::API::Base
    api_method :list_products,
                :expects => [:string],
                :returns => [:string]

    api_method :list_users,
                :expects => [:string],
                :returns => [:string]

    api_method :list_orders,
                :expects => [:string],
                :returns => [:string]

end


dir: RAILS_ROOT/app/controller/myserver_controller.rb
class MyserverController < ApplicationController
     wsdl_service_name 'Myserver'
     web_service_api MyserverApi

    def list_products(str)
    end

    def list_users(str)
    end

    def list_orders(str)
    end
end

In the api you put all the method that are in the controller and after
you use
your models inside your controller. You can do the job with one API
class definition or you split in more for how many controllers you
have.

Or if you already have your controllers done, you just need to write
some API





2007/6/19, joaz <rails-mailing-list@andreas-s.net>:
474216d84e3b5381cba84cd04a3a3b35?d=identicon&s=25 joaz (Guest)
on 2007-06-19 17:49
> Or if you already have your controllers done, you just need to write
> some API
Wenn 95% of all controller actions just grabs some data like

def list
  @people = Person.find(:all)
end

I tried something like this:
  api_method :list, :returns => [[Person]]

But I get an error when accessing via invoke using the SOAP protocol:
"decimal is not a valid base type" on numeric fields in our postgresql
database.
4317d685bafaae74c9a2dd64c545b98d?d=identicon&s=25 claudio (Guest)
on 2007-06-19 18:05
(Received via mailing list)
api_method :list, :returns => [[:string]]

with this returns an array with one record for each row


2007/6/19, joaz <rails-mailing-list@andreas-s.net>:
474216d84e3b5381cba84cd04a3a3b35?d=identicon&s=25 joaz (Guest)
on 2007-06-19 18:17
claudio wrote:
> api_method :list, :returns => [[:string]]
>
> with this returns an array with one record for each row

well in my case this returns an array with Object.to_s
["#<Person:0xb701e23c>", "#<Person:0xb701e0d4>",...]
This topic is locked and can not be replied to.