typeform 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +2 -0
- data/lib/typeform.rb +86 -0
- data/lib/typeform/form.rb +40 -0
- data/lib/typeform/version.rb +3 -0
- data/typeform.gemspec +31 -0
- metadata +165 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d87009da2181534474893ab6ee219ed1bd707f12
|
4
|
+
data.tar.gz: bc34b4ffce46935df80998c64d5e5922ebde4e07
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d57c8ce69f4332557bcc6b5fbde0cc0aa5a14cb5b90d3310fdbd1a141aad634b2c7303ff12439985189b5bfd79f28ab3881d138838f3adaf83bf75d9bbb29931
|
7
|
+
data.tar.gz: 435d610d5cb499daf0d09a971ba2f5f8d8222534c4bf3259897cf4edc9357c356ff614cebb1e55d62bee01eb3af15b79a1e5d0eccaf091ffb257f4e1a7a21b75
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Philip De Smedt
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Typeform
|
2
|
+
|
3
|
+
Typeform is a Ruby gem that provides a wrapper for interacting with the Typeform Data API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'typeform'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install typeform
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Please refer to the [Typeform Data API Documentation](http://helpcenter.typeform.com/hc/en-us/articles/200071986-Data-API) for more information about the API, or follow the examples below:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'typeform'
|
27
|
+
|
28
|
+
Typeform.api_key = ENV['TYPEFORM_API_KEY']
|
29
|
+
typeform_id = "an_id_here"
|
30
|
+
form = Typeform::Form.new(typeform_id)
|
31
|
+
|
32
|
+
all_entries = form.all_entries
|
33
|
+
incomplete_entries = form.incomplete_entries
|
34
|
+
complete_entries = form.complete_entries
|
35
|
+
|
36
|
+
# Fetches all complete entries since today
|
37
|
+
newest_entries = form.complete_entries(since: Time.now.to_i)
|
38
|
+
```
|
39
|
+
|
40
|
+
For now, the wrapper returns the default format as returned by the Typeform Data API. I have some thoughts on how they should structure their data and how they can be build a [Hypermedia APIs](http://en.wikipedia.org/wiki/Hypermedia), but the current implementation allows you to build your custom logic on top of the responses (e.g. your pagination logic).
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it ( https://github.com/philipdesmedt/typeform/fork )
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/typeform.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "hashie"
|
3
|
+
Hash.send :include, Hashie::Extensions
|
4
|
+
|
5
|
+
require "typeform/version"
|
6
|
+
require "typeform/form"
|
7
|
+
|
8
|
+
module Typeform
|
9
|
+
class << self
|
10
|
+
# Allow Typeform.api_key = "..."
|
11
|
+
def api_key=(api_key)
|
12
|
+
Typeform.api_key = api_key
|
13
|
+
end
|
14
|
+
|
15
|
+
# Allow Typeform.base_uri = "..."
|
16
|
+
def base_uri=(uri)
|
17
|
+
Tyepform.base_uri uri
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Represents a Typeform API error and contains specific data about the error.
|
22
|
+
class TypeformError < StandardError
|
23
|
+
attr_reader :data
|
24
|
+
def initialize(data)
|
25
|
+
@data = Hashie::Mash.new(data)
|
26
|
+
super "The Typeform API responded with the following error - #{data}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class ClientError < StandardError; end
|
31
|
+
class ServerError < StandardError; end
|
32
|
+
class BadRequest < TypeformError; end
|
33
|
+
class Unauthorized < StandardError; end
|
34
|
+
class NotFound < ClientError; end
|
35
|
+
class Unavailable < StandardError; end
|
36
|
+
|
37
|
+
class Typeform
|
38
|
+
include HTTParty
|
39
|
+
|
40
|
+
@@base_uri = "https://api.typeform.com/v0/"
|
41
|
+
@@api_key = ""
|
42
|
+
headers({
|
43
|
+
'User-Agent' => "typeform-rest-#{VERSION}",
|
44
|
+
'Content-Type' => 'application/json; charset=utf-8',
|
45
|
+
'Accept-Encoding' => 'gzip, deflate'
|
46
|
+
})
|
47
|
+
base_uri @@base_uri
|
48
|
+
|
49
|
+
class << self
|
50
|
+
# Get the API key (Typeform::Typeform.api_key)
|
51
|
+
def api_key; @@api_key end
|
52
|
+
|
53
|
+
# Set the API key
|
54
|
+
def api_key=(api_key)
|
55
|
+
return @@api_key unless api_key
|
56
|
+
@@api_key = api_key
|
57
|
+
end
|
58
|
+
|
59
|
+
# Get the Base URI.
|
60
|
+
def base_uri; @@base_uri end
|
61
|
+
|
62
|
+
def get(*args); handle_response super end
|
63
|
+
# No POST, PUT or DELETE for now - Read only Typeform API
|
64
|
+
# def post(*args); handle_response super end
|
65
|
+
# def put(*args); handle_response super end
|
66
|
+
# def delete(*args); handle_response super end
|
67
|
+
|
68
|
+
def handle_response(response) # :nodoc:
|
69
|
+
case response.code
|
70
|
+
when 400
|
71
|
+
raise BadRequest.new response.parsed_response
|
72
|
+
when 401
|
73
|
+
raise Unauthorized.new
|
74
|
+
when 404
|
75
|
+
raise NotFound.new
|
76
|
+
when 400...500
|
77
|
+
raise ClientError.new response.parsed_response
|
78
|
+
when 500...600
|
79
|
+
raise ServerError.new
|
80
|
+
else
|
81
|
+
response
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'typeform'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Typeform
|
5
|
+
|
6
|
+
class Form
|
7
|
+
attr_reader :form_id
|
8
|
+
|
9
|
+
def initialize(form_id)
|
10
|
+
@form_id = form_id
|
11
|
+
end
|
12
|
+
|
13
|
+
def all_entries
|
14
|
+
response = get
|
15
|
+
Hashie::Mash.new(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
def complete_entries(params = {})
|
19
|
+
response = get(params.merge(completed: true))
|
20
|
+
Hashie::Mash.new(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
def incomplete_entries(params = {})
|
24
|
+
response = get(params.merge(completed: false))
|
25
|
+
Hashie::Mash.new(response)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def get(params = nil)
|
30
|
+
params ||= {}
|
31
|
+
params[:key] = Typeform.api_key
|
32
|
+
Typeform.get uri, :query => params
|
33
|
+
end
|
34
|
+
|
35
|
+
def uri
|
36
|
+
"/form/#{form_id}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/typeform.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
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"
|
8
|
+
spec.version = Typeform::VERSION
|
9
|
+
spec.authors = ["Philip De Smedt"]
|
10
|
+
spec.email = ["philip.desmedt@gmail.com"]
|
11
|
+
spec.summary = "A Ruby interface to the Typeform Data API"
|
12
|
+
spec.description = "Implements the complete functionality of the Typeform Data API v0"
|
13
|
+
spec.homepage = "https://github.com/philipdesmedt/typeform"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.required_ruby_version = '>= 1.9.2'
|
21
|
+
spec.required_rubygems_version = '>= 1.3.5'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "minitest"
|
26
|
+
spec.add_development_dependency "vcr"
|
27
|
+
spec.add_development_dependency "webmock"
|
28
|
+
spec.add_runtime_dependency "hashie", "~> 3.0.0"
|
29
|
+
spec.add_runtime_dependency "httparty"
|
30
|
+
spec.add_runtime_dependency "json"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: typeform
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Philip De Smedt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-20 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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: minitest
|
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: vcr
|
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: webmock
|
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: hashie
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.0.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.0.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: httparty
|
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: json
|
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
|
+
description: Implements the complete functionality of the Typeform Data API v0
|
126
|
+
email:
|
127
|
+
- philip.desmedt@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- Gemfile
|
134
|
+
- LICENSE.txt
|
135
|
+
- README.md
|
136
|
+
- Rakefile
|
137
|
+
- lib/typeform.rb
|
138
|
+
- lib/typeform/form.rb
|
139
|
+
- lib/typeform/version.rb
|
140
|
+
- typeform.gemspec
|
141
|
+
homepage: https://github.com/philipdesmedt/typeform
|
142
|
+
licenses:
|
143
|
+
- MIT
|
144
|
+
metadata: {}
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: 1.9.2
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 1.3.5
|
159
|
+
requirements: []
|
160
|
+
rubyforge_project:
|
161
|
+
rubygems_version: 2.4.4
|
162
|
+
signing_key:
|
163
|
+
specification_version: 4
|
164
|
+
summary: A Ruby interface to the Typeform Data API
|
165
|
+
test_files: []
|