Archive

Archive for November, 2008

LBS: OpenCellID

November 30th, 2008 rupert Comments off

Picture 1.png
Figure 1. CellIDs for Manila taken from opencellID.org

http://mobiforge.com/developing/story/adding-location-a-non-gps-phone-introducing-opencellid

Interesting to see there was an opensource initiative to map cellIDs. Don’t know if Google made the same process for Google Maps MyLocation but I guess its very similar. Would it be possible to integrate such technology for SMS/USSD Development? Meaning when a mobile request to a back end system, the cellID would be included in the header before being passed to the application. I am fully aware this process is possible, however, I’m wondering if it is possible without installing any application (most likely j2me) on the mobile?

Categories: mobile Tags:

Rails Note #11: TDD and Loading Development Fixtures for Testing

November 25th, 2008 rupert Comments off

Here is a brief outline on how I am doing test driven development personally.

1. Code up tests/functional/foo_controller_test.rb until you know what you expect from the method. Make the test method as self explanatory as much as possible.

def test_goto_restaurant_next
end

2. Imagine how the URL parameters will be passed to the controller.

get :goto, 'WHOISD-ABONENT'=> MOBILE_NUMBER, :categ_id => '123', :node_id => '10', :page => '2'

3. At this point. It gets too exciting to code up the controller itself. Hold on, try to make an assertion on a variable that we will use in the view.

assert_equal assigns("sub_menus").length, 2

4. Code the controller

5. Code the view

6. Test from the browser.

7. Refactor the testcase and make more assertions.

8. Run the testcase

Now, it could be very hard to execute the tests if you don’t have the same development data inside your testing database. I found a good tip from the Rail’s Way book, and used ar_fixtures.

For whatever reason, dumping data to fixtures is not a part of core Rails. Considering that Rails gives you a to_yaml method on ActiveRecord models and Hash objects, it wouldn’t be too hard to write your own Rake task. However, it’s not necessary to do so because of a well-proven plugin written by Geoff Grosenbach. It’s called ar_fixtures and you can install it with the following command:

$ script/plugin install http://topfunky.net/svn/plugins/ar_fixtures

Once the plugin is installed, dumping a fixture is a simple matter of invoking a new rake task called rake db:fixtures:dump. Unlike the built-in loading rake task, this one takes a MODEL parameter with the name of the ActiveRecord class that you want to dump data for:

$ rake db:fixtures:dump MODEL=BillingCode
Categories: rails Tags: , ,

Rails Note #10: Generating XML

November 25th, 2008 rupert Comments off

This post should have made it a looong time ago..

I am currently building an application where all the output formats is in XML. One of the first problems I had was to output the xml.

1. At first try, I could append ‘xml’ in the routes as a format parameter. But this takes into consideration that all our views would be in XML. However, you could have your views to be index.xml.erb or index.rxml, if you are using the builder templates plugin.

ActionController::Routing::Routes.draw do |map|
  #map.connect '/menu/show.xml', :controller => 'menu', :action => 'show', :format => 'xml'
 
  map.connect ':controller/:action/:id', :format => 'xml'
  map.connect ':controller/:action/:id.:format', :format => 'xml'
end

2. If my application requires me to output both html and xml, then the above would not be sufficient. In my controller, I have to explicitly say :layout => false which means it would not use the application.html.erb found in app/views/layouts if we have one.

So far, I made progress using builder templates only but it is enough to suit my needs. Below is a sample controller and view.

app/controller/mobile_controller.rb

def index
  headers['Content-Type'] = 'text/xml; charset=utf-8'
  render :layout => false
end

app/views/index.rxml

xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
xml.content :type => "hypertext" do
 
xml.head do
  xml.pageID "1"
  xml.title "USSD Page from Ruby"
  xml.protocol "html,java,wap,ussd,xhtml"
end
 
xml.body {        
  greeting = 'Welcome back!'
  xml.p greeting
}
 
end
Categories: rails Tags:

Long Time No Trac

November 25th, 2008 rupert Comments off

Its been a while I haven’t setup an svn repository for SCM. Anyhow, here are the steps just in case I forget again and again…

1. Add a new trac setting in /etc/apache2/sites-available/default

 

2. Copy a template

cp -Rf /var/www/trac/trac-template /var/www/localdumplings

3. Restart Apache2

4. Resync the repository

trac-admin localdumpling resync
Categories: Uncategorized Tags:

Rails Note #9: Getting HTTP Headers

November 20th, 2008 rupert Comments off

1. I was trying to get the http headers dump from a mobile phone. So I quickly dump it in a log file to see its contents..

    headers['Content-Type'] = 'text/xml; charset=utf-8'
    for header in request.env.select {|k,v| k.match("^HTTP.*")}
        logger.info(header[0].split('_',2)[1] + ":" + header[1])
    end

Reference:
http://tonycode.com/wiki/index.php?title=Dumping_HTTP_Headers

2. However, please note that you can actually see everything from the request as parameters.

Parameters: {“MSAG-ADDRESS-PREFIX”=>”aSTARTa”, “format”=>”xml”, “protocol”=>”ussd”, “user-agent”=>”Jakarta Commons-HttpClient/3.0.1″, “WHOISD-ABONENT”=>”8613520747210″, “action”=>”menu”, “controller”=>”ussd”, “subscriberID”=>”8613520747210″, “WHOISD-USR”=>”-1″, “host”=>”wap.watago.mobi”, “WHOISD-USSD-MESSAGE”=>”", “content-length”=>”0″}

This means we can easily do..

@whoisd_abonent = params['WHOISD-ABONENT'] || nil
Categories: rails, ruby Tags: ,