paperform-ruby 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d483735478590697492be1a869f9536ef36275642a1ae95922cc94d65bc8caf8
4
- data.tar.gz: 4c605b376aff5dd81ad32d21f63dc96436db4bb2b1ca19a090c6339af6c88ef6
3
+ metadata.gz: 6060b4b81e688eb3c68472179a88537db75e07ff551ee978e015bfc17f3b973b
4
+ data.tar.gz: 38fe05801fb68fa25a66e19afabd55ed9930bcc7c47c85bae09410aaf00d6e4d
5
5
  SHA512:
6
- metadata.gz: 5f7f619a11e75537b0c858e0714f65f0ba5bd7b55c46e887bb12c3d838f2309907737c7b1b92535c48ed36280d28adba657ead24055bc97e34b8343a40f4f152
7
- data.tar.gz: 482dd37a6075cfbf8c5e661015bf7e897e64b8a82510d8f7c187464bf5657801c96a7c99eb363fe113723fec4e731725b30474123530a0a2fb436a5d7be48945
6
+ metadata.gz: 6059550d0a533cd613c6411fa20da16191b320c0ae115625a8bd2bf2e3df4955babe426298884d1479c17ec423a352415891355a67d5a9ff7fe84cf1bdede5bb
7
+ data.tar.gz: dc9beef02f378f066d90da442849cf8d174c705c6fb3a52224f48e2b41e8f38181f50a61f4ccbfa8ba2cb280e462c73d2e89b34daca1578252d2ee108a5520b4
@@ -0,0 +1,29 @@
1
+ name: Tests
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - "*"
7
+ push:
8
+ branches:
9
+ - master
10
+ jobs:
11
+ tests:
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ matrix:
15
+ ruby: ["2.5", "2.6", "2.7", "3.0"]
16
+
17
+ steps:
18
+ - uses: actions/checkout@master
19
+
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ bundler: default
25
+ bundler-cache: true
26
+
27
+ - name: Run tests
28
+ run: |
29
+ bundle exec rake test
data/Gemfile CHANGED
@@ -5,4 +5,3 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
5
5
  # Specify your gem's dependencies in paperform-ruby.gemspec
6
6
  gemspec
7
7
 
8
- gem 'curb'
data/Gemfile.lock CHANGED
@@ -1,37 +1,51 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paperform-ruby (1.0.0)
4
+ paperform-ruby (2.0.0)
5
+ faraday (~> 1.7)
6
+ faraday_middleware (~> 1.1)
5
7
 
6
8
  GEM
7
9
  remote: https://rubygems.org/
8
10
  specs:
9
- curb (0.9.10)
10
- diff-lcs (1.3)
11
- rake (10.5.0)
12
- rspec (3.8.0)
13
- rspec-core (~> 3.8.0)
14
- rspec-expectations (~> 3.8.0)
15
- rspec-mocks (~> 3.8.0)
16
- rspec-core (3.8.2)
17
- rspec-support (~> 3.8.0)
18
- rspec-expectations (3.8.4)
19
- diff-lcs (>= 1.2.0, < 2.0)
20
- rspec-support (~> 3.8.0)
21
- rspec-mocks (3.8.1)
22
- diff-lcs (>= 1.2.0, < 2.0)
23
- rspec-support (~> 3.8.0)
24
- rspec-support (3.8.2)
11
+ faraday (1.10.0)
12
+ faraday-em_http (~> 1.0)
13
+ faraday-em_synchrony (~> 1.0)
14
+ faraday-excon (~> 1.1)
15
+ faraday-httpclient (~> 1.0)
16
+ faraday-multipart (~> 1.0)
17
+ faraday-net_http (~> 1.0)
18
+ faraday-net_http_persistent (~> 1.0)
19
+ faraday-patron (~> 1.0)
20
+ faraday-rack (~> 1.0)
21
+ faraday-retry (~> 1.0)
22
+ ruby2_keywords (>= 0.0.4)
23
+ faraday-em_http (1.0.0)
24
+ faraday-em_synchrony (1.0.0)
25
+ faraday-excon (1.1.0)
26
+ faraday-httpclient (1.0.1)
27
+ faraday-multipart (1.0.3)
28
+ multipart-post (>= 1.2, < 3)
29
+ faraday-net_http (1.0.1)
30
+ faraday-net_http_persistent (1.2.0)
31
+ faraday-patron (1.0.0)
32
+ faraday-rack (1.0.0)
33
+ faraday-retry (1.0.3)
34
+ faraday_middleware (1.2.0)
35
+ faraday (~> 1.0)
36
+ minitest (5.15.0)
37
+ multipart-post (2.1.1)
38
+ rake (13.0.6)
39
+ ruby2_keywords (0.0.5)
25
40
 
26
41
  PLATFORMS
27
42
  ruby
28
43
 
29
44
  DEPENDENCIES
30
- bundler (~> 1.16)
31
- curb
45
+ bundler (~> 2.3.4)
46
+ minitest (~> 5.0)
32
47
  paperform-ruby!
33
- rake (~> 10.0)
34
- rspec (~> 3.0)
48
+ rake (~> 13.0)
35
49
 
36
50
  BUNDLED WITH
37
- 1.16.6
51
+ 2.3.4
data/README.md CHANGED
@@ -22,42 +22,81 @@ Or install it yourself as:
22
22
 
23
23
  Head to the [developer documentation page](https://paperform.co/developer/api-v1-documentation/) on the paperform website for general info about the api. To get started, you'll need to generate a token. This will serve as the bearer token passed with every request you send to Paperform. Visit [this page](https://paperform.co/account/developer) in your paperform account to generate one. Note that you'll need to have a Pro or Agency account in order to use the API. Store this somewhere in your rails app (like a .env file or something). From there, you can use the gem like this:
24
24
 
25
- ### Submissions
25
+
26
+ ## Auth
27
+
28
+ After we have gotten our token, we just need to initialize the client
26
29
 
27
30
  ```ruby
28
- require 'paperform'
31
+ client = Paperform::Client.new(token: token)
32
+ ```
29
33
 
30
- submission = Paperform::Submission.new(ENV['PAPERFORM_TOKEN']) # assuming I stored my paperform token in the env variable PAPERFORM_TOKEN
34
+ Every request returns a JSON body response
31
35
 
32
- submission.list('sample-form') # this is the slug prefix in your paperform url. Ie, sample-form.paperform.co.
36
+ ## Forms
37
+ ```ruby
38
+ client.forms
39
+ ```
40
+
41
+ You can also pass in parameters that you need.
33
42
 
34
- submission.list('<uuid>') # this is the uuid of the submission. You can find this value for a given submission in your paperform account
43
+ ```ruby
44
+ client.forms(limit: 200, skip: 3)
45
+ ``
35
46
 
47
+ ## Form
48
+
49
+ ```ruby
50
+ client.form(slug_or_id)
51
+ ```
52
+
53
+ ## Form Fields
54
+
55
+ ```ruby
56
+ client.form_fields(slug_or_id)
36
57
  ```
37
58
 
38
- This will return a list of submitted forms. You can also pass an options hash as a second parameter. Check the developer documentation link above for attributes you can send in this options hash.
59
+ ## Partial Submissions
39
60
 
61
+ ```ruby
62
+ client.partial_submissions
63
+ ```
64
+ You can also pass in parameters that you need.
40
65
 
41
- ### Partial Submissions
66
+ ```ruby
67
+ client.partial_submissions(limit: 200, skip: 3)
68
+ ```
69
+
70
+ ## Partial Submission
42
71
 
43
72
  ```ruby
44
- require 'paperform'
73
+ client.partial_submission(slug_or_id)
74
+ ```
45
75
 
46
- partial_sub = Paperform::PartialSubmission.new(ENV['PAPERFORM_TOKEN']) # assuming I stored my paperform token in the env variable PAPERFORM_TOKEN
47
76
 
48
- partial_sub.list('sample-form') # this is the slug prefix in your paperform url. Ie, sample-form.paperform.co.
77
+ ## Submissions
49
78
 
50
- partial_sub.list('<uuid>') # this is the uuid of the submission. You can find this value for a given submission in your paperform account
79
+ ```ruby
80
+ client.submissions
81
+ ```
82
+ You can also pass in parameters that you need.
51
83
 
84
+ ```ruby
85
+ client.submissions(limit: 200, skip: 3)
52
86
  ```
53
87
 
54
- This will return a list of partially submitted forms. You can also pass an options hash as a second parameter. Check the developer documentation link above for attributes you can send in this options hash.
88
+ ## Submission
89
+
90
+ ```ruby
91
+ client._submission(slug_or_id)
92
+ ```
55
93
 
56
94
 
57
95
  ## Contributing
58
96
 
59
97
  Bug reports and pull requests are welcome on GitHub at https://github.com/nekapoor/paperform-ruby.
60
98
 
99
+
61
100
  ## License
62
101
 
63
102
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,6 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
2
+ require "rake/testtask"
3
3
 
4
- RSpec::Core::RakeTask.new(:spec)
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
5
9
 
6
- task :default => :spec
10
+ task default: :test
data/bin/console CHANGED
@@ -10,5 +10,6 @@ require "paperform"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
+ client = Paperform::Client.new(token: ENV["PAPERFORM_TOKEN"])
13
14
  require "irb"
14
15
  IRB.start(__FILE__)
@@ -0,0 +1,79 @@
1
+ module Paperform
2
+ class Client
3
+ BASE_URL = 'https://api.paperform.co/v1'
4
+ attr_reader :token
5
+
6
+ def initialize(token:, stubs: nil)
7
+ @token = token
8
+ @stubs = stubs
9
+ end
10
+
11
+ # GET /forms https://paperform.co/developer/api-v1-documentation/#tag/forms
12
+ def forms(**params)
13
+ handle_response connection.get('forms', params)
14
+ end
15
+
16
+ # GET https://paperform.co/developer/api-v1-documentation/#operation/Get%20Form
17
+ def form(slug_or_id)
18
+ handle_response connection.get("forms/#{slug_or_id}")
19
+ end
20
+
21
+ # GET https://paperform.co/developer/api-v1-documentation/#operation/Get%20Form%20Fields
22
+ def form_fields(slug_or_id)
23
+ handle_response connection.get("forms/#{slug_or_id}/fields")
24
+ end
25
+
26
+ # GET https://paperform.co/developer/api-v1-documentation/#operation/List%20Partial%20Submissions
27
+ def partial_submissions(**params)
28
+ handle_response connection.get('partial-submissions')
29
+ end
30
+
31
+
32
+ # GET https://paperform.co/developer/api-v1-documentation/#operation/Get%20Partial%20Submission
33
+ def partial_submission(slug_or_id)
34
+ handle_response connection.get("partial-submissions/#{slug_or_id}")
35
+ end
36
+
37
+ # GET https://paperform.co/developer/api-v1-documentation/#operation/List%20Submissions
38
+ def submissions(form:, **params)
39
+ handle_response(connection.get('submissions', {form: form}.merge(params)))
40
+ end
41
+
42
+ # GET https://paperform.co/developer/api-v1-documentation/#operation/Get%20Submission
43
+ def submission(slug_or_id)
44
+ handle_response connection.get("submissions/#{slug_or_id}")
45
+ end
46
+
47
+ private
48
+
49
+ def connection
50
+ @connection ||= Faraday.new(url: BASE_URL) do |faraday|
51
+ faraday.headers['Authorization'] = "Bearer #{@token}"
52
+ if @stubs
53
+ faraday.adapter :test, @stubs
54
+ end
55
+ end
56
+ end
57
+
58
+
59
+ def handle_response(response)
60
+ case response.status
61
+ when 200
62
+ response.body
63
+ when 400
64
+ raise Error, response.body
65
+ when 401
66
+ raise Error, response.body
67
+ when 403
68
+ raise Error, response.body
69
+ when 404
70
+ raise Error, response.body
71
+ when 422
72
+ raise Error, response.body
73
+ when 500
74
+ raise Error, "Possible Internal Server Error"
75
+ end
76
+ JSON.parse response.body
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,3 @@
1
+ module Paperform
2
+ class Error < StandardError; end
3
+ end
@@ -0,0 +1 @@
1
+ require 'paperform'
data/lib/paperform.rb CHANGED
@@ -1,2 +1,8 @@
1
- require 'paperform/partial_submission'
2
- require 'paperform/submission'
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "json"
4
+
5
+ module Paperform
6
+ autoload :Client, "paperform/client"
7
+ autoload :Error, "paperform/error"
8
+ end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "paperform-ruby"
7
- spec.version = "1.0.0"
7
+ spec.version = "2.0.0"
8
8
  spec.authors = ["Neeraj Kapoor"]
9
9
  spec.email = ["neeraj.kapoor@learntobe.org"]
10
10
 
@@ -22,7 +22,10 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_development_dependency "bundler", "~> 1.16"
26
- spec.add_development_dependency "rake", "~> 10.0"
27
- spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "bundler", "~> 2.3.4"
26
+ spec.add_development_dependency "rake", "~> 13.0"
27
+ spec.add_development_dependency "minitest", "~> 5.0"
28
+
29
+ spec.add_dependency "faraday", "~> 1.7"
30
+ spec.add_dependency "faraday_middleware", "~> 1.1"
28
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperform-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neeraj Kapoor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-28 00:00:00.000000000 Z
11
+ date: 2022-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,42 +16,70 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: 2.3.4
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: 2.3.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '5.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday_middleware
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
55
83
  description: A wrapper around the paperform api.
56
84
  email:
57
85
  - neeraj.kapoor@learntobe.org
@@ -59,6 +87,7 @@ executables: []
59
87
  extensions: []
60
88
  extra_rdoc_files: []
61
89
  files:
90
+ - ".github/workflows/ci.yml"
62
91
  - ".gitignore"
63
92
  - ".rspec"
64
93
  - ".travis.yml"
@@ -69,9 +98,10 @@ files:
69
98
  - Rakefile
70
99
  - bin/console
71
100
  - bin/setup
101
+ - lib/paperform-ruby.rb
72
102
  - lib/paperform.rb
73
- - lib/paperform/partial_submission.rb
74
- - lib/paperform/submission.rb
103
+ - lib/paperform/client.rb
104
+ - lib/paperform/error.rb
75
105
  - paperform-ruby.gemspec
76
106
  homepage: https://github.com/nekapoor/paperform-ruby
77
107
  licenses:
@@ -92,8 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
122
  - !ruby/object:Gem::Version
93
123
  version: '0'
94
124
  requirements: []
95
- rubyforge_project:
96
- rubygems_version: 2.7.8
125
+ rubygems_version: 3.0.3
97
126
  signing_key:
98
127
  specification_version: 4
99
128
  summary: A wrapper around the paperform api.
@@ -1,32 +0,0 @@
1
- module Paperform
2
- class PartialSubmission
3
- attr_reader :token
4
-
5
- BASE_URL = 'https://api.paperform.co/v1/partial-submissions'
6
-
7
- def initialize(token)
8
- @token = token
9
- end
10
-
11
- def find(id)
12
- params = { id: id }
13
-
14
- response = Curl.get(BASE_URL, params) do |http|
15
- http.headers['Authorization'] = "Bearer #{token}"
16
- end
17
-
18
- response.body
19
- end
20
-
21
- def list(form_id, options = nil)
22
- params = { form: form_id }
23
- params.merge!(options) if options
24
-
25
- response = Curl.get(BASE_URL, params) do |http|
26
- http.headers['Authorization'] = "Bearer #{token}"
27
- end
28
-
29
- response.body
30
- end
31
- end
32
- end
@@ -1,32 +0,0 @@
1
- module Paperform
2
- class Submission
3
- attr_reader :token
4
-
5
- BASE_URL = 'https://api.paperform.co/v1/submissions'
6
-
7
- def initialize(token)
8
- @token = token
9
- end
10
-
11
- def find(id)
12
- params = { id: id }
13
-
14
- response = Curl.get(BASE_URL, params) do |http|
15
- http.headers['Authorization'] = "Bearer #{token}"
16
- end
17
-
18
- response.body
19
- end
20
-
21
- def list(form_id, options = nil)
22
- params = { form: form_id }
23
- params.merge!(options) if options
24
-
25
- response = Curl.get(BASE_URL, params) do |http|
26
- http.headers['Authorization'] = "Bearer #{token}"
27
- end
28
-
29
- response.body
30
- end
31
- end
32
- end