ask_awesomely 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -0
- data/lib/ask_awesomely/api_client.rb +12 -1
- data/lib/ask_awesomely/design.rb +83 -0
- data/lib/ask_awesomely/dsl.rb +7 -3
- data/lib/ask_awesomely/picture.rb +1 -1
- data/lib/ask_awesomely/version.rb +1 -1
- data/lib/ask_awesomely.rb +2 -0
- metadata +2 -2
- data/.codeclimate.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b1872c38eca936853d8a4c749c86825c32e67b3
|
4
|
+
data.tar.gz: 21e73d3a4c42a1a1b5046c353c893a453c2179cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a71c7706f7c3570b7967ab4b12da84b5ed782f70cc1703b7a805b52c4c1f2c40ef1ea97082db984a35c0b61afec34432b6a9f65bc7a8d7864fc638882cdda631
|
7
|
+
data.tar.gz: 7677f681ef80f096dde29bcac94aca517c06144e6b5002838296c729f92f638b05c6f319a6ca11646ec0a3f8bc5b899110d0641a5d4a2769e39b13e543922cd9
|
data/README.md
CHANGED
@@ -352,6 +352,27 @@ field :legal
|
|
352
352
|
end
|
353
353
|
```
|
354
354
|
|
355
|
+
## Custom Designs
|
356
|
+
|
357
|
+
You can customise the appearance of your Typeform by adding a design. While you don't have as much control as you would through the builder on Typeform.com, you are still able to play with colours and fonts. The documentation contains a list of [possible font selections](http://docs.typeform.io/docs/designs).
|
358
|
+
|
359
|
+
```ruby
|
360
|
+
design do
|
361
|
+
question_color "#FF0099"
|
362
|
+
button_color "#ABCDEF"
|
363
|
+
answer_color "#4AF6E9"
|
364
|
+
background_color "#000000"
|
365
|
+
|
366
|
+
font "Vollkorn"
|
367
|
+
end
|
368
|
+
```
|
369
|
+
|
370
|
+
If you already have a design and would like to re-use it, you can use an ID from the created form.
|
371
|
+
|
372
|
+
```ruby
|
373
|
+
design 12345
|
374
|
+
```
|
375
|
+
|
355
376
|
## Logic Jumps
|
356
377
|
|
357
378
|
A logic jump allows you to change the next questions you ask based on the answer of a previous question. For example, you could have a `yes_no` field that shows one question if the answer is 'yes', and a different question if the answer is 'no'. At the time of writing this is the only supported behaviour for logic jumps.
|
@@ -6,7 +6,8 @@ module AskAwesomely
|
|
6
6
|
ENDPOINTS = {
|
7
7
|
root: "/",
|
8
8
|
create_typeform: "/forms",
|
9
|
-
create_picture: "/images"
|
9
|
+
create_picture: "/images",
|
10
|
+
create_design: "/designs"
|
10
11
|
}
|
11
12
|
|
12
13
|
def initialize
|
@@ -45,6 +46,16 @@ module AskAwesomely
|
|
45
46
|
JSON.parse(response.body)
|
46
47
|
end
|
47
48
|
|
49
|
+
def submit_design(design)
|
50
|
+
response = request.post(
|
51
|
+
url_for(:create_design),
|
52
|
+
headers: headers,
|
53
|
+
body: design.to_json
|
54
|
+
)
|
55
|
+
|
56
|
+
JSON.parse(response.body)
|
57
|
+
end
|
58
|
+
|
48
59
|
private
|
49
60
|
|
50
61
|
def request
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module AskAwesomely
|
2
|
+
class Design
|
3
|
+
|
4
|
+
VALID_FONTS = %w[
|
5
|
+
Acme
|
6
|
+
Arial
|
7
|
+
Arvo
|
8
|
+
Bangers
|
9
|
+
Cabin
|
10
|
+
Cabin Condensed
|
11
|
+
Courier
|
12
|
+
Crete Round
|
13
|
+
Dancing Script
|
14
|
+
Exo
|
15
|
+
Georgia
|
16
|
+
Handlee
|
17
|
+
Karla
|
18
|
+
Lato
|
19
|
+
Lobster
|
20
|
+
Lora
|
21
|
+
McLaren
|
22
|
+
Monsterrat
|
23
|
+
Nixie
|
24
|
+
Old Standard TT
|
25
|
+
Open Sans
|
26
|
+
Oswald
|
27
|
+
Playfair
|
28
|
+
Quicksand
|
29
|
+
Raleway
|
30
|
+
Signika
|
31
|
+
Sniglet
|
32
|
+
Source Sans Pro
|
33
|
+
Vollkorn
|
34
|
+
]
|
35
|
+
|
36
|
+
def initialize(&block)
|
37
|
+
@state = OpenStruct.new(colors: {})
|
38
|
+
instance_eval(&block)
|
39
|
+
end
|
40
|
+
|
41
|
+
def id
|
42
|
+
@id ||= upload_to_typeform["id"]
|
43
|
+
end
|
44
|
+
|
45
|
+
def background_color(color)
|
46
|
+
@state.colors[:background] = color
|
47
|
+
end
|
48
|
+
|
49
|
+
def question_color(color)
|
50
|
+
@state.colors[:question] = color
|
51
|
+
end
|
52
|
+
|
53
|
+
def answer_color(color)
|
54
|
+
@state.colors[:answer] = color
|
55
|
+
end
|
56
|
+
|
57
|
+
def button_color(color)
|
58
|
+
@state.colors[:button] = color
|
59
|
+
end
|
60
|
+
|
61
|
+
def font(font)
|
62
|
+
unless VALID_FONTS.include?(font)
|
63
|
+
raise AskAwesomely::InvalidFontError, "#{font} is not supported; you must use one of the following fonts: #{VALID_FONTS.join(', ')}"
|
64
|
+
end
|
65
|
+
|
66
|
+
@state.font = font
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_json(*)
|
70
|
+
{
|
71
|
+
colors: @state.colors,
|
72
|
+
font: @state.font
|
73
|
+
}.to_json
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def upload_to_typeform
|
79
|
+
ApiClient.new.submit_design(self)
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
data/lib/ask_awesomely/dsl.rb
CHANGED
@@ -41,11 +41,15 @@ module AskAwesomely
|
|
41
41
|
_state.jumps << LogicJump.new(conditions)
|
42
42
|
end
|
43
43
|
|
44
|
+
def design(id = nil, &block)
|
45
|
+
_state.design_id = id || ->(_) { Design.new(&block).id }
|
46
|
+
end
|
47
|
+
|
44
48
|
def send_responses_to(url)
|
45
49
|
unless url =~ /\A#{URI::regexp(['http', 'https'])}\z/
|
46
50
|
raise AskAwesomely::InvalidUrlError, "you must use a valid URL for webhooks, e.g https://example.com/webhook"
|
47
51
|
end
|
48
|
-
|
52
|
+
|
49
53
|
_state.webhook_submit_url = url
|
50
54
|
end
|
51
55
|
end
|
@@ -58,7 +62,7 @@ module AskAwesomely
|
|
58
62
|
end
|
59
63
|
|
60
64
|
private
|
61
|
-
|
65
|
+
|
62
66
|
def initialize(context = nil)
|
63
67
|
@context = context
|
64
68
|
@state = self.class._state
|
@@ -68,7 +72,7 @@ module AskAwesomely
|
|
68
72
|
return if state.webhook_submit_url
|
69
73
|
AskAwesomely.configuration.logger.warn(<<-STR.gsub(/^\s*/, ''))
|
70
74
|
Your Typeform has no webhook URL! The responses to this form **will NOT** be saved!
|
71
|
-
To set one, add `send_responses_to "https://example.com/webhook"` to #{self.class.name}
|
75
|
+
To set one, add `send_responses_to "https://example.com/webhook"` to #{self.class.name}
|
72
76
|
STR
|
73
77
|
end
|
74
78
|
end
|
data/lib/ask_awesomely.rb
CHANGED
@@ -17,6 +17,7 @@ require "ask_awesomely/api_client"
|
|
17
17
|
require "ask_awesomely/typeform"
|
18
18
|
require "ask_awesomely/embeddable"
|
19
19
|
require "ask_awesomely/logic_jump"
|
20
|
+
require "ask_awesomely/design"
|
20
21
|
|
21
22
|
module AskAwesomely
|
22
23
|
|
@@ -24,6 +25,7 @@ module AskAwesomely
|
|
24
25
|
FieldTypeError = Class.new(ArgumentError)
|
25
26
|
EmbedTypeError = Class.new(ArgumentError)
|
26
27
|
InvalidUrlError = Class.new(TypeError)
|
28
|
+
InvalidFontError = Class.new(ArgumentError)
|
27
29
|
|
28
30
|
def self.configuration
|
29
31
|
@configuration ||= Configuration.new
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ask_awesomely
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Machin
|
@@ -115,7 +115,6 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
- ".codeclimate.yml"
|
119
118
|
- ".gitignore"
|
120
119
|
- ".rspec"
|
121
120
|
- ".ruby-version"
|
@@ -131,6 +130,7 @@ files:
|
|
131
130
|
- lib/ask_awesomely/api_client.rb
|
132
131
|
- lib/ask_awesomely/choice.rb
|
133
132
|
- lib/ask_awesomely/configuration.rb
|
133
|
+
- lib/ask_awesomely/design.rb
|
134
134
|
- lib/ask_awesomely/dsl.rb
|
135
135
|
- lib/ask_awesomely/embeddable.rb
|
136
136
|
- lib/ask_awesomely/embeds/drawer.erb
|