Created
December 15, 2011 02:45
-
-
Save probablykabari/1479603 to your computer and use it in GitHub Desktop.
Example of using the survey-gizmo-ruby gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'survey-gizmo-ruby' | |
# somewhere in your app define your survey gizmo login credentials. | |
SurveyGizmo.setup(:user => '[email protected]', :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