Skip to content

Instantly share code, notes, and snippets.

@probablykabari
Created December 15, 2011 02:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save probablykabari/1479603 to your computer and use it in GitHub Desktop.
Save probablykabari/1479603 to your computer and use it in GitHub Desktop.
Example of using the survey-gizmo-ruby gem
require 'survey-gizmo-ruby'
# somewhere in your app define your survey gizmo login credentials.
SurveyGizmo.setup(:user => 'you@somewhere.com', :password => 'mypassword')
# get al resources
surveys = SurveyGizmo::API::Survey.all
questions = SurveyGizmo::API::Question.all(:survey_id => 12345)
# get a single resource
survey = SurveyGizmo::API::Survey.first(:id => 12345)
survey.title # => My Title
survey.pages # => [page1, page2,...]
survey.pages.first.questions # => [question1, question2,...]
# create a resource
question = SurveyGizmo::API::Question.create(:survey_id => survey.id, :title => 'Do you like ruby?', :type => 'checkbox')
# update a resource
question.title = "Do you LOVE Ruby?"
question.save # => true
question.saved? # => true
# Error handling
question.title = nil
question.save # => false
question.errors # => ['You should probably have a title...']
# delete a resource
question.destroy # => true
question.destroyed? # => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment