typeform-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5b7fe3729f6d220c700c7d3e84eb9c2891d8e20a
4
+ data.tar.gz: 79a8fb1c2b21a215584a933bd3cca6c8d9deb168
5
+ SHA512:
6
+ metadata.gz: 534646c1ae913ae7498458e02ca6474645aca1b4160058e0f87e470274b0a1b7a661f9069919f74f40d3ea02a4eb5331f34cf8fb2f3c063fe4c7ba7f8e5246f7
7
+ data.tar.gz: 39be9012b42a4b0e5dacd918e9ad6110730f0b09741c48edb6ac1d76728f5a194a3560838fec7263575d96f3df9e48ced1a7b69a96b8dba292ae659880658931
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ .envrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in typeform.gemspec
4
+ gemspec
@@ -0,0 +1,75 @@
1
+ # Typeform
2
+
3
+ [Typeform I/O](http://typeform.io/) client for Ruby.
4
+
5
+ ## Usage
6
+
7
+ ### Initialize Client
8
+
9
+ ```ruby
10
+ typeform_api_key = ENV['TYPEFORM_API_KEY']
11
+ client = Typeform::Client.new(typeform_api_key)
12
+ ```
13
+
14
+ ### Get API information
15
+
16
+ If you want to make sure your authentication and connection to Typeform I/O works, call `Typeform::Client#information`.
17
+
18
+ ```ruby
19
+ client.information
20
+ ```
21
+
22
+ The response contains information about the API. It is useful for testing or making sure you have access.
23
+
24
+ ```json
25
+ {
26
+ "name": "Typeform I/O Build API",
27
+ "description": "Build API for creating forms awesomely",
28
+ "version": "v0.4",
29
+ "documentation": "https://docs.typeform.io/",
30
+ "support": "support@typeform.io",
31
+ "time": "2015-05-26 17:55:23 +0000"
32
+ }
33
+ ```
34
+
35
+ ### Create a typeform
36
+
37
+ Call `Typeform::Client#create_form_from_file` to create a new typeform.
38
+
39
+ ```ruby
40
+ file = File.open("example/example.json")
41
+ client.create_form_from_file(file)
42
+ ```
43
+
44
+ You have parameters to set the title, webhook URL and of course, the fields. The form endpoint will also return you a hash of URLs that you can use to distribute your typeform or delete it.
45
+
46
+ ```json
47
+ {
48
+ "id": "keEwsGeuC",
49
+ "title": "My first typeform",
50
+ "fields": [
51
+ {
52
+ "type": "short_text",
53
+ "question": "What is your name?"
54
+ }
55
+ ],
56
+ "links": [
57
+ {
58
+ "rel": "self",
59
+ "href": "https://api.typeform.io/latest/forms/keEwsGeuC"
60
+ },
61
+ {
62
+ "rel": "form_render",
63
+ "href": "https://forms.typeform.io/to/keEwsGeuC"
64
+ }
65
+ ]
66
+ }
67
+ ```
68
+
69
+ ### Show typeform
70
+
71
+ You can get the structure back of a typeform. It's useful if you want to allow your users to edit their typeform or you just want to get the URL of the typeform by leveraging the links.rel['form_render'].href link.
72
+
73
+ ```ruby
74
+ client.show_form(form_id)
75
+ ```
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "typeform"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ {
2
+ "title": "title",
3
+ "fields": [
4
+ {
5
+ "type": "short_text",
6
+ "question": "short_text"
7
+ }
8
+ ],
9
+ "webhook_submit_url": "https://webhook_submit_url.com"
10
+ }
@@ -0,0 +1,30 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require "typeform"
3
+ require "pry"
4
+
5
+ typeform_api_key = ENV['TYPEFORM_API_KEY']
6
+ client = Typeform::Client.new(typeform_api_key)
7
+
8
+ # information
9
+ pp client.information
10
+
11
+ # show form
12
+ pp client.show_form("tPvxO8qyP6gIzg")
13
+
14
+ # create_form_from_json
15
+ # field = Typeform::Field.new
16
+ # field.type = "multiple_choice"
17
+ # field.question = "What is your name?"
18
+ # field.description = "description"
19
+ # field.required = false
20
+ # field.choices = [{label: "A"}]
21
+ # form = Typeform::Form.new
22
+ # form.title = "title"
23
+ # form.fields = [field]
24
+ # form.design_id = "design_id"
25
+ # form.webhook_submit_url = "https://webhook_submit_url.com"
26
+ # pp client.create_form_from_json(form.as_json).body
27
+
28
+ # create_form_from_file
29
+ # file = File.open("example/example.json")
30
+ # pp client.create_form_from_file(file)
@@ -0,0 +1,30 @@
1
+ <!--Upload this file to your server-->
2
+
3
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4
+ <html>
5
+ <head>
6
+ <!--Add the title of your typeform below-->
7
+ <title>All fields</title>
8
+
9
+ <!--CSS styles that ensure your typeform takes up all the available screen space (DO NOT EDIT!)-->
10
+ <style type="text/css">
11
+ html{
12
+ margin: 0;
13
+ height: 100%;
14
+ overflow: hidden;
15
+ }
16
+ iframe{
17
+ position: absolute;
18
+ left:0;
19
+ right:0;
20
+ bottom:0;
21
+ top:0;
22
+ border:0;
23
+ }
24
+ </style>
25
+ </head>
26
+ <body>
27
+ <iframe id="typeform-full" width="100%" height="100%" frameborder="0" src="https://forms.typeform.io/to/tPvxO8qyP6gIzg"></iframe>
28
+ <script type="text/javascript" src="https://s3-eu-west-1.amazonaws.com/share.typeform.com/embed.js"></script>
29
+ </body>
30
+ </html>
@@ -0,0 +1,7 @@
1
+ require "typeform/version"
2
+ require "typeform/client"
3
+
4
+ module Typeform
5
+ class << self
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+ require "typeform/version"
2
+ require "typeform/connection"
3
+ require "typeform/form"
4
+ require "typeform/field"
5
+ require "faraday"
6
+ require "faraday_middleware"
7
+ require "json"
8
+
9
+ module Typeform
10
+ class Client
11
+ def initialize(api_key)
12
+ @conn = Connection.new(api_key)
13
+ end
14
+
15
+ def information
16
+ @conn.get "/"
17
+ end
18
+
19
+ def show_form(id)
20
+ @conn.get "/forms/#{id}"
21
+ end
22
+
23
+ def create_form_from_json(json)
24
+ @conn.post "/forms", json
25
+ end
26
+
27
+ def create_form_from_file(file)
28
+ create_form_from_json(JSON.parse(file.read))
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ module Typeform
2
+ class Connection
3
+ @@base_uri = "https://api.typeform.io"
4
+
5
+ def initialize(api_key)
6
+ @api_key = api_key
7
+ @conn = Faraday.new(url: @@base_uri) do |faraday|
8
+ faraday.request :json
9
+ faraday.response :logger
10
+ faraday.adapter Faraday.default_adapter
11
+ faraday.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
12
+ end
13
+ end
14
+
15
+ def set_base_headers(request)
16
+ request.headers["X-API-TOKEN"] = @api_key
17
+ request.headers["Content-Type"] = "application/json; charset=utf-8"
18
+ request.headers["Accept-Encoding"] = "gzip, deflate"
19
+ end
20
+
21
+ def get(path)
22
+ @conn.get do |request|
23
+ set_base_headers(request)
24
+ request.url "/v0.3#{path}"
25
+ end
26
+ end
27
+
28
+ def post(path, body)
29
+ @conn.post do |request|
30
+ set_base_headers(request)
31
+ request.url "/v0.3#{path}"
32
+ request.body = body
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,47 @@
1
+ module Typeform
2
+ class Field
3
+ include JSON::Encodable
4
+
5
+ property :type, type: String
6
+ property :question, type: String
7
+ property :description, type: String
8
+ property :required
9
+ property :choices
10
+
11
+ attr_accessor :type, :question, :description, :required, :choices
12
+
13
+ # This value could take...
14
+ # short_text: The ShortText Field is the typical, standard text input that you would expect.
15
+ # long_text: You would use a LongTextField if you want your user to leave answers with freely written text, longer than one line.
16
+ # multiple_choice: The MultipleChoiceField is used for (guess), displaying multiple choice text based answers.
17
+ # picture_choice: The PictureChoiceField is much like the MultipleChoiceField but you can also use images as choices and make your typeforms beautiful and engaging.
18
+ # statement: The statement field is not a question, it's just a opportunity to make conversation in your typeform.
19
+ # dropdown: The DropdownField is a cross between select element auto-completion. Use it when you need your respondent to choose from a long list of choices.
20
+ # yes_no: The YesNo Field is a field that allows the user to answer only yes or no to a question
21
+ # number: The NumberField is like a ShortTextField that only allows numbers.
22
+ # raiting: RatingField is the best field to use if you want your users to rate anything in a visual way.
23
+ # opinion_scale: OpinionScale field is the perfect field if you want to do a NPS style evaluation or simply ask your respondents to review a product of yours, with a scale you can set yourself.
24
+ # email: You want your users to give you their precious email? Then the EmailField is just the right field for you!
25
+ # website: The WebsiteField is the field you would use if you want to collect a URL from your respondent. It will validate that the answer contains a URL.
26
+ # legal: The LegalField is very similar to the YesNoField, with some minor UI differences including a smaller body text.
27
+ def type
28
+ @type
29
+ end
30
+
31
+ def question
32
+ @question
33
+ end
34
+
35
+ def description
36
+ @description
37
+ end
38
+
39
+ def required
40
+ @required
41
+ end
42
+
43
+ def choices
44
+ @choices
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,30 @@
1
+ require "json-encodable"
2
+
3
+ module Typeform
4
+ class Form
5
+ include JSON::Encodable
6
+
7
+ property :title, type: String
8
+ property :fields
9
+ property :design_id, type: Integer
10
+ property :webhook_submit_url, type: String
11
+
12
+ attr_accessor :title, :fields, :design_id, :webhook_submit_url
13
+
14
+ def title
15
+ @title
16
+ end
17
+
18
+ def fields
19
+ @fields
20
+ end
21
+
22
+ def design_id
23
+ @design_id
24
+ end
25
+
26
+ def webhook_submit_url
27
+ @webhook_submit_url
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Typeform
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'typeform/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "typeform-ruby"
8
+ spec.version = Typeform::VERSION
9
+ spec.authors = ["Kentaro Takiguchi"]
10
+ spec.email = ["kentaro-takiguchi@cookpad.com"]
11
+
12
+ spec.summary = "Typeform I/O client for Ruby"
13
+ spec.description = "Simple wrapper for the Typeform I/O"
14
+ spec.homepage = "https://github.com/rejasupotaro/typeform-ruby"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "pry-byebug"
26
+ spec.add_development_dependency "rspec-json_matcher"
27
+
28
+ spec.add_dependency "faraday"
29
+ spec.add_dependency "faraday_middleware"
30
+ spec.add_dependency "json"
31
+ spec.add_dependency "json-encodable"
32
+ end
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: typeform-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kentaro Takiguchi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-json_matcher
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: faraday_middleware
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: json
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: json-encodable
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Simple wrapper for the Typeform I/O
154
+ email:
155
+ - kentaro-takiguchi@cookpad.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rspec"
162
+ - ".travis.yml"
163
+ - Gemfile
164
+ - README.md
165
+ - Rakefile
166
+ - bin/console
167
+ - bin/setup
168
+ - example/example.json
169
+ - example/example.rb
170
+ - example/index.html
171
+ - lib/typeform.rb
172
+ - lib/typeform/client.rb
173
+ - lib/typeform/connection.rb
174
+ - lib/typeform/field.rb
175
+ - lib/typeform/form.rb
176
+ - lib/typeform/version.rb
177
+ - typeform.gemspec
178
+ homepage: https://github.com/rejasupotaro/typeform-ruby
179
+ licenses: []
180
+ metadata: {}
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 2.2.2
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: Typeform I/O client for Ruby
201
+ test_files: []
202
+ has_rdoc: