10 Replies Latest reply on Aug 15, 2012 7:11 AM by Divyansh Madan

    Rho::RhoEvent Calendar API

      Hey,

      I want to create an event ased on the selection of a date and time,but somehow I am not able to do that.I referenced http://docs.rhomobile.com/rhodesapi/rhoevent-api but I am somehow confused about the syntax.What I want to do is,I want to use a data stored in my database as string and on selection,I want to use that to create an event.

       

      Any help would be appreciated.

       

      Thanks,

      Divyansh

        • Re: Rho::RhoEvent Calendar API

          Ok, let's assume that you've already got your strings from the DB, so here's a little mockup to get us started:

           

          #initial data

          title = "Test title";

          notes = "Test Notes";

          start_date = Time.new(2012, 8, 13, 12, 00, 00);

          end_date = Time.new(2012, 8, 14, 12, 00, 00);

          location = "Test Location";

           

          #init the event

          event = Hash.new();

          event[Rho::RhoEvent::TITLE] = title;

          event[Rho::RhoEvent::NOTES] = notes;

          event[Rho::RhoEvent::START_DATE] = start_date;

          event[Rho::RhoEvent::END_DATE] = end_date;

          event[Rho::RhoEvent::LOCATION] = location;

           

          #create the entry in the calendar

          created_event = Rho::RhoEvent.create!(event);

          #take a look at what we just entered

          created_event.inspect;

           

          If you're also stuck with recurrence, let me know.

            • Re: Rho::RhoEvent Calendar API

              I have the title, start date and the end date in the db in form of string ,so I dont know how to put the string in the form start_date = Time.new(2012, 8, 13, 12, 00, 00);...are you using anything from the databse...?

                • Re: Rho::RhoEvent Calendar API

                  If the string is already in a proper TIMESTAMP column, then you should be able to just pass the value in to the event[Rho::RhoEvent::START_DATE] key.

                  If not, you'll need to pull the string in and use string.split().

                   

                  The last time I had to do this, I had an improper timestamp field in the db (someone used varchar for some ridiculous reason) that was something like: "08-13-2012 12:00:00".

                   

                  So lets assume that you DO have an improper timestamp field from the DB, and that you already have it loaded into a string. We're just going to use my above example:

                   

                  #get value from db

                  #

                  #your db retrieval code here. might have to re cast your result to a string

                  #

                  #so we'll end up with a variable holding the string result from the query, lets assume the following:

                  db_start_date = "08-13-2012 12:00:00"

                  splits = db_start_date.split(' ');

                  #splits after this is: ["08-13-2012", "12:00:00"]

                  date_splits = splits[0].split('-');

                  #date_splits after this is: ["08", "13", "2012"]

                  time_splits = splits[1].split(':');

                  #time_splits after this is: ["12", "00", "00"]

                   

                  Now, we have split strings containing the individual date and time values. If you wanted to make this ultra readable, you could load everything up in a properly named hash, but that's kind of redundant at this point. We can just throw these values into the Time.new() call now:

                   

                  start_date = Time.new(date_splits[2], date_splits[1], date_splits[0], time_splits[0], time_splits[1], time_splits[2]);

                  event[Rho::RhoEvent::START_DATE] = start_date;

                   

                   

                  disclaimer: I've been coding php for the last 3 hours. apologies for any ruby syntax errors.

                    • Re: Rho::RhoEvent Calendar API

                      I am calling a method in my app and the following is written in that method

                      #init the event

                          event = Hash.new()

                          title = "Test title"

                          notes = "Test Notes"

                          location = "Test Location"

                          db_start_date = "08-13-2012 12:00:00"

                          splits = db_start_date.split(' ')

                          #splits after this is: ["08-13-2012", "12:00:00"]

                          date_splits = splits[0].split('-')

                          #date_splits after this is: ["08", "13", "2012"]

                          time_splits = splits[1].split(':')

                          #time_splits after this is: ["12", "00", "00"]

                          start_date = Time.new(date_splits[2], date_splits[1], date_splits[0], time_splits[0], time_splits[1], time_splits[2])

                      db_end_date = "08-13-2012 13:00:00"

                          splits = db_close_date.split(' ')

                          #splits after this is: ["08-13-2012", "12:00:00"]

                          close_date_splits = splits[0].split('-');

                          #date_splits after this is: ["08", "13", "2012"]

                      close_time_splits = splits[1].split(':')

                          #time_splits after this is: ["12", "00", "00"]

                          close_date = Time.new( close_date_splits[2],  close_date_splits[1],  close_date_splits[0],  close_time_splits[0],  close_time_splits[1],  close_time_splits[2])

                          event[Rho::RhoEvent::TITLE] = title

                          event[Rho::RhoEvent::NOTES] = notes

                          event[Rho::RhoEvent::START_DATE] = start_date

                          event[Rho::RhoEvent::END_DATE] = end_date

                          event[Rho::RhoEvent::LOCATION] = location

                          

                          #create the entry in the calendar

                          created_event = Rho::RhoEvent.create!(event)

                          #take a look at what we just entered

                          created_event.inspect

                         

                      redirect :action => :index

                       

                      but its keeps on giving "error loading page"...in the log it gives an error App error:Can't convert string into exact number.

                        • Re: Rho::RhoEvent Calendar API

                          You'll need to recast the array vals with to_i()

                            • Re: Rho::RhoEvent Calendar API

                              now it shows "arguement out of range"...App error...

                                • Re: Rho::RhoEvent Calendar API

                                  Argh, you're killing me here man.

                                   

                                  That code is a general gist of what you need to do, no guarantees it's going to work for you. How well do you know ruby, and how adept are you at using the api and core online reference? These two resources will provide far more information than I have the patience to type in a forum.

                                   

                                  Here's the fixed code: There were 2 array values that were reversed. I've also added a line or two for inspecting. You can dump the event, but I like keeping instance vars descriptive for whichever poor soul has to maintain what we write.

                                   

                                      event = Hash.new()

                                      title = "Test title"

                                      notes = "Test Notes"

                                      location = "Test Location"

                                      db_start_date = "08-13-2012 12:00:00"

                                      splits = db_start_date.split(' ')

                                      #splits after this is: ["08-13-2012", "12:00:00"]

                                      date_splits = splits[0].split('-')

                                      #date_splits after this is: ["08", "13", "2012"]

                                      time_splits = splits[1].split(':')

                                      #time_splits after this is: ["12", "00", "00"]

                                      start_date = Time.new(date_splits[2].to_i, date_splits[0].to_i, date_splits[1].to_i, time_splits[0].to_i, time_splits[1].to_i, time_splits[2].to_i)

                                      db_end_date = "08-13-2012 13:00:00"

                                      #splits = db_close_date.split(' ')

                                      #splits after this is: ["08-13-2012", "12:00:00"]

                                      close_date_splits = splits[0].split('-');

                                      #date_splits after this is: ["08", "13", "2012"]

                                      close_time_splits = splits[1].split(':')

                                      #time_splits after this is: ["12", "00", "00"]

                                      close_date = Time.new( close_date_splits[2].to_i,  close_date_splits[0].to_i,  close_date_splits[1].to_i,  close_time_splits[0].to_i,  close_time_splits[1].to_i,  close_time_splits[2].to_i)

                                      event[Rho::RhoEvent::TITLE] = title

                                      event[Rho::RhoEvent::NOTES] = notes

                                      event[Rho::RhoEvent::START_DATE] = start_date

                                      event[Rho::RhoEvent::END_DATE] = close_date

                                      event[Rho::RhoEvent::LOCATION] = location

                                   

                                      #create the entry in the calendar

                                      created_event = Rho::RhoEvent.create!(event)

                                      #take a look at what we just entered

                                      @event_status = created_event.inspect

                                      render :action => :someoutputpage;

                                   

                                   

                                  note: I tested this code this time. It should work.