Saturday, November 27, 2010

Building rhodes application for Blackberry


In this blog we will learn to build rhodes application for Blackberry:

Step 1.) You have to purchase  Blackberry JDE Signature Keys. As you have to sign application before loading it to device. You can purchase this from :


This will cost you around 20 US doller.  Signature files can be only registered once per computer. 

Note : You have to enter PIN while filling a form. Please remember this PIN as it will be used later

Step 2.) You will recive 3 .CSI from blackberry. Download this files.

Step3.)  Creating sigtool.csk and sigtool.db files

i)   Double-click on the attachment.
ii)   If a dialog box appears that states that a private key cannot be found, complete steps 3 through 6 before you continue. Otherwise, proceed to step vii.
iii)   Click "Yes" to create a new key pair file.
iv)   Type a password for your private key of at least viii characters, and type it again to confirm.  This is your private key password, which protects your private key. Please remember this password as you will be prompted for it each time signing is attempted or a signature key is installed.
v)   Click "Ok"
vi)   Move your mouse to generate date for a new private key.
vii)   In the "Registration PIN" field, type the PIN number that you supplied on the signature key order form.
viii)   In the Private Key password field, type the password created in step iv.
ix)   Click "Register".
x) Click "Exit".
11) Repeat this process for the other .csi files.

Once this process is complete sigtool.csk and sigtool.db files will be created in bin directory of your Blackberry JDK


Step 4.)Then you can provide password in rhobuild.yml file (located in the Rhodes SDK folder)
build:
   bbsignpwd:

Step 5.) Run this code in your application directory

rake device:bb:production

Step 6.)Now you can check your build in

OTA: /bin/target

You should see many .cod files and one .jad file
Upload all of those files to a web server, then open the .jad file from the browser on your blackberry device

Wednesday, November 10, 2010

Start Rhosync server on specific port

If you run "rake rhosync:start" by default it will start on port 9292. This command call 'rackup config.ru' without specifying the port
To start Rhosync server on Specific Port you can use 


rackup -p <port> config.ru 


Example : rackup -p 80 config.ru 

Wednesday, October 27, 2010

Create a Rhodes application which will sync data from rails application using Rhosync

In this blog we will create a Rhodes application which will synchronize your data from rails application through Rhosync.
We need to create 3 applications
  1. Rails Application: It will feed data in json or XML format.
  2. Rhodes Application: This code will be installed in mobiles.
  3. Rhosync Application: These will sync the data from rails App to Rhodes Application in your phone
Steps to create rails Application:
I will just create a rails application using scaffold:
  1. rails employee_details
  2. cd employee_details
  3. Ruby script/generate scaffold employee name:string phno:integer address:text
  4. Update your database.yml 
  5. Rake db:migrate
  6. Add these code in your employees controller (you can skip this step if you want to only show employee details and does not do crud operations.)
              protect_from_forgery :except => [:create, :update, :delete]
    
    7. Add this line under response in controller:
             
             format.json { render :json => @employee }

    8. Once it is done we will run it on port 3000:

              http://localhost:3000\employees.json

         we will get output in json format.


Steps to create Rhodes application:
  1. Rhogen app employee
  2. Cd employee
  3. Rhogen model employee name,phno,address
  4. Add link in index.erb to your index page
  5. Enable sync in model Employee  
                enable :sync


    6.   Edit rhoconfig.txt file and set
             syncserver = 'http://localhost:9292/application
    7.    rake run:bb


Steps to create Rhosync application:
  1. Rhosync app employee_server
  2. Rhosync source employee
  3. Then employee.erb incude json and rest client
          require 'json'
          require 'rest_client'

     4. Update the query method

  def query(params=nil)
    parsed=JSON.parse(RestClient.get("http://localhost:3000/employees.json").body)
    @result={}
    parsed.each { |item|@result[item["employee"]["id"].to_s]=item["employee"] } if parsed
    @result
  end

Now you can test this by login to your simulator.





Tuesday, October 12, 2010

Bug in rhodes-translator- 0.0.1 template

As metadata in Rhodes is very new, few of the templates in rhodes_translater gem has bugs.
I tried to use select box using metadata. But it's field was not saving the field value.
There is small bug in select.rb in rhodes_translator gem so I modified this file. So to fixed this issue:
Replace the file select.rb in
C:\Ruby187\lib\ruby\gems\1.8\gems\rhodes-translator- 0.0.1\lib\rhodes_translator\templates

with this new select.rb
(Download it from link below)


Saturday, October 9, 2010

Creating a Rhodes Application which will synchronize your tweets to your phone

In this blog I will create a Rhodes application which will sync your tweets through rhosync.

I am currently using Rhodes 2.1.0 and Rhosync 2.0.6.

If you want to some complex operation you can read twitter API docs:

http://dev.twitter.com/doc/get/statuses/user_timeline

Step 1.) Create a Rhodes Application

1.) Go to command prompt and create Rhodes application

>rhogen app twitter-api

>cd twitter-api

>rhogen model twitter text

2.) Now update index.erb( Adding a link to index page of Twitter controller

link_to “Twitter”, :controller => :Twitter


3.) Enable sync in Twitter model.

Update twitter.rb and add the following line

enable sync

4.) Update rhoconfig.txt(Setting the path for rhosync server)

syncserver = ‘http://localhost:9292/application’

5.) Start the simulator

rake run:bb

Step 2.) Create Rhosync Application

1.) Go to command promt

>rhosync app twitter –server

> cd twitter-server

>rhosync source twitter

2.) Update the source adapter twitter.rb

require ‘json’

require ‘open-uri’

Add this code in query method:

def query(params=nil)

parsed=""

open('http://api.twitter.com/1/statuses/user_timeline.json?screen_name=nalwayaabhishek') do |f|

parsed=JSON.parse(f.read)

end

@result = {}

parsed.each do |item|

item_hash = {}

item_hash['text'] = item['text']

@result[item['id'].to_s] = item_hash

end

@result

end

3.) Start redis server

rake redis:start

4.) Start rhosync server

rake rhosync:start

By default it will start on port 9292.


Once the simulater is started Login with any username and password. And sync the data.

Now you can see your tweets even if you are offline.

Thursday, September 30, 2010

Nokogiri HTML and XML parser

Nokogiri gem, a new HTML, XML, SAX and Reader parser for Ruby.

It parses and searches XML/HTML faster than Hpricot(Hpricot being the current de facto Ruby HTML parser) and boasts XPath support, CSS3 selector support (a big deal, because CSS3 selectors are mega powerful) and the ability to be used as a "drop in" replacement for Hpricot.

On an Hpricot vs Nokogiri benchmark, Nokogiri clocked in at 7 times faster at initially loading an XML document, 5 times faster at searching for content based on an XPath, and 1.62 times faster at searching for content via a CSS-based search.

Here is the example :

require 'nokogiri'

require 'open-uri'

# Get a Nokogiri::HTML:Document for the page we’re #interested in...

doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))

#Do funky things with it using Nokogiri::XML::Node methods...

# Search for nodes by css

doc.css('h3.r a.l').each do |link|

puts link.content

end

####

# Search for nodes by xpath

doc.xpath('//h3/a[@class="l"]').each do |link|

puts link.content

end

####

# Or mix and match.

doc.search('h3.r a.l', '//h3/a[@class="l"]').each do |link|

puts link.content

end

Source : http://nokogiri.org/


Saturday, September 25, 2010

My libraries in lib folder is not loading for Rails3..

My libraries in lib folder is not loading for Rails3!!!

Is it a bug?...NO

In Rails 3 it does not automatically load files in lib folders. . If you create any module/class in lib folder and try to use it, the server will throw an "uninitialized constant Modulename (NameError)". You have to manually include the modules which you want to use.


The possible reason for this behaviour is:

  • This makes a Rails application behave more closely to any Ruby project, leaving the autoload to directories specific to Rails .
  • Increasing performance.
  • Autoloading in lib was always causing some pain, since some people had files like "employee.rb" but there was no "employee" module defined it.

There is solution to unable this feature again:

Put this in application.rb

config.autoload_paths += %W(#{config.root}/lib)

config.autoload_paths += Dir["#{config.root}/lib/**/"]

Wednesday, August 18, 2010

Rhodes Installation

Installing Rhodes(Rhomobile)
These are the steps to install rhodes
Step 1 : Install Ruby: Better download window installer for Ruby 1.8.6 or 1.8.7. I am using ruby 1.8.7 and it work good for me. You can download it from http://www.ruby-lang.org/en/downloads/
Note : Don’t forget to add ruby to your path(It will ask you while installing ruby). You can test it from command prompt by typing ruby -v
Step 2: Install rubygems: Any version above 1.3.5 will work
Step 3: Install GNU : Install GNU for windows so that commands like make etc can work. You can download it from http://gnuwin32.sourceforge.net/packages/make.htm for windows. For Linux and Mac it will be already installed.
Step 4: Install JDK : Install JDK version 1.6.0_2 or higher. You can download it from http://www.oracle.com/technetwork/java/javase/downloads/index.html
Make sure you set JAVA_HOME and that JAVA_HOME/bin is on your path.
Major issues which may prompt are:
--If you get any "no such file to load -- something" messages while running the rake tasks or rhogen commands, this can usually be resolved by running '[sudo] gem install something'.
-- If your libintl3.dll is not loaded then download it by googling and put in bin folder.
Step 5 : You can install Rhodes in two ways
- Download it from git
- Download it as gem
I will prefer download it as gem. Just type on command prompt
gem install rhodes
Step 6: Install Simulator : Install the simulator of the phone for which you want to build application
1.) Blackberry : You can download the latest version of simulator from the following URL : https://www.blackberry.com/Downloads/entry.do?code=060AD92489947D410D897474079C1477
2.) Iphone: You can install it from apple website. But it will work on apple machine.
3.) Android : You can download the latest version of simulator from the following URL :
You are ready to create your first application.

Thursday, August 12, 2010

Rhodes Framework


The Rhodes is a microframework based on ruby and it is used to develop rapidly NATIV apps for Mobiles. The best thing which I like about Rhodes is that we have to develop the application once and it can be build for all major Phones. It is currently supported for Blackberry, Iphone, Android, Windows Mobile, RIM and symbians. It generates pure native apps but if we check the code it is pure html and ruby. It work with synchronized local data and take advantage of device capabilities such as GPS, PIM contacts and camera.

The Advantages of Rhodes is :

· support for ALL smartphones

· Open source

· synchronized offline data

· a Model View Controller (MVC) framework

· an Object Relational Manager (ORM) to avoid direct SQL coding

· Available as Ruby gem and also available on github for download

· Portable

· Productive

· Support and community

· Codes is similar to Rails

· Can write Unit Test cases using specs

It is product of Romobile. The major product of rhomobile are Rhodes ,RhoSync and RhoHub.

RhoSync

RhoSync is a standalone server which keeps enterprise application data current and available on users’ smartphones. The information is stored locally on a user’s device and available to him even when disconnected and offline.


RhoHub

Easy hosted development for mobile apps. It is very much similer to Heroku. RhoHub offers a hosted development environment for mobile applications. It is built on top of Rhodes and RhoSync. It allows developers to write native apps in HTML and Ruby using their web browser and then build these apps without installing device SDKs.


To know more about Rhodes watch this video :