Rho app sync with SQL database without MVC/heroku

I don't know if it discussed allready, but i'm interested about that: there is a way to synchronize data from mobile terminals directly with a SQL database (without MVC, and without heroku). Is there a way to obtain more information/samples on this issue?

Robert Galvin
Hi I have moved this question

Hi

I have moved this question to the RhoConnect space. It was filed under the AppForum space initially.

CD Aurelian wrote:

I don't know if it discussed allready, but i'm interested about that: there is a way to synchronize data from mobile terminals directly with a SQL database (without MVC, and without heroku). Is there a way to obtain more information/samples on this issue?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Lars Burgess
Hello,Just marking this

Hello,

Just marking this thread as assumed answered, please reply back if you still have questions.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


CD Aurelian
ohh, Lars - sorry!I managed

ohh, Lars - sorry!

I managed to do what I wanted, it's as much help from your! thanx a lot to everyone.....

when I have questions I will not hesitate to speak to you.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


CD Aurelian
i did a service (web api

i did a service (web api actually) that return a json with data from database (what i want to synchronize) , i make a rhodes (client mobie) and a rhoconnect application.

i just follow the tutorial and i replace the heroku link with my web api link ( the json script). it doesn't work , i don't know what i mistake  and i hope someone to help me.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Robin West
i just follow the tutorial

i just follow the tutorial and i replace the heroku link with my web api link ( the json script). it doesn't work , i don't know what i mistake  and i hope someone to help me.

This probably won't work unless your web service imitates exactly what the rhostore.heroku.com service is doing.  For example, what does your json feed look like?  Does it match the structure exactly as http://rhostore.heroku.com/products.json

You might want to spend some time really understanding the adapter code from the sample: http://docs.rhomobile.com/rhoconnect/source-adapters#sample-adapter

Once you get the hang of ruby and also the library this example uses (RestClient), the ruby code there is pretty straightforward.  One thing that helps me with this type of sample code is dropping into irb and typing in code snippets that I want to understand in more detail.  For example, you can run the following in irb (just  type "irb" at a command prompt, then paste the code below):

require 'json'

require 'rest_client'

@base = 'http://rhostore.heroku.com/products'

body = RestClient.get("#{@base}.json").body

puts body

This will print something like:

"[{\"product\": {\"name\": \"ADIDAS 123\", \"brand\": \"ADIDAS\", \"updated_at\": \"2012-06-12T13:48:23Z\", \"price\": \"123,00\", \"quantity\": \"2\", \"id\": 87231, \"sku\": \"ADD-123\", \"created_at\": \"2012-06-12T13:48:23Z\"}}, {\"product\": {\"name\": \"iPhone\", \"brand\": \"Apple\", \"updated_at\": \"2012-06-12T13:56:57Z\", \"price\": \"199.99\", \"quantity\": \"20\", \"id\": 87232, \"sku\": \"12345\", \"created_at\": \"2012-06-12T13:56:57Z\"}}]"


Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


CD Aurelian
my json returning is

my json returning is something like this:

[

{"Category":"birou","Name":"Masa","Price":120},

{"Category":"Birou","Name":"dulap","Price":250}

]

if i look to herroku i must have something like :

[

{"Product":{"Category":"birou","Name":"Masa","Price":120}},

{"Product":{"Category":"Birou","Name":"dulap","Price":250}}

]

have i right?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Lars Burgess
Your code will also work,

Your code will also work, just change the source adapter code to parse it appropriately.

Vote: 
Vote up!
Vote down!

Points: 1

You voted ‘up’


CD Aurelian
you have right Lars Burgess.

you have right Lars Burgess. everything it's ok. But great care when the service is created: you must have the same property like Rhodes/RhoConnect application:

ex:  if you have a product in rhoconnect  something like : category, price, bran in service you must have the same properties of the small print.

another big point : in my example, the returning of json from api service is domething like that: [{"Category":"birou","Name":"Masa","Price":120}] , and the heroku json is : [{"Product":{"Category":"birou","Name":"Masa","Price":120}}], you must modify in  source adaptor the query method from

JSON.parse(RestClient.get("#{res.headers[:location]}").body)["product"]["id"]

to

JSON.parse(RestClient.get("#{res.headers[:location]}").body)["id"] .

it's not so big deal , but be more careful......

thanks a lot to everyone, especially thank Lars that I strengthened my confidence that I did the right thing.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


CD Aurelian
Lars  explain me one thing: i

Lars  explain me one thing:

i have the following web service link : http://localhost/WebApp/api/products/addproduct/?name=test1&brand=test&price=199&quantity=1&sku=1234523 that return a json like: [{"brand":"test","created_at":"2012-06-11T09:07:54Z","id":28,"name":"test1","price":199,"quantity":1,"sku":"1234523","updated_at":"2012-06-11T09:08:54Z"}] but i don't know hwo to send from client to the source adapter.

my create method is :

def create(create_hash)

    res = RestClient.post(@create,:product => create_hash)

   JSON.parse(

       RestClient.get("#{res.headers[:location]}").body

    )["id"]#["product"]["id"]

    #res.new_id

  end

where create is: @create = 'http://192.168.1.15/WebApp/api/products'#/AddProduct/?Name={name}&Brand={brand}&Price={price}&Quantity={quantity}&Sku={sku}'  .

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Lars Burgess
It looks like your webservice

It looks like your webservice is expecting a GET request instead of a POST? (since all the parameters are part of the url instead of the post body)  You would need to use RestClient.get instead of RestClient.post and then don't have a post body.  Also your code here:

@create = 'http://192.168.1.15/WebApp/api/products'#/AddProduct/?Name={name}&Brand={brand}&Price={price}&Quantity={quantity}&Sku={sku}'

I don't quite follow, are you trying to do an interpolated string where name,brand,price,quantity,sku variables are added to the string?  If so it should be:

@create = "http://192.168.1.15/WebApp/api/products'#/AddProduct/?Name=#{name}&Brand=#{brand}&Price=#{price}&Quantity=#{quantity}&Sku=#{sku}"


Double quotes " and hash-brackets are used to insert variables into a string literal.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


CD Aurelian
Lars i don't understand about

Lars i don't understand about the link and the service.

you told me :" It looks like your webservice is expecting a GET request instead of a POST?" but my attribute of methode in service is :

[WebInvoke(Method = "POST",

RequestFormat = WebMessageFormat.Json,

ResponseFormat = WebMessageFormat.Json,

UriTemplate = "/AddProduct/?name={name}&brand={brand}&price={price}&quantity={quantity}&sku={sku}")]

So it's a POST.

when i append the service from my browser , i'll append with the follwing link:

http://192.168.1.15/WebApp/api/products/AddProduct/?name=testare&brand=test&price=100&quantity=2&sku=3234

and it's work : it add to database my request: testare as name, test as brand etc.

i put "#" to rhoconnect link, it's look like : @create = "http://192.168.1.15/WebApp/api/products/AddProduct/?name=#{name}&brand=#{brand}&price=#{price}&quantity=#{quantity}&sku=#{sku}"

and here is my create methode :

def create(create_hash)

    res = RestClient.post(@create,:product => create_hash)

    #res = RestClient.post(@create)

   JSON.parse(

         RestClient.get("#{res.headers[:location]}").body

       )["id"]

  end

i try to put RestClient.get in create methode but i have the some result.

what it is my wrongs?

I noticed that if i format the create link like :

@create = 'http://192.168.1.15/WebApp/api/products/AddProduct/?name=testname&brand=testbrand1&price=1&quantity=2&sku=3'

and when i make a create, the rhoconnect add o data base the record. so,  the url is wrong and i don't know how to make an url . create_hash add itself what i add in my rhodes form but it don't add my information to the url.

so...? what can i do?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Lars Burgess
[WebInvoke(Method = "POST"

[WebInvoke(Method = "POST",

RequestFormat = WebMessageFormat.Json,

ResponseFormat = WebMessageFormat.Json,

UriTemplate = "/AddProduct/?name={name}&brand={brand}&price={price}&quantity={quantity}&sku={sku}")]

So it's a POST.

The reason I mentioned it looks like a POST is typically a POST will put all the data in the body, not in the URL.  But if you've coded your web service to accept a POST, that's fine, it really doesn't make any difference.

when i append the service from my browser , i'll append with the follwing link:

http://192.168.1.15/WebApp/api/products/AddProduct/?name=testare&brand=test&price=100&quantity=2&sku=3234

and it's work : it add to database my request: testare as name, test as brand etc.

i put "#" to rhoconnect link, it's look like : @create = "http://192.168.1.15/WebApp/api/products/AddProduct/?name=#{name}&brand=#{brand}&price=#{price}&quantity=#{quantity}&sku=#{sku}"

and here is my create methode :

def create(create_hash)

    res = RestClient.post(@create,:product => create_hash)

    #res = RestClient.post(@create)

   JSON.parse(

         RestClient.get("#{res.headers[:location]}").body

       )["id"]

  end

i try to put RestClient.get in create methode but i have the some result.

what it is my wrongs?

I suggest you take a deeper look into your web service code and really understand what it is you're trying to expose for the AddProduct route.  I would suggest not putting these attributes in the URL, instead keep them in the post body and then your code will be simpler in the adapter.  Can you create a record using a basic http tool like curl?  This will also help you craft the matching ruby code that will accomplish the same thing.

Finally, what is the value of "@create" variable when you call RestClient.post?  According to your code above it is initialized somewhere else, maybe do a

puts @create.inspect

before you call RestClient.post and see what @create looks like.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


CD Aurelian
you are right Lars. Give to

you are right Lars. Give to Caesar what is Caesar's : if it's a POST let's to be a POST ....

my create link must be

@create = "http://192.168.1.15/WebApp/api/products/AddProduct

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments