ask_awesomely 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +8 -0
  6. data/Gemfile +4 -0
  7. data/README.md +474 -0
  8. data/Rakefile +11 -0
  9. data/ask_awesomely.gemspec +27 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +7 -0
  12. data/lib/ask_awesomely.rb +31 -0
  13. data/lib/ask_awesomely/api_client.rb +56 -0
  14. data/lib/ask_awesomely/choice.rb +10 -0
  15. data/lib/ask_awesomely/configuration.rb +30 -0
  16. data/lib/ask_awesomely/dsl.rb +50 -0
  17. data/lib/ask_awesomely/embeddable.rb +30 -0
  18. data/lib/ask_awesomely/embeds/drawer.erb +3 -0
  19. data/lib/ask_awesomely/embeds/fullscreen.erb +28 -0
  20. data/lib/ask_awesomely/embeds/modal.erb +3 -0
  21. data/lib/ask_awesomely/embeds/widget.erb +3 -0
  22. data/lib/ask_awesomely/field.rb +18 -0
  23. data/lib/ask_awesomely/field/dropdown.rb +18 -0
  24. data/lib/ask_awesomely/field/email.rb +5 -0
  25. data/lib/ask_awesomely/field/field.rb +68 -0
  26. data/lib/ask_awesomely/field/legal.rb +4 -0
  27. data/lib/ask_awesomely/field/long_text.rb +9 -0
  28. data/lib/ask_awesomely/field/multiple_choice.rb +30 -0
  29. data/lib/ask_awesomely/field/number.rb +22 -0
  30. data/lib/ask_awesomely/field/opinion_scale.rb +40 -0
  31. data/lib/ask_awesomely/field/picture_choice.rb +34 -0
  32. data/lib/ask_awesomely/field/rating.rb +31 -0
  33. data/lib/ask_awesomely/field/short_text.rb +9 -0
  34. data/lib/ask_awesomely/field/statement.rb +21 -0
  35. data/lib/ask_awesomely/field/website.rb +4 -0
  36. data/lib/ask_awesomely/field/yes_no.rb +4 -0
  37. data/lib/ask_awesomely/picture.rb +41 -0
  38. data/lib/ask_awesomely/s3.rb +51 -0
  39. data/lib/ask_awesomely/typeform.rb +43 -0
  40. data/lib/ask_awesomely/version.rb +3 -0
  41. metadata +166 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f05c9c5cdae79172a5a1bcddbef1f3c6fa488033
4
+ data.tar.gz: 798898689f330e31f28685a690180813797c84d5
5
+ SHA512:
6
+ metadata.gz: cf064d4f65fb1d9bcc6e9a41f979aa16c5621ae3dbcd482c55371bad955aeba199c6fb34351f368507c2c9eb1f60d0d49b955eadf7923fde6c4ae0617313d097
7
+ data.tar.gz: ed9e1bd633c56fbf521a8fc521a61c49d0073269241b7fcfa47397cd5c894c031e452b42b5c7916a426c2ce2ac858f89f33dcf0ba2956b0f5b35ada56477cd63
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ vendor/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ - 2.2.3
5
+ - rbx-2
6
+ env:
7
+ global:
8
+ secure: IiOYP2G1Ufie+zMYz/l/+wnLwej6REZCKgFN+hNUU5//0UugDMQHbVHSLPSEuAu3g8T/9CcPgYLVYcTrsZC9Hn/TtB3Sc8w3OuSELD1prsanMlySjTHDTLmZynmDT/IFWxz2mdKIaFwHKvbipJw+VUxyTiFD/Iu/Ns/goM4+HBemxh2cuomAqPIo2qTKWxl9hpcT3YFf9ylbLKFe6LfnRCygeTK+nY3ooZMP+vC5tnYmLX74FINZKnliG8npNXG0fc7X/W5zzy0vKHGKobirxTqgMERZH1voGCShoVKtH9YISgr9g+JJ8AvVHVr58mjc3U26tChl6MKxMYIc+iscX/aoUEPQ6yPgST+Wj7+ZcFduFg/C3xgs0BoNRsJDLDD37a9uyEJet7iusMARs+X+buimRdEUvddkEdW4SNj76Jqjwsgp09Isl5LOLwUB+xsCE9s6CK3pOOsPHVnultFILsSk86Cre2+E2QEukt4r1cghn+Lf9+sdRwOHnBUT6G3p5S1t313JWNfZGx3auFEXacK5jmDjvqWH6QPUfVZJ25XGlHkVhsv4q09/dJcyr//tPsjD6Yrx2hc+pkIu24o8RPQlmpgTTpb/A3a2xaJOaP+PNJB0yT3LAxabEmvsCZCmmhScScagxTCdlBpP43q/Bjr2RA5Mbd+LVRBh7t/90RI=
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ask_awesomely.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,474 @@
1
+ # Ask Awesomely
2
+
3
+ Build Typeforms awesomely. In Ruby.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/ask_awesomely.svg)](http://badge.fury.io/rb/ask_awesomely) [![Build Status](https://travis-ci.org/leemachin/ask_awesomely.svg?branch=master)](https://travis-ci.org/leemachin/ask_awesomely)
6
+
7
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
8
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
9
+ ## Table of Contents
10
+
11
+ - [Installation](#installation)
12
+ - [Usage](#usage)
13
+ - [Authentication](#authentication)
14
+ - [If you're using images](#if-youre-using-images)
15
+ - [Basic example](#basic-example)
16
+ - [Available fields and options](#available-fields-and-options)
17
+ - [Statement](#statement)
18
+ - [Short text](#short-text)
19
+ - [Long text](#long-text)
20
+ - [Multiple choice](#multiple-choice)
21
+ - [Picture choice](#picture-choice)
22
+ - [Dropdown](#dropdown)
23
+ - [Yes/No](#yesno)
24
+ - [Number](#number)
25
+ - [Rating](#rating)
26
+ - [Opinion Scale](#opinion-scale)
27
+ - [Email](#email)
28
+ - [Website](#website)
29
+ - [Legal](#legal)
30
+ - [Common Customisations](#common-customisations)
31
+ - [Passing Context](#passing-context)
32
+ - [Rendering the Typeform](#rendering-the-typeform)
33
+ - [Getting the URL](#getting-the-url)
34
+ - [Embedding](#embedding)
35
+ - [Modal](#modal)
36
+ - [Widget](#widget)
37
+ - [Drawer](#drawer)
38
+ - [Fullscreen](#fullscreen)
39
+ - [Todo](#todo)
40
+ - [Development](#development)
41
+ - [Contributing](#contributing)
42
+
43
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
44
+
45
+
46
+ ## Installation
47
+
48
+ I wouldn't recommend you do this yet, because it doesn't actually work. Nevertheless, add this line to your application's Gemfile:
49
+
50
+ ```ruby
51
+ gem 'ask_awesomely'
52
+ ```
53
+
54
+ And then execute:
55
+
56
+ ```shell
57
+ bundle
58
+ ```
59
+
60
+ Or install it yourself as:
61
+
62
+ ```shell
63
+ gem install ask_awesomely
64
+ ```
65
+
66
+
67
+ ## Usage
68
+
69
+ ### Authentication
70
+
71
+ Firstly, you will need to be able to authenticate:
72
+
73
+ ```ruby
74
+ AskAwesomely.configure do |config|
75
+ config.typeform_api_key = ENV["YOUR_TYPEFORM_IO_API_KEY"]
76
+ end
77
+ ```
78
+
79
+ Your API Keys are **super secret** so don't commit them in your code. Use `ENV` or
80
+ something like [dotenv](https://github.com/bkeepers/dotenv) so you can keep the credentials out of the repository. This stops bad people from stealing the key and hijacking your Typeform I/O account.
81
+
82
+ ### If you're using images
83
+
84
+ It's possible to create questions that have images (or pictures, as we call them) attached. In fact, one field type relies on this!
85
+
86
+ Currently Typeform I/O is only able to accept a URL to an image, which means that any images you use have to be uploaded elsewhere first.
87
+
88
+ **If you already handle image uploads in your app** (for example, with [Dragonfly](https://github.com/markevans/dragonfly)), you're okay.
89
+
90
+ **If you don't**, you will need to give `AskAwesomely` your AWS credentials so it can do all of the heavy lifting for you.
91
+
92
+ ```ruby
93
+ AskAwesomely.configure do |config|
94
+ config.aws_access_key_id = ENV["YOUR_AWS_ACCESS_KEY_ID"]
95
+ config.aws_access_key_secret = ENV["YOUR_AWS_ACCESS_KEY_SECRET"]
96
+ end
97
+ ```
98
+
99
+ As before, don't commit these keys to your repo unless you want [bad things to happen](http://vertis.io/2013/12/16/unauthorised-litecoin-mining.html). Check up on the [AWS Best Practices](http://docs.aws.amazon.com/general/latest/gr/aws-access-keys-best-practices.html) if you want to know more.
100
+
101
+ ### Basic example
102
+
103
+ You will want to create a class that represents a specific form to be built:
104
+
105
+ ```ruby
106
+ class MyNewTypeform
107
+
108
+ include AskAwesomely::DSL
109
+
110
+ title "My New Typeform"
111
+
112
+ tags "awesome", "hehe"
113
+
114
+ field :statement do
115
+ say "Hello, Rubyists!"
116
+ end
117
+
118
+ field :multiple_choice do
119
+ ask "What is your favourite language?"
120
+ choice "Ruby"
121
+ choice "Python"
122
+ choice "Javascript"
123
+ choice "COBOL"
124
+
125
+ can_specify_other
126
+ end
127
+
128
+ end
129
+ ```
130
+
131
+ After that, it's simply a matter of calling `build` on the class:
132
+
133
+ ```ruby
134
+ typeform = MyNewTypeform.build
135
+ ```
136
+
137
+ Check the rest of the (not currently finished) documentation to find out what else you can do.
138
+
139
+ Check out [Typeform I/O](https://typeform.io) for detailed information about the API, and how to get your API key.
140
+
141
+
142
+ ## Available fields and options
143
+
144
+ Each field has unique properties. Here are the fields you can use, and the extra
145
+ things you can do to customise them.
146
+
147
+ <small>Note that some options might not yet be available on [Typeform I/O](https://typeform.io).</small>
148
+
149
+ <small>Also note that some field types and customisations that are available on [Typeform.com](https://typeform.com) may not be available on [Typeform I/O](https://typeform.io).</small>
150
+
151
+
152
+ ### Statement
153
+
154
+ A block of text that isn't a question and requires no answer.
155
+
156
+ ```ruby
157
+ field :statement do
158
+ say "what you want to say"
159
+ button_text "Okay, next question"
160
+ show_quotation_marks
161
+ end
162
+ ```
163
+
164
+ ### Short text
165
+
166
+ A question where the answer is a short amount of free-form text.
167
+
168
+ ```ruby
169
+ field :short_text do
170
+ ask "What do you think of me?"
171
+ max_characters 3
172
+ end
173
+ ```
174
+
175
+ ### Long text
176
+
177
+ A question where the answer is free-form, like `short_text`, but can be *much* longer.
178
+
179
+ ```ruby
180
+ field :long_text do
181
+ ask "What do you *really* think of me?"
182
+ max_characters 700
183
+ end
184
+ ```
185
+
186
+ ### Multiple choice
187
+
188
+ A question that allows the user to choose from a range answers.
189
+
190
+ ```ruby
191
+ field :multiple_choice do
192
+ ask "Why not both?"
193
+
194
+ choice "Yes"
195
+ choice "No"
196
+
197
+ allow_multiple_selections
198
+ randomize
199
+ end
200
+ ```
201
+
202
+ ### Picture choice
203
+
204
+ Similar to `multiple_choice`, only you can add a picture to each answer too. This will handle the complications around image uploading for you if you're dealing with local files and pass along your AWS credentials. Otherwise, it will work with whatever system you already have in place – just give it a URL instead of a file path.
205
+
206
+
207
+ ```ruby
208
+ field :picture_choice do
209
+ ask "Which of these is a spoon?"
210
+
211
+ # `image` can be a `String`, a `URL`, a `Pathname`, or a `File`
212
+ choice "Knife", picture: "http://iseeyouveplayedknifeyspooneybefore.com/spoon.jpg"
213
+ choice "Spoon", picture: Rails.root.join("app/assets/images/knife.jpg")
214
+ choice "Spork", picture: "/var/www/images/spork.png"
215
+
216
+ allow_multiple_selections
217
+ randomize
218
+ end
219
+ ```
220
+
221
+ ### Dropdown
222
+
223
+ Similar again to `multiple_choice`, when you have too many options to show at once.
224
+
225
+ ```ruby
226
+ field :dropdown do
227
+ ask "Which is the odd one out?"
228
+
229
+
230
+ (1..100).each do |number|
231
+ choice (number != 70 ? number : "seventy")
232
+ end
233
+
234
+ in_alphabetical_order
235
+ end
236
+ ```
237
+
238
+ ### Yes/No
239
+
240
+ A question that demands the user to commit to their own certainty.
241
+
242
+ ```ruby
243
+ field :yes_no do
244
+ ask "Will you marry me?"
245
+ required
246
+ end
247
+ ```
248
+
249
+ ### Number
250
+
251
+ A `short_text` style question that only accepts numerical input. It can be limited to a range.
252
+
253
+ ```ruby
254
+ field :number do
255
+ ask "How many fingers am I holding up?"
256
+
257
+ min 0
258
+ max 4
259
+
260
+ # alternatively
261
+ between 0..4
262
+ end
263
+ ```
264
+
265
+ ### Rating
266
+
267
+ A question that prompts the user to quantify their opinion of something.
268
+
269
+ ```ruby
270
+ field :rating do
271
+ ask "How much did you enjoy Jonny Wiseau's seminal hit, The Room?"
272
+
273
+ steps 10
274
+ shape :thumbs_up
275
+ end
276
+
277
+ ```
278
+
279
+ ### Opinion Scale
280
+
281
+ A refined form of `rating` more appropriate for "bad / neutral / good" style questions.
282
+
283
+ ```ruby
284
+ field :opinion_scale do
285
+ ask "How would you rate our service?"
286
+
287
+ steps 11
288
+
289
+ left_side "Terrible"
290
+ middle "Average"
291
+ right_side "Amazeballs"
292
+
293
+ starts_from_one
294
+ end
295
+ ```
296
+
297
+ ### Email
298
+
299
+ A question type painstakingly created to request a valid email address.
300
+
301
+ ```ruby
302
+ field :email do
303
+ ask "Can I have your email please?"
304
+ description "So you can be my best pen-pal buddy forever."
305
+ end
306
+ ```
307
+
308
+ ### Website
309
+
310
+ Ask the user to enter a valid URL.
311
+
312
+ ```ruby
313
+ field :website do
314
+ ask "Show me a funny GIF"
315
+ end
316
+ ```
317
+
318
+ ### Legal
319
+
320
+ ![YAAAAWWWWN](https://31.media.tumblr.com/3a602d9eb5e18d208b86bc18c4ea0735/tumblr_ns3e06dxFO1tyncywo1_250.gif)
321
+
322
+ Like the `yes_no` field, but primarily intended for accepting terms and conditions. Stuff like that.
323
+
324
+ ```ruby
325
+ field :legal
326
+ ask "Do you accept my lofty demands?"
327
+ required
328
+ end
329
+ ```
330
+
331
+
332
+ #### Common Customisations
333
+
334
+ Every field type allows you customize the following things:
335
+
336
+ - the description: a smaller chunk of text to give extra detail to a question
337
+ - tags: small strings to help you identify questions
338
+ - answer required: prevent form submission until the question is answered
339
+
340
+ ```ruby
341
+ field :legal do
342
+ # ...
343
+ description "Don't accept, I dare you."
344
+ required
345
+ tags "some-kind-of-tag-for-legal", "wtf"
346
+ end
347
+ ```
348
+
349
+
350
+ ## Passing Context
351
+
352
+ **note: not yet supported**
353
+
354
+ Building a form full of hard-coded data is all well and good, but it doesn't offer much benefit over using a web interface. What if you want to build personalised forms based on, say, an `ActiveRecord` model?
355
+
356
+ Lets create the basic form, with a title and a single question:
357
+
358
+ ```ruby
359
+ class UserTypeform
360
+ include AskAwesomely::DSL
361
+
362
+ title -> (user) { "#{user.name}'s New Typeform" }
363
+
364
+ field :yes_no do
365
+ say -> (user) { "Is this your email address? #{user.email}" }
366
+ required
367
+ end
368
+ end
369
+ ```
370
+
371
+ Notice that we're now using a lambda for the title and question, instead of a hardcoded string. In this case, we're expecting an object that has a `name` and an `email`, so we can inject that data into the form.
372
+
373
+ The next step is to build the form with such an object. For example, in Rails:
374
+
375
+ ```ruby
376
+ rodrigo = User.create(name: "Rodrigo", email: "rodrigo@example.com")
377
+
378
+ typeform = UserTypeform.build(rodrigo)
379
+ ```
380
+
381
+ Or in plain Ruby:
382
+
383
+ ```ruby
384
+ gabriela = OpenStruct.new(name: "Gabriela", email: "gabriela@example.com")
385
+
386
+ typeform = UserTypeform.build(gabriela)
387
+ ```
388
+
389
+
390
+ ## Rendering the Typeform
391
+
392
+ Calling `build` will send your Typeform structure to the API right away, and if everything is hunky-dory you'll get a nice new `Typeform` object to play with.
393
+
394
+ ### Getting the URL
395
+
396
+ Every Typeform you successfully generate through Typeform I/O will come back with a new public URL. This points to the rendered version of the Typeform and it's what you can send out to your users, or participants, or whomever.
397
+
398
+ For example, you might email a bunch of personalised Typeforms in a Rails app like this:
399
+
400
+ ```ruby
401
+
402
+ User.find_each do |user|
403
+ typeform = UserTypeform.build(user)
404
+ TypeformMailer.send_to_user(user, typeform.public_url)
405
+ end
406
+ ```
407
+
408
+ ### Embedding
409
+
410
+ You can also embed a form straight away if you prefer. `AskAwesomely` generates the correct embed code for you, with the correct URL and Typeform title. The style can be customised with CSS but some aspects of the embed itself are not currently customisable (e.g. changing button text and widget size).
411
+
412
+ To see what each embedding option looks like, check out the `Embedding Modes`[http://docs.typeform.io/docs/embedding-introduction) documentation at Typeform I/O. It has pictures and everything.
413
+
414
+ Assuming you have built a Typeform as in the other examples, rendering the embed code is simple:
415
+
416
+ #### Modal
417
+
418
+ Pops up over the page content and fills most of the screen.
419
+
420
+ ```ruby
421
+ typeform.embed_as(:modal)
422
+ ```
423
+
424
+ #### Widget
425
+
426
+ Allows you more control over where the form is embedded and how it appears. Just a box on the page.
427
+
428
+ ```ruby
429
+ typeform.embed_as(:widget)
430
+ ```
431
+
432
+ #### Drawer
433
+
434
+ Makes the form slide in from the side of the page, hamburger menu style, and fills at least half of the screen.
435
+
436
+ ```ruby
437
+ typeform.embed_as(:drawer)
438
+ ```
439
+
440
+ #### Fullscreen
441
+
442
+ Becomes the entire page.
443
+
444
+ Note that this outputs a **complete** HTML document, CSS and all. If you're working with your own views and layouts this will not embed properly unless inserted into an empty layout. Can work well with Sinatra or other small frameworks if you just want to build a form and display it.
445
+
446
+ ```ruby
447
+ typeform.embed_as(:fullscreen)
448
+ ```
449
+
450
+
451
+ ## Todo
452
+
453
+ - implement and test dynamic fields
454
+ - test the API interaction behaves well
455
+ - deal with errors from the API
456
+ - allow webhook URL to be configured
457
+ - allow design to be configured
458
+
459
+
460
+
461
+ ## Development
462
+
463
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
464
+
465
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
466
+
467
+
468
+ ## Contributing
469
+
470
+ 1. Fork it (https://github.com/leemachin/ask_awesomely/fork)
471
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
472
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
473
+ 4. Push to the branch (`git push origin my-new-feature`)
474
+ 5. Create a new Pull Request