Is there a method to know the RhoConnect app_endpoint from a source adapter?

In my Rails application, I'm using rhoconnect-rb with this configuration:

Rhoconnect.configure do |config|

  config.uri          = "http://localhost:9292"

  config.token        = "30d8f4315d774eff87c06a656d379b88"

  config.app_endpoint = "http://localhost:3000"

end

Is there a method to know the RhoConnect app_endpoint from a source adapter?

By the way, I wrote a source adapter (MySourceAdapter) that matches Rails default API, the usage is something like:

class Company < MySourceAdapter

end

And it's ready to go with a Rails application. It lightly depends on activesupport gem

Do you think that it's helpful/contributable?

Darryn Campbell
You can get app_endpoint by

You can get app_endpoint by calling Rhoconnect.appserver method

Vote: 
Vote up!
Vote down!

Points: 1

You voted ‘up’


Lars Burgess
If you're using rhoconnect-rb

If you're using rhoconnect-rb plugin, you don't need to write any source adapters.  Just fire up a vanilla rhoconnect app (that has no adapters) and connect your rails application's rhoconnect-rb plugin to it.

http://docs.rhomobile.com/rhoconnect/rails-plugin

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Juan Pastas
When I comment my source

When I comment my source adapters, I get this in RhoConnect console:

Failure to create adapter from class Company: #<Exception: Please provide a :token or set it in uri>

Please provide a :token or set it in uri/Users/adiaz/.rvm/gems/ruby-1.9.3-p194/gems/rhoconnect-3.2.0/lib/rhoconnect/dynamic_adapter.rb:23:in `initialize'

This is what I've done:

1. run rhoconnect get-token in my RhoConnect application folder,

2. copy ~/.rhoconnect_token contents config/initializers/rhoconnect.rb in my Rails application folder (I had it wrong set)

3. restart RhoConnect instance

4. restart Rails application

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Maxim Zverev
Please, upgrade your

Please, upgrade your rhoconnect to 3.2.1 at least. 3.2.0 has a bug in the plugin initialization section which was fixed in 3.2.1.

Max.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Juan Pastas
Upgraded to 3.2.1, but same

Upgraded to 3.2.1, but same error.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Maxim Zverev
You need to change the

You need to change the version of RhoConnect in your app's Gemfile from 3.2.0 to 3.2.1, then run 'bundle install'.

Just installing the new gem is not enough.

Max.

Vote: 
Vote up!
Vote down!

Points: 1

You voted ‘up’


Juan Pastas
Ok, already done that,

Ok, already done that, because I'm getting this:

Please provide a :token or set it in uri/Users/adiaz/.rvm/gems/ruby-1.9.3-p194/gems/rhoconnect-3.2.1/lib/rhoconnect/dynamic_adapter.rb:23:in `initialize'

Although the new version is used, the problem stills.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Maxim Zverev
Please, check if you see your

Please, check if you see your Rails's app endpoint in the app's web-console (http://localhost:9292/console/) and it's correct. Also, check the rhoconnect's app log to see that /save_adapter method called by your Rails app and it was succesfull (i.e. returned 200).

Another thing: when you said that you have commented your source adapter, did you also comment them out in the settings.yml file (:sources setting)?

Max.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Juan Pastas
Please, check if you see your

Please, check if you see your Rails's app endpoint in the app's web-console (http://localhost:9292/console/) and it's correct.

I can't see my Rails's endpoint in the console where exactly it appears?

Also, check the rhoconnect's app log to see that /save_adapter method called by your Rails app and it was succesfull (i.e. returned 200).

I think it's ok:

127.0.0.1 - - [13/Jul/2012 19:02:39] "POST /api/source/save_adapter HTTP/1.1" 200 21 0.0359

Another thing: when you said that you have commented your source adapter, did you also comment them out in the settings.yml file (:sources setting)?

I tried both ways and having the same problem:

Failure to create adapter from class Company: #<Exception: Please provide a :token or set it in uri>

Please provide a :token or set it in uri/Users/adiaz/.rvm/gems/ruby-1.9.3-p194/gems/rhoconnect-3.2.1/lib/rhoconnect/dynamic_adapter.rb:23:in `initialize'

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Maxim Zverev
You can check the Rails

You can check the Rails endpoint in the Web Console - Settings -> Plugin Settings -> Backend App URL.

If this setting is empty - then, initialization was not completed properly.

Max.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Juan Pastas
Is correctly set to http:/

Is correctly set to http://localhost:3000.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Darryn Campbell
Then, please check that the

Then, please check that the token is the same in the Settings -> API Token

Max.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Juan Pastas
token is the same in rails

token is the same in rails/config/initializers/rhoconnect.rb and in RhoCnnect web console.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Maxim Zverev
One more thing: you need to

One more thing: you need to put the api token into the settings.yml file into the correcponding config section, like:

:development:

     :api_token: my_token

Reason is: In case of dynamic adapters - you need to have static token (since it needs to be the same in Rails app and RhoConnect and doesn't vary on restarts). So, you do not need to get the token like you did by copying the randomly generated token into the Rails app (because it will vary on every redis restart). What you need is to set one up statically in the settings.yml and then use it in your Rails app initializers.rb.

Max.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Juan Pastas
Thanks, that changed the

Thanks, that changed the error by:

SourceAdapter raised query exception: 404 Resource Not Found: error on method `rhoconnect_query` for Company: undefined method `rhoconnect_query' for #<Class:0x007fd5fb61b1a0>

Any advice?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Maxim Zverev
It looks like you didn't

It looks like you didn't implement mandatory 'rhoconnect_query' in the Company model of your Rails app.

http://edgedocs.rhomobile.com/rhoconnect/rails-plugin#querying-datasets

Max.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Juan Pastas
Thanks, I've missed and fixed

Thanks, I've missed and fixed that.

Now, although RhoConnect console doesn't show any error, the mobile simulator doesn't synchronize, what could it be?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Maxim Zverev
Did you properly setup

Did you properly setup partition method? If your source is partitioned by user (which is the default), then, you need to partition your Rails app to use the same user_id. Otherwise, you won't see any data.

For example:

Your device has logged in with user "testuser". In this case, your "partition" method in the model of the Rails app must return "testuser".

For example:

def partition

     "testuser"

end

In this case, you will see the data (if you're logged in as "testuser"). Other users won't see anything.

Naturally, above example is very primitive (since partition method in real life should return current user dynamically).  Look here for partitioning:

http://edgedocs.rhomobile.com/rhoconnect/rails-plugin#partitioning-datasets

Max.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Juan Pastas
RhoConnect partitioning

RhoConnect partitioning:

Company:

    :poll_interval: 300

    :partition_type: app

Rails model:

class Company < ActiveRecord::Base

...

def partition

    :app

  end

...

def self.rhoconnect_query(partition = nil)

    all

  end

This is the partition method I'm using, is something missed here?

Thanks for helping me.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Maxim Zverev
Please, log the objects to

Please, log the objects to see if there are any, for example:

def self.rhoconnect_query(partition)

     res = all

     puts " res is #{res.inspect}"

     res

end

Max.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Juan Pastas
I do Company.rhoconnect_query

I do Company.rhoconnect_query in Rails console, and shows me all the companies I've added.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Maxim Zverev
Set poll_interval to 0 - this

Set poll_interval to 0 - this will ensure that every time you call Sync, it will go to your Rails app.

Also, do you have "enable :sync" in your Rhodes app/Company/company.rb?

Flush the db to make sure everything is clean, re-start rhoconnect, then, Rails app.

Also, please post the rhoconnect log.

Max.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Juan Pastas
Thanks for your help, Its

Thanks for your help, Its working now. Did not make your last post suggestions.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments