Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. #gems we need
  2. require 'ohmage'
  3. require 'SecureRandom' unless defined?(SecureRandom)
  4.  
  5. # check if you have a version of the ohmage gem that will work with this
  6. abort unless Ohmage::Version.to_s >= '0.0.19'
  7.  
  8. # first set up the client
  9. oh = Ohmage::Client.new() # assumes env has necessary variables
  10.  
  11. # make sure ohmage.admin is in public class
  12. oh.class_update(class_urn: 'urn:class:public', user_role_list_add: 'ohmage.admin;privileged')
  13.  
  14. # create a single prompt campaign. note 'photo1' is skippable.
  15. urn = 'urn:campaign:photo:test2'
  16. name = 'Photo Test'
  17. xml = '<?xml version="1.0" encoding="UTF-8"?>
  18. <campaign>
  19. <surveys>
  20. <survey>
  21. <id>photo</id>
  22. <title>photo</title>
  23. <description>photo description</description>
  24. <submitText>Thanks</submitText>
  25. <anytime>true</anytime>
  26. <contentList>
  27. <prompt>
  28. <promptType>photo</promptType>
  29. <id>photo1</id>
  30. <displayLabel>photo1</displayLabel>
  31. <promptText>take a photo</promptText>
  32. <skippable>true</skippable>
  33. <skipLabel>Skip</skipLabel>
  34. <properties>
  35. <property>
  36. <key>maxDimension</key>
  37. <label>800</label>
  38. </property>
  39. </properties>
  40. </prompt>
  41. </contentList>
  42. </survey>
  43. </surveys>
  44. </campaign>'
  45. photo_campaign = oh.campaign_create(running_state: 'running', privacy_state: 'shared', class_urn_list: 'urn:class:public', campaign_urn: urn, campaign_name: name, xml: xml)
  46. photo_campaign = photo_campaign.first # oh.campaign_read always returns an array.
  47.  
  48. # upload a response to it
  49. survey_uuid = SecureRandom.uuid()
  50. image_uuid = SecureRandom.uuid()
  51. image_location = '/Users/steve/Downloads/badImage.png'
  52. oh.survey_upload(campaign_creation_timestamp: photo_campaign.creation_timestamp,
  53. campaign_urn: photo_campaign.urn,
  54. surveys: [{survey_key: survey_uuid,
  55. location_status: 'unavailable',
  56. time: 1434046871000,
  57. timezone: 'America/Los_Angeles',
  58. survey_id: 'photo',
  59. survey_launch_context: {
  60. launch_time: 1434046871000,
  61. launch_timezone: 'America/Los_Angeles',
  62. active_triggers: []
  63. },
  64. responses: [
  65. {prompt_id: 'photo1', value: image_uuid}
  66. ]
  67. }
  68. ].to_json,
  69. image_uuid => image_location
  70. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement