typeform-ruby-client 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 26dc648b3db80d4de8e071be5e274f0773e6700d26611b00ab3ca35d164b3471
4
+ data.tar.gz: cf44266fdfebba2de8f7b3385162e56cd9e25583853a8a26d9370404291ba9d4
5
+ SHA512:
6
+ metadata.gz: 4c1691d2d740bad74a11af7ba5a6bbb14b25b6530d3a2ce57bf933f848572977886edd06bae9643f0edc1e120f5503253cc618a262840e1a4e978bfd9f3def37
7
+ data.tar.gz: 7e66c4bba1a9ad18ddd051ecd4bfcf93a98f4314de1916828b9464f668cfab625256473f6a3ba2b134e2dc3f8fa0c9b795fb5bcf70a2c66d31d0d1667e30185c
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.overcommit.yml ADDED
@@ -0,0 +1,25 @@
1
+ CommitMsg:
2
+ ALL:
3
+ quiet: true
4
+ TextWidth:
5
+ enabled: true
6
+ max_subject_width: 72
7
+ max_body_width: 72
8
+ PreCommit:
9
+ BundleCheck:
10
+ enabled: true
11
+ HardTabs:
12
+ enabled: true
13
+ LineEndings:
14
+ enabled: true
15
+ MergeConflicts:
16
+ enabled: true
17
+ RuboCop:
18
+ enabled: true
19
+ command: ["bundle", "exec", "rubocop"] # Invoke within Bundler context
20
+ TrailingWhitespace:
21
+ enabled: true
22
+
23
+ # PrePush:
24
+ # Minitest:
25
+ # enabled: true
data/.rubocop.yml ADDED
@@ -0,0 +1,231 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-minitest
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.7
7
+ # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
8
+ # to ignore them, so only the ones explicitly set in this file are enabled.
9
+ DisabledByDefault: true
10
+
11
+ Performance:
12
+ Exclude:
13
+ - '**/test/**/*'
14
+
15
+ # Prefer &&/|| over and/or.
16
+ Style/AndOr:
17
+ Enabled: true
18
+
19
+ # Align `when` with `case`.
20
+ Layout/CaseIndentation:
21
+ Enabled: true
22
+
23
+ # Align comments with method definitions.
24
+ Layout/CommentIndentation:
25
+ Enabled: true
26
+
27
+ Layout/ElseAlignment:
28
+ Enabled: true
29
+
30
+ # Align `end` with the matching keyword or starting expression except for
31
+ # assignments, where it should be aligned with the LHS.
32
+ Layout/EndAlignment:
33
+ Enabled: true
34
+ EnforcedStyleAlignWith: variable
35
+ AutoCorrect: true
36
+
37
+ Layout/EmptyLineAfterMagicComment:
38
+ Enabled: true
39
+
40
+ Layout/EmptyLinesAroundAccessModifier:
41
+ Enabled: true
42
+ EnforcedStyle: only_before
43
+
44
+ Layout/EmptyLinesAroundBlockBody:
45
+ Enabled: true
46
+
47
+ # In a regular class definition, no empty lines around the body.
48
+ Layout/EmptyLinesAroundClassBody:
49
+ Enabled: true
50
+
51
+ # In a regular method definition, no empty lines around the body.
52
+ Layout/EmptyLinesAroundMethodBody:
53
+ Enabled: true
54
+
55
+ # In a regular module definition, no empty lines around the body.
56
+ Layout/EmptyLinesAroundModuleBody:
57
+ Enabled: true
58
+
59
+ # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
60
+ Style/HashSyntax:
61
+ Enabled: true
62
+
63
+ Layout/FirstArgumentIndentation:
64
+ Enabled: true
65
+
66
+ # Method definitions after `private` or `protected` isolated calls need one
67
+ # extra level of indentation.
68
+ Layout/IndentationConsistency:
69
+ Enabled: true
70
+ EnforcedStyle: indented_internal_methods
71
+
72
+ # Two spaces, no tabs (for indentation).
73
+ Layout/IndentationWidth:
74
+ Enabled: true
75
+
76
+ Layout/LeadingCommentSpace:
77
+ Enabled: true
78
+
79
+ Layout/SpaceAfterColon:
80
+ Enabled: true
81
+
82
+ Layout/SpaceAfterComma:
83
+ Enabled: true
84
+
85
+ Layout/SpaceAfterSemicolon:
86
+ Enabled: true
87
+
88
+ Layout/SpaceAroundEqualsInParameterDefault:
89
+ Enabled: true
90
+
91
+ Layout/SpaceAroundKeyword:
92
+ Enabled: true
93
+
94
+ Layout/SpaceBeforeComma:
95
+ Enabled: true
96
+
97
+ Layout/SpaceBeforeComment:
98
+ Enabled: true
99
+
100
+ Layout/SpaceBeforeFirstArg:
101
+ Enabled: true
102
+
103
+ Style/DefWithParentheses:
104
+ Enabled: true
105
+
106
+ # Defining a method with parameters needs parentheses.
107
+ Style/MethodDefParentheses:
108
+ Enabled: true
109
+
110
+ Style/FrozenStringLiteralComment:
111
+ Enabled: true
112
+ EnforcedStyle: always
113
+ Exclude:
114
+ - 'actionview/test/**/*.builder'
115
+ - 'actionview/test/**/*.ruby'
116
+ - 'actionpack/test/**/*.builder'
117
+ - 'actionpack/test/**/*.ruby'
118
+ - 'activestorage/db/migrate/**/*.rb'
119
+ - 'activestorage/db/update_migrate/**/*.rb'
120
+ - 'actionmailbox/db/migrate/**/*.rb'
121
+ - 'actiontext/db/migrate/**/*.rb'
122
+
123
+ Style/RedundantFreeze:
124
+ Enabled: true
125
+
126
+ # Use `foo {}` not `foo{}`.
127
+ Layout/SpaceBeforeBlockBraces:
128
+ Enabled: true
129
+
130
+ # Use `foo { bar }` not `foo {bar}`.
131
+ Layout/SpaceInsideBlockBraces:
132
+ Enabled: true
133
+ EnforcedStyleForEmptyBraces: space
134
+
135
+ # Use `{ a: 1 }` not `{a:1}`.
136
+ Layout/SpaceInsideHashLiteralBraces:
137
+ Enabled: true
138
+
139
+ Layout/SpaceInsideParens:
140
+ Enabled: true
141
+
142
+ # Check quotes usage according to lint rule below.
143
+ Style/StringLiterals:
144
+ Enabled: true
145
+ EnforcedStyle: double_quotes
146
+
147
+ # Detect hard tabs, no hard tabs.
148
+ Layout/IndentationStyle:
149
+ Enabled: true
150
+
151
+ # Blank lines should not have any spaces.
152
+ Layout/TrailingEmptyLines:
153
+ Enabled: true
154
+
155
+ # No trailing whitespace.
156
+ Layout/TrailingWhitespace:
157
+ Enabled: true
158
+
159
+ # Use quotes for string literals when they are enough.
160
+ Style/RedundantPercentQ:
161
+ Enabled: true
162
+
163
+ Lint/AmbiguousOperator:
164
+ Enabled: true
165
+
166
+ Lint/AmbiguousRegexpLiteral:
167
+ Enabled: true
168
+
169
+ Lint/ErbNewArguments:
170
+ Enabled: true
171
+
172
+ # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
173
+ Lint/RequireParentheses:
174
+ Enabled: true
175
+
176
+ Lint/ShadowingOuterLocalVariable:
177
+ Enabled: true
178
+
179
+ Lint/RedundantStringCoercion:
180
+ Enabled: true
181
+
182
+ Lint/UriEscapeUnescape:
183
+ Enabled: true
184
+
185
+ Lint/UselessAssignment:
186
+ Enabled: true
187
+
188
+ Lint/DeprecatedClassMethods:
189
+ Enabled: true
190
+
191
+ Style/ParenthesesAroundCondition:
192
+ Enabled: true
193
+
194
+ Style/RedundantBegin:
195
+ Enabled: true
196
+
197
+ Style/RedundantReturn:
198
+ Enabled: true
199
+ AllowMultipleReturnValues: true
200
+
201
+ Style/Semicolon:
202
+ Enabled: true
203
+ AllowAsExpressionSeparator: true
204
+
205
+ # Prefer Foo.method over Foo::method
206
+ Style/ColonMethodCall:
207
+ Enabled: true
208
+
209
+ Style/TrivialAccessors:
210
+ Enabled: true
211
+
212
+ Performance/FlatMap:
213
+ Enabled: true
214
+
215
+ Performance/RedundantMerge:
216
+ Enabled: true
217
+
218
+ Performance/StartWith:
219
+ Enabled: true
220
+
221
+ Performance/EndWith:
222
+ Enabled: true
223
+
224
+ Performance/RegexpMatch:
225
+ Enabled: true
226
+
227
+ Performance/ReverseEach:
228
+ Enabled: true
229
+
230
+ Performance/UnfreezeString:
231
+ Enabled: true
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at kimsuelim@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in channeltalk-ruby-client.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ typeform-ruby-client (0.1.2)
5
+ faraday (~> 0.15)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ childprocess (4.1.0)
12
+ codecov (0.6.0)
13
+ simplecov (>= 0.15, < 0.22)
14
+ coderay (1.1.3)
15
+ docile (1.4.0)
16
+ faraday (0.17.5)
17
+ multipart-post (>= 1.2, < 3)
18
+ iniparse (1.5.0)
19
+ method_source (1.0.0)
20
+ minitest (5.15.0)
21
+ multipart-post (2.1.1)
22
+ overcommit (0.58.0)
23
+ childprocess (>= 0.6.3, < 5)
24
+ iniparse (~> 1.4)
25
+ rexml (~> 3.2)
26
+ parallel (1.22.1)
27
+ parser (3.1.1.0)
28
+ ast (~> 2.4.1)
29
+ pry (0.14.1)
30
+ coderay (~> 1.1)
31
+ method_source (~> 1.0)
32
+ rainbow (3.1.1)
33
+ rake (12.3.3)
34
+ regexp_parser (2.3.0)
35
+ rexml (3.2.5)
36
+ rubocop (1.27.0)
37
+ parallel (~> 1.10)
38
+ parser (>= 3.1.0.0)
39
+ rainbow (>= 2.2.2, < 4.0)
40
+ regexp_parser (>= 1.8, < 3.0)
41
+ rexml
42
+ rubocop-ast (>= 1.16.0, < 2.0)
43
+ ruby-progressbar (~> 1.7)
44
+ unicode-display_width (>= 1.4.0, < 3.0)
45
+ rubocop-ast (1.17.0)
46
+ parser (>= 3.1.1.0)
47
+ rubocop-minitest (0.19.1)
48
+ rubocop (>= 0.90, < 2.0)
49
+ rubocop-performance (1.13.3)
50
+ rubocop (>= 1.7.0, < 2.0)
51
+ rubocop-ast (>= 0.4.0)
52
+ ruby-progressbar (1.11.0)
53
+ simplecov (0.21.2)
54
+ docile (~> 1.1)
55
+ simplecov-html (~> 0.11)
56
+ simplecov_json_formatter (~> 0.1)
57
+ simplecov-html (0.12.3)
58
+ simplecov_json_formatter (0.1.4)
59
+ unicode-display_width (2.1.0)
60
+ vcr (6.1.0)
61
+
62
+ PLATFORMS
63
+ x86_64-darwin-19
64
+
65
+ DEPENDENCIES
66
+ bundler
67
+ codecov
68
+ minitest (~> 5.0)
69
+ overcommit
70
+ pry
71
+ rake (~> 12.0)
72
+ rubocop
73
+ rubocop-minitest
74
+ rubocop-performance
75
+ simplecov
76
+ typeform-ruby-client!
77
+ vcr
78
+
79
+ BUNDLED WITH
80
+ 2.3.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Choi, Seung-youn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # Typeform Ruby Client
2
+
3
+ The Typeform Client for Ruby. Provides both resource oriented interfaces and API clients for Typeform services.
4
+
5
+ ## Links of Interest
6
+
7
+ * [Typeform API Docs](https://developer.typeform.com/)
8
+ * [Changelog](https://github.com/itdaa-dev/typeform-ruby-client/blob/main/CHANGELOG.md)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'typeform-ruby-client'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install typeform-ruby-client
25
+
26
+ ## Usage
27
+
28
+ ### Configuration
29
+
30
+ Before making requests, you must configure the gem with your key
31
+ and secret. If you are using Rails, you can do this in an initializer.
32
+
33
+ ```ruby
34
+ Typeform.configure do |config|
35
+ config.typeform_token = "YOUR PERSONAL TOKEN"
36
+ config.timeout = 10
37
+ config.debug = false
38
+ end
39
+ ```
40
+
41
+ ### API
42
+ ```ruby
43
+ * Typeform::Api::Form.retrieve_forms
44
+ * Typeform::Api::Form.retrieve_form(form_id)
45
+ * Typeform::Api::Response.retrieve_responses(form_id)
46
+ ```
47
+
48
+ ## Development
49
+
50
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
51
+
52
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/itdaa-dev/typeform-ruby-client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
61
+
62
+ ## Code of Conduct
63
+
64
+ Everyone interacting in the Typeform::Ruby::Client project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/itdaa-dev/typeform-ruby-client/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "zoom"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/changelog.md ADDED
@@ -0,0 +1,2 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typeform # :nodoc:
4
+ module Api
5
+ # users
6
+ class Form < Client
7
+ class << self
8
+ # retrieve forms
9
+ # def retrieve_forms(page_size: 200)
10
+ # parse(JSON.parse(connection.get("forms?page_size=#{page_size}").body))
11
+ # end
12
+ def retrieve_forms(workspace_id, page_size: 200, template: "Template")
13
+ parse(JSON.parse(connection.get("forms?page_size=#{page_size}&workspace_id=#{workspace_id}&search=#{template}").body))
14
+ end
15
+
16
+ # retrieve a form by a form_id
17
+ def retrieve_form(form_id)
18
+ parse(JSON.parse(connection.get("forms/#{form_id}").body))
19
+ end
20
+
21
+ def create_form(params)
22
+ res = connection.post("forms", params.to_json)
23
+ return JSON.parse(res.body.force_encoding("UTF-8"))["id"]
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typeform # :nodoc:
4
+ module Api
5
+ # users
6
+ class Response < Client
7
+ class << self
8
+ # retrieve reponses by a form_id
9
+ def retrieve_responses(form_id, page_size: 1000)
10
+ parse(JSON.parse(connection.get("forms/#{form_id}/responses?page_size=#{page_size}").body))
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typeform # :nodoc:
4
+ module Api
5
+ # users
6
+ class Workspace < Client
7
+ class << self
8
+ # retrieve forms
9
+ def retrieve_workspaces(page_size: 200)
10
+ parse(JSON.parse(connection.get("workspaces?page_size=#{page_size}").body))
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typeform # :nodoc:
4
+ # Common functionality across Typeform API objects.
5
+ class Client
6
+ # The connection object being used to communicate with Typeform.
7
+ # @return [Typeform::Connection] the connection
8
+ def connection
9
+ self.class.connection
10
+ end
11
+
12
+ # Converts the response body to an ObjectifiedHash.
13
+ def self.parse(body)
14
+ if body.is_a?(Hash)
15
+ body = body.deep_underscore_keys
16
+ ObjectifiedHash.new(body)
17
+ elsif body.is_a?(Array)
18
+ body = body.deep_underscore_keys
19
+ body.collect! { |e| ObjectifiedHash.new(e) }
20
+ elsif body
21
+ true
22
+ elsif !body
23
+ false
24
+ elsif body.nil?
25
+ false
26
+ else
27
+ raise Typeform::Error.new("Couldn't parse a response body")
28
+ end
29
+ end
30
+
31
+ class << self
32
+ # The connection object being used to communicate with Typeform.
33
+ # @return [Typeform::Connection] the connection
34
+ def connection
35
+ @@connection ||= Connection.new
36
+ end
37
+
38
+ # Assign a default connection object.
39
+ # @param conn [Typeform::Connection] the connection
40
+ # @return [Typeform::Connection] the connection
41
+ def connection=(conn)
42
+ @@connection = conn
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typeform
4
+ # Defines constants and methods related to configuration.
5
+ module Configuration
6
+ # An array of valid keys in the options hash when configuring a Typeform::Client.
7
+ OPTION_KEYS = [:typeform_token, :timeout, :debug]
8
+
9
+ # The user agent that will be sent to the API endpoint if none is set.
10
+ DEFAULT_USER_AGENT = "Typeform Ruby Client Gem #{Typeform::VERSION}"
11
+
12
+ # Base URI for the Typeform API.
13
+ DEFAULT_API_BASE_URI = "https://api.typeform.com/"
14
+
15
+ attr_accessor(*OPTION_KEYS)
16
+
17
+ # Convenience method to allow configuration options to be set in a block.
18
+ def configure
19
+ yield(self)
20
+ end
21
+
22
+ # Creates a hash of options and their values.
23
+ def options
24
+ options = {}
25
+ OPTION_KEYS.each { |key| options[key] = send(key) }
26
+ options
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typeform
4
+ class Connection
5
+ # Create a Connection object.
6
+ def initialize
7
+ @typeform_token = Typeform.typeform_token
8
+ @api_base_uri = Configuration::DEFAULT_API_BASE_URI
9
+ @headers = { user_agent: Configuration::DEFAULT_USER_AGENT }
10
+ @connection = Faraday.new(url: @api_base_uri, headers: @headers) do |faraday|
11
+ # faraday.request :multipart
12
+ faraday.request :url_encoded
13
+ faraday.response :logger if Typeform.debug
14
+ faraday.adapter :net_http
15
+ end
16
+ end
17
+
18
+ # Perform a GET request.
19
+ # @param path [String] The path at which to make ther request.
20
+ # @param params [Hash] A hash of request parameters.
21
+ def get(path, params = {})
22
+ request(:get, path, params)
23
+ end
24
+
25
+ # Perform a PUT request.
26
+ # @param path [String] The path at which to make ther request.
27
+ # @param params [Hash] A hash of request parameters.
28
+ def put(path, params = {})
29
+ request(:put, path, params)
30
+ end
31
+
32
+ # Perform a patch request.
33
+ # @param path [String] The path at which to make ther request.
34
+ # @param params [Hash] A hash of request parameters.
35
+ def patch(path, params = {})
36
+ request(:patch, path, params)
37
+ end
38
+
39
+ # Perform a POST request.
40
+ # @param path [String] The path at which to make ther request.
41
+ # @param params [Hash] A hash of request parameters.
42
+ def post(path, params = {})
43
+ request(:post, path, params)
44
+ end
45
+
46
+ # Perform a DELETE request.
47
+ # @param path [String] The path at which to make ther request.
48
+ # @param params [Hash] A hash of request parameters.
49
+ def delete(path, params = {})
50
+ request(:delete, path, params)
51
+ end
52
+
53
+ private
54
+ def request(verb, path, params = {})
55
+ raise ArgumentError.new "Invalid http verb #{verb}" unless [:get, :post, :put, :patch, :delete].include?(verb)
56
+
57
+ response = @connection.run_request(verb, path, params, auth_header) do |request|
58
+ request.params.update(params) if [:get, :delete].include?(verb) && params
59
+ request.headers["Content-Type"] = "application/json" if [:post, :put, :patch].include?(verb)
60
+ yield(request) if block_given?
61
+ end
62
+
63
+ unless (200..299).include?(response.status)
64
+ body = JSON.parse(response.body)
65
+ raise Typeform::Error.new(body)
66
+ end
67
+ response
68
+ end
69
+
70
+ def auth_header
71
+ {
72
+ "accept" => "application/json",
73
+ "authorization" => "Bearer #{@typeform_token}",
74
+ }
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Hash
4
+ # Returns a new hash with all keys converted using the +block+ operation.
5
+ def transform_keys
6
+ return enum_for(:transform_keys) { size } unless block_given?
7
+ result = {}
8
+ each_key do |key|
9
+ result[yield(key)] = self[key]
10
+ end
11
+ result
12
+ end unless method_defined?(:transform_keys)
13
+
14
+ # Returns a new hash with all keys converted to underscore strings.
15
+ #
16
+ # hash = { firstName: "Rob", lastName: "Bob" }
17
+ #
18
+ # hash.underscore_keys
19
+ # # => {:first_name=>"Rob", :last_name=>"Bob"}
20
+ def underscore_keys
21
+ transform_keys { |key| underscore_key(key) }
22
+ end
23
+
24
+ # Returns a new hash with all keys converted to camelcase strings.
25
+ #
26
+ # hash = { first_name: "Rob", last_name: "Bob" }
27
+ #
28
+ # hash.camelize_keys
29
+ # # => {:firstName=>"Rob", :lastName=>"Bob"}
30
+ def camelize_keys
31
+ transform_keys { |key| camelize_key(key) }
32
+ end
33
+
34
+ # Returns a new hash with all keys converted to underscore strings.
35
+ # This includes the keys from the root hash and from all
36
+ # nested hashes and arrays.
37
+ #
38
+ # hash = { person: { firstName: "Rob", lastName: "Bob" } }
39
+ #
40
+ # hash.deep_underscore_keys
41
+ # # => {:person=>{:first_name=>"Rob", :last_name=>"Bob"}}
42
+ def deep_underscore_keys
43
+ deep_transform_keys_in_object(self) { |key| underscore_key(key) }
44
+ end
45
+
46
+ # Returns a new hash with all keys converted to camelcase strings.
47
+ # This includes the keys from the root hash and from all
48
+ # nested hashes and arrays.
49
+ #
50
+ # hash = { person: { first_name: "Rob", last_name: "Bob" } }
51
+ #
52
+ # hash.deep_camelize_keys
53
+ # # => {:person=>{:firstName=>"Rob", :lastName=>"Bob"}}
54
+ def deep_camelize_keys
55
+ deep_transform_keys_in_object(self) { |key| camelize_key(key) }
56
+ end
57
+
58
+ private
59
+ # support methods for deep transforming nested hashes and arrays
60
+ def deep_transform_keys_in_object(object, &block)
61
+ case object
62
+ when Array
63
+ object.map { |e| deep_transform_keys_in_object(e, &block) }
64
+ when Hash
65
+ object.each_with_object({}) do |(key, value), result|
66
+ result[yield(key)] = deep_transform_keys_in_object(value, &block)
67
+ end
68
+ # Hash[object.map { |key, value| [yield(key), deep_transform_keys_in_object(value, &block)] }]
69
+ else
70
+ object
71
+ end
72
+ end
73
+
74
+ def underscore_key(key)
75
+ if key.is_a?(Symbol)
76
+ underscore(key.to_s).to_sym
77
+ elsif key.is_a?(String)
78
+ underscore(key)
79
+ else
80
+ key
81
+ end
82
+ end
83
+
84
+ def underscore(camel_cased_word)
85
+ return camel_cased_word unless /[A-Z-]|::/.match?(camel_cased_word)
86
+ word = camel_cased_word.to_s.gsub("::", "/")
87
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
88
+ word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
89
+ word.tr!("-", "_")
90
+ word.downcase!
91
+ word
92
+ end
93
+
94
+ def camelize_key(key)
95
+ if key.is_a?(Symbol)
96
+ camelize(key.to_s, :lower).to_sym
97
+ elsif key.is_a?(String)
98
+ camelize(key, :lower)
99
+ else
100
+ key
101
+ end
102
+ end
103
+
104
+ def camelize(underscore_word, first_letter = :upper)
105
+ word = underscore_word.to_s
106
+ case first_letter
107
+ when :upper
108
+ word = word.sub(/^[a-z\d]*/) { $&.capitalize }
109
+ when :lower
110
+ word = word.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase }
111
+ end
112
+
113
+ word.gsub!(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }
114
+ word.gsub!(/\//, "::")
115
+ word
116
+ end
117
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typeform # :nodoc:
4
+ # Raised when there is an error communicating with Typeform.
5
+ class Error < StandardError; end
6
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typeform
4
+ # Converts hashes to the objects.
5
+ class ObjectifiedHash
6
+ # Creates a new ObjectifiedHash object.
7
+ def initialize(hash)
8
+ @hash = hash
9
+ @data = hash.each_with_object({}) do | (key, value), data |
10
+ value = ObjectifiedHash.new(value) if value.is_a? Hash
11
+ data[key.to_s] = value
12
+ end
13
+ end
14
+
15
+ # @return [Hash] The original hash.
16
+ def to_hash
17
+ @hash
18
+ end
19
+ alias to_h to_hash
20
+
21
+ # @return [String] Formatted string with the class name, object id and original hash.
22
+ def inspect
23
+ "#<#{self.class}:#{object_id} {hash: #{@hash.inspect}}"
24
+ end
25
+
26
+ # Delegate to ObjectifiedHash.
27
+ def method_missing(key)
28
+ @data.key?(key.to_s) ? @data[key.to_s] : super
29
+ end
30
+
31
+ def respond_to_missing?(method_name, include_private = false)
32
+ @hash.keys.map(&:to_sym).include?(method_name.to_sym) || super
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typeform
4
+ VERSION = "0.1.2"
5
+ end
data/lib/typeform.rb ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+
5
+ require "typeform/version"
6
+ require "typeform/core_ext/hash/keys"
7
+ require "typeform/configuration"
8
+ require "typeform/connection"
9
+ require "typeform/client"
10
+ require "typeform/error"
11
+ require "typeform/objectified_hash"
12
+
13
+ require "typeform/api/form"
14
+ require "typeform/api/response"
15
+ require "typeform/api/workspace"
16
+
17
+ module Typeform
18
+ extend Configuration
19
+ end
data/t ADDED
File without changes
@@ -0,0 +1,42 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "typeform/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "typeform-ruby-client"
7
+ spec.version = Typeform::VERSION
8
+ spec.authors = ["Choi, Seung-youn"]
9
+ spec.email = ["alchemist718@gmail.com"]
10
+
11
+ spec.summary = "Typeform Ruby Client"
12
+ spec.description = "The Typeform Client for Ruby. Provides both resource oriented interfaces and API clients for Typeform services."
13
+ spec.homepage = "https://github.com/itdaa-dev/typeform-ruby-client"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/itdaa-dev/typeform-ruby-client"
18
+ spec.metadata["changelog_uri"] = "https://github.com/itdaa-dev/typeform-ruby-client/changelog"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "faraday", "~> 0.15"
30
+
31
+ spec.add_development_dependency "bundler"
32
+ spec.add_development_dependency "rake", "~> 12.0"
33
+ spec.add_development_dependency "minitest", "~> 5.0"
34
+ spec.add_development_dependency "vcr"
35
+ spec.add_development_dependency "rubocop"
36
+ spec.add_development_dependency "rubocop-performance"
37
+ spec.add_development_dependency "rubocop-minitest"
38
+ spec.add_development_dependency "simplecov"
39
+ spec.add_development_dependency "codecov"
40
+ spec.add_development_dependency "pry"
41
+ spec.add_development_dependency "overcommit"
42
+ end
metadata ADDED
@@ -0,0 +1,241 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: typeform-ruby-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Choi, Seung-youn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-04-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.15'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
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: rubocop
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: rubocop-performance
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
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: rubocop-minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
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: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
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: codecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: overcommit
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: The Typeform Client for Ruby. Provides both resource oriented interfaces
182
+ and API clients for Typeform services.
183
+ email:
184
+ - alchemist718@gmail.com
185
+ executables: []
186
+ extensions: []
187
+ extra_rdoc_files: []
188
+ files:
189
+ - ".gitignore"
190
+ - ".overcommit.yml"
191
+ - ".rubocop.yml"
192
+ - ".ruby-version"
193
+ - CODE_OF_CONDUCT.md
194
+ - Gemfile
195
+ - Gemfile.lock
196
+ - LICENSE.txt
197
+ - README.md
198
+ - Rakefile
199
+ - bin/console
200
+ - bin/setup
201
+ - changelog.md
202
+ - lib/typeform.rb
203
+ - lib/typeform/api/form.rb
204
+ - lib/typeform/api/response.rb
205
+ - lib/typeform/api/workspace.rb
206
+ - lib/typeform/client.rb
207
+ - lib/typeform/configuration.rb
208
+ - lib/typeform/connection.rb
209
+ - lib/typeform/core_ext/hash/keys.rb
210
+ - lib/typeform/error.rb
211
+ - lib/typeform/objectified_hash.rb
212
+ - lib/typeform/version.rb
213
+ - t
214
+ - typeform-ruby-client.gemspec
215
+ homepage: https://github.com/itdaa-dev/typeform-ruby-client
216
+ licenses:
217
+ - MIT
218
+ metadata:
219
+ homepage_uri: https://github.com/itdaa-dev/typeform-ruby-client
220
+ source_code_uri: https://github.com/itdaa-dev/typeform-ruby-client
221
+ changelog_uri: https://github.com/itdaa-dev/typeform-ruby-client/changelog
222
+ post_install_message:
223
+ rdoc_options: []
224
+ require_paths:
225
+ - lib
226
+ required_ruby_version: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - ">="
229
+ - !ruby/object:Gem::Version
230
+ version: '0'
231
+ required_rubygems_version: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - ">="
234
+ - !ruby/object:Gem::Version
235
+ version: '0'
236
+ requirements: []
237
+ rubygems_version: 3.1.6
238
+ signing_key:
239
+ specification_version: 4
240
+ summary: Typeform Ruby Client
241
+ test_files: []