# How to use API from AWS -- help!

**URL:** <https://www.ruby-forum.com/t/how-to-use-api-from-aws-help/82295>\
**Category:** Rails\
**Created:** [January 18, 2007, 8:20pm UTC](https://www.ruby-forum.com/t/how-to-use-api-from-aws-help/82295 "2007-01-18T20:20:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c2a13f/32.png) [@rph](https://www.ruby-forum.com/u/rph)\
**Post date:** [January 18, 2007, 8:20pm UTC](https://www.ruby-forum.com/t/how-to-use-api-from-aws-help/82295/1 "2007-01-18T20:20:53Z")

</div>

I’m building a users web service (direct dispatching) that will (I hope)  
allow several other applications to manage the same pool of users. Plus  
it will act as a single-sign-on solution for what I’m doing. But I’m  
having difficulty accessing the UserAPI. Here’s what I’ve done so far:

$\> rails usermanagement

- “usermanagement” is the application that will have an API to allow  
other applications to manage the user base (register, edit, login,  
authenticate, etc).

Within usermanagement, I have:

1. models/user.rb

2. controllers/user\_controller.rb

3. apis/user\_api.rb

4. Model: User.rb - This file just holds some business logic for  
maintaining the users.

5. Controller: class UserController \< ApplicationController and below  
this line at the top of the file, I have:

wsdl\_service\_name ‘User’  
web\_service\_api UserApi

then my method implementations.

1. ApiDefinition: UserApi.rb - this file has all of my “api\_method”  
calls and details what methods expect and return.

Now, that’s how I’m setup, and I’ve tested all of this and followed the  
AWDWRv2 book. My problem is trying to access these methods from a  
completely new application, so continuing:

$\> rails newapplication

- “newapplication” will be one of the many applications that must use  
the users web service to register and login, etc. How can I access  
these methods? Here’s what I’m trying (with no luck):

1. In: class SomeController \< ApplicationController I have,  
web\_client\_api :user, :xmlrpc, “[http://localhost:3000/user/api/RPC2](http://localhost:3000/user/api/RPC2)”,  
:handler\_name =\> “user\_api”

And I try using things like “user\_api.authenticate(un,pw)” etc. Doesn’t  
work, I’m currently getting:

“Missing API definition file in apis/user\_api.rb” but surely you don’t  
have to include the file from the other service from within each  
application, right? Because then I would have to have a User.rb model  
in every case as well?

1. In: class SomeController \< ApplicationController I’ve tried,  
user\_api = ActionWebService::Client::XmlRpc.new(UserApi,  
“[http://localhost:3000/user/api/RPC2](http://localhost:3000/user/api/RPC2)”)

And tried accessing things like “user\_api.authenticate(un,pw)” etc.  
That doesn’t work, either. I got the following errors:

“uninitialized constant UserApi” when trying to open the file  
“user\_api.rb”. I don’t know how to fix this.

Actually, I don’t know how to access my methods in the “usermanagement”  
service from any of my other services. Can someone explain that to me?  
See anything wrong with what I’ve tried? And sorry this is so long, but  
I want to include as much information as possible. Thanks a lot for any  
help.

---

<div class="post-metadata">

**Author:** ![rph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c2a13f/32.png) [@rph](https://www.ruby-forum.com/u/rph)\
**Post date:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/how-to-use-api-from-aws-help/82295/2 "2007-01-19T16:31:01Z")

</div>

Hi, my recommendation is to the following:

a) invoke and verify that your external webservice using script/console

```
user_api = ActionWebService::Client::XmlRpc.new(UserApi,
  "http://localhost:3000/user/api/RPC2"

```

b) If (a) is working as expected, then you should read and follow the  
information  
in 25.7 of AWDwRv2.

```
 If not, then you should follow an incremental development

```

approach to correct  
the code:

```
 code A
 test A
 debug A
 code A
 test A
 debug A
 and so on.

 You may not need to debug in every case and you'll continue this 

```

process  
until you have completed the implementation. Why do it this way?  
It seems  
that you have implemented alot of code without testing it until  
the very end.  
Also, I have don’t have time to do it for you and this is  
something that you need  
to learn.

```
 Good luck,

 -Conrad
```

---

<div class="post-metadata">

**Author:** ![rph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c2a13f/32.png) [@rph](https://www.ruby-forum.com/u/rph)\
**Post date:** [September 25, 2007, 10:37pm UTC](https://www.ruby-forum.com/t/how-to-use-api-from-aws-help/82295/3 "2007-09-25T22:37:17Z")

</div>

On 1/18/07, Conrad T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> in 25.7 of AWDwRv2.
> debug A
> Good luck,
> 
> ```
> 
> > the users web service to register and login, etc. How can I access  
> > have to include the file from the other service from within each  
> > “uninitialized constant UserApi” when trying to open the file
> > 
> > >
> 
> >

Hi,

You might also try hitting it with curl:

curl -H “Content-Type: text/xml” -H “SoapAction: authenticate” -d @msg  
-X POST [http://localhost:3000/user/api](http://localhost:3000/user/api)

where @msg is a file with the SOAP or xml message.

I have experience more on the server side of exposing web services  
from a rails controller, not so much in consuming services using  
ActionWebService::Client. If all the applications will be rails  
consider activeresource instead of AWS.

Good luck.

–  
Zack C.  
[http://depixelate.com](http://depixelate.com)
