Talking in Pictures

A blog about visual communication

ScreenSteps Desktop 2.7 Now Available! Download ScreenSteps 2.7

Posts Tagged ‘Ruby’

The ScreenSteps Live API Ruby Wrapper

Today we have released a new Ruby wrapper for interacting with the ScreenSteps Live API using ActiveResource. The video below shows some examples of using the wrapper in the console. The API will let you:

  • Retrieve spaces, manuals, buckets and lessons
  • Search spaces, manuals and buckets
  • Get lessons for a given tag in a space, manual or bucket
  • Create tasks in your ScreenSteps Live account

We hope that this will make it easier for Rubyists to integrate ScreenSteps Live with their Ruby applications.

You can download the latest version of the library at GitHub: http://github.com/bluemango/ScreenSteps-Live-API-Ruby-Wrapper

Several of the ideas for setting up the library were taken from the Batchbook ruby library.

Bookmark and Share

Creating a New Person in BatchBook Using the Ruby Batchbook API Wrapper

We have recently been migrating from Highrise to Batchbook for our CRM software. Though Batchbook isn’t nearly as pretty as Highrise, it has some killer functionality in regard to integration with other services we use as well as a pretty slick way for adding custom data fields. It also has an API that makes it easy to integrate with our existing apps.

The API has a Ruby wrapper so it should be a snap to implement. Except that there was a documentation failure. It wasn’t that the documentation was bad. It just wasn’t there. So here are a couple of examples to help anyone who might be using the Ruby wrapper. Hopefully this will save you a few hours of scratching your head.

The Ruby wrapper uses ActiveResource, which is pretty slick. The good thing about this endeavor was that I learned a lot more about ActiveResource which I hadn’t really paid attention to until now.

Setup

To start using the library all you need to do is [download the batchbook.rb file](http://github.com/batchblue/batchbook) and stick it somewhere in your app. I add it to the `lib/` directory.


Fix Settings

The current version of the batchbook.rb file on github has localhost as the domain. You won’t have much luck accessing the API at the localhost:3000 domain. Hopefully they will update this soon, but if they haven’t just change the batchbook.rb file on lines 41-44 to look like this:

 self.host_format = '%s://%s/%s'
 self.domain_format = '%s.batchbook.com'
 self.path = 'service'
 self.protocol = 'https'

Start Using

To start messing around with this I just run script/console from the terminal to get into my Rails app. Then enter:

require 'batchbook'
BatchBook.account = 'your_account'
BatchBook.token = 'your_api_key'

Creating a New Person With an Email

Creating a person is easy enough.

person = BatchBook::Person.new person.first_name = ‘john’ person.last_name = ‘doe’

But what if you want to add an email address? This WON’T work:

person.email = 'john@mail.com'

That is because Batchbook has this concept of locations. So a person doesn’t have an email address. They have a location labeled “work” which has email, phone, city, etc.

So to add that email address, do this:

location = BatchBook::Location.new
location.label = 'work' ## You need this line or it won't save
location.email = 'john@mail.com'

Now, before you call location.save you need to do one very important thing. The location is a nested attribute of the person, so you need to add a path prefix option. Do this:

If you haven’t already saved your person, do so. This will assign an ID to the person object, which you are going to need.

person.save

ActiveResource then posts the information to http://youraccount.batchbook.com/services/people.xml

Now add the prefix option to the location.

location.prefix_options[:person_id] = person.id

This is part of ActiveResource and will add a prefix onto the url. If you don’t add the prefix, ActiveResource posts to /services/locations.xml. That isn’t what you want. The API needs to get a POST to /services/people/#{the_id_of_the_person}/locations.xml. By adding the prefix_option person_id we tell ActiveResource to add the people/#{the_id_of_the_person} to the front of the locations url.

Now just save.

location.save

That’s it. In hindsight it makes sense. But it sure had me confused last night.

Webinar: Why Your Documentation is Useless and How to Fix It
Download the free webinar to learn why your documentation/knowledge base is ineffective and what simple steps you can take to improve it.
Bookmark and Share

Cancel Forms And Avoid The If Then Statements

One of the big pains with Rails form helpers is that they don’t have a cancel button. No, problem – that is easy enough to add in. Just use a second submit tag like so:

            <%= f.submit "Create" %>
            <%= submit_tag "Cancel" %>

Now, if the user clicks the “Cancel” button a “commit” param with a value of “Cancel” will be submitted.

This is nothing earth-shattering. I have found this technique on various blogs. But then they all suggest checking for this parameter in the update or create method of your controller. I don’t like this because it makes you add in extra “if-then” statements. I really hate “if-then” statements. They make the code so much harder to read.

So what to do?

Use a before filter.

before_filter :check_for_cancel, :only => [:create, :update]

Then add in your method to check for the cancel parameter in the commit message.

  private

  def check_for_cancel
    if params[:commit] == "Cancel"
      redirect_to admin_spaces_path
    end
  end

That’s it. So now, if anyone clicks on the “Cancel” button on an edit or new form they will be redirected to the index.

If you really wanted to you could make the Cancel button submit the cancel parameter as part of the model hash. You would do it like this:

            <%= submit_tag "Cancel", :name => "model[cancel]" %>

You would just need to update your check_for_cancel method to check for that param. I prefer the previous method though since it is more generic.

Bookmark and Share
Screensteps Support Suite

ScreenSteps is the most effective tool for creating and delivering customer tutorials and guides.
Learn about the ScreenSteps Support Suite