panda_doc 0.0.1

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
+ SHA1:
3
+ metadata.gz: 6ebb23e4abe4534d913bab229afc9e8881a62b53
4
+ data.tar.gz: d7f6f1562bd1187790e78ce70a2a262d4f1a5b2a
5
+ SHA512:
6
+ metadata.gz: 56b872850b068389570cc8d2662967aba03b84d727666660724656ae1693b022213f928564519d38ff08d754e0d3a2060be1169d58af70fd778d5e75a46f80cf
7
+ data.tar.gz: 620ad9bab0834711147428a159c5a84539079117a180feff08885fad886364fe7553721d93642cb766fdf7f5ebef61931632535261553596cafa5c45a871a362
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+
3
+ cache:
4
+ - bundler
5
+
6
+ rvm:
7
+ - 2.2.4
8
+ - 2.3.0
9
+
10
+ addons:
11
+ code_climate:
12
+ repo_token: d1d9c0636042863489880dbdf1c8865721b9b70f4199d612d77ee2dcfc803704
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [Unreleased]
6
+
7
+ ## 0.0.1 (2016-02-03)
8
+
9
+ - Initial release
10
+
11
+ [Unreleased]: https://github.com/opti/panda_doc/compare/v0.0.1...HEAD
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in panda_doc.gemspec
4
+ gemspec
5
+
6
+ gem "bundler", "~> 1.11"
7
+ gem "rake", "~> 10.0"
8
+ gem "rspec", "~> 3.4"
9
+ gem "byebug"
10
+
11
+ group :test do
12
+ gem "codeclimate-test-reporter", require: false
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Igor Pstyga
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,144 @@
1
+ # PandaDoc
2
+
3
+ PandaDoc gem is a simple wrapper for PandaDoc.com API. Please check the official
4
+ API [documenation](https://developers.pandadoc.com) for more details.
5
+
6
+ [![Build Status](https://travis-ci.org/opti/panda_doc.svg?branch=master)](http://travis-ci.org/opti/panda_doc)
7
+ [![Code Climate](https://codeclimate.com/github/opti/panda_doc/badges/gpa.svg)](https://codeclimate.com/github/opti/panda_doc)
8
+ [![Test Coverage](https://codeclimate.com/github/opti/panda_doc/badges/coverage.svg)](https://codeclimate.com/github/opti/panda_doc/coverage)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'panda_doc'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install panda_doc
25
+
26
+ ## Configuration
27
+
28
+ Please refer to the [Authentication](https://developers.pandadoc.com/#authentication)
29
+ documentation to get the idea how to get an access token.
30
+
31
+ ```ruby
32
+ PandaDoc.configure do |config|
33
+ config.access_token = "an access token"
34
+ end
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ Every response wrapped into a ruby object with values coerced in corresponding types.
40
+
41
+ #### Creating a document
42
+
43
+ ```ruby
44
+ PandaDoc::Document.create(
45
+ name: "Sample Document",
46
+ url: "url_to_a_document",
47
+ recipients: [
48
+ {
49
+ email: "john.appleseed@yourdomain.com",
50
+ first_name: "John",
51
+ last_name: "Appleseed",
52
+ role: "Signer",
53
+ default: false
54
+ }
55
+ ],
56
+ fields: {
57
+ field_id: {
58
+ title: "Field 1"
59
+ }
60
+ }
61
+ )
62
+
63
+ document.uuid # => "oovHPtkwDqEAvaKmdud"
64
+ document.name # => "Sample Document"
65
+ document.status # => "document.uploaded"
66
+ document.created_at # => #<DateTime: 2016-02-03T14:56:21-08:00>
67
+ document.updated_at # => #<DateTime: 2016-02-03T14:56:21-08:00>
68
+ ```
69
+
70
+ #### Creating a document from a template
71
+
72
+ ```ruby
73
+ document = PandaDoc::Document.create(
74
+ name: "Sample Document",
75
+ template_uuid: "uuid_of_the_template",
76
+ recipients: [
77
+ {
78
+ email: "john.appleseed@yourdomain.com",
79
+ first_name: "John",
80
+ last_name: "Appleseed",
81
+ role: "Signer",
82
+ default: false
83
+ }
84
+ ],
85
+ fields: {
86
+ field_id: {
87
+ value: "Field 1"
88
+ }
89
+ }
90
+ )
91
+ ```
92
+
93
+ #### Sending a document
94
+
95
+ ```ruby
96
+ PandaDoc::Document.send("UUID", message: "A message to include into the email")
97
+ ```
98
+
99
+ #### Ccreating a View Session
100
+
101
+ ```ruby
102
+ session = PandaDoc::Document.session("UUID",
103
+ recipient: "john.applessed@yourdoamin.com",
104
+ lifetime: 300
105
+ )
106
+
107
+ session.id # => "adssdAvyDXBS"
108
+ session.expires_at # => #<DateTime: 2016-02-03T14:56:21-08:00>
109
+ ```
110
+
111
+ #### Error handling
112
+
113
+ If an error occurs during an API request it will be wrapped into a plain ruby
114
+ object as well.
115
+
116
+ ```ruby
117
+ response = PandaDoc::Document.create(name: "Sample Document")
118
+
119
+ if response.success?
120
+ uuid = response.uuid
121
+ else
122
+ puts response.error.message
123
+ end
124
+ ```
125
+
126
+ ## Development
127
+
128
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
129
+
130
+ 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).
131
+
132
+ ## Contributing
133
+
134
+ Bug reports and pull requests are welcome on GitHub at https://github.com/opti/panda_doc.
135
+
136
+ 1. Fork it ( https://github.com/opti/panda_doc/fork )
137
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
138
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
139
+ 4. Push to the branch (`git push origin my-new-feature`)
140
+ 5. Create a new Pull Request
141
+
142
+ ## License
143
+
144
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ desc "Run specs"
5
+ RSpec::Core::RakeTask.new(:spec) do |task|
6
+ task.verbose = false
7
+ end
8
+
9
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "panda_doc"
5
+
6
+ require "irb"
7
+ require "irb/completion"
8
+ require "byebug"
9
+ IRB.start
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
@@ -0,0 +1,43 @@
1
+ module PandaDoc
2
+ class ApiClient
3
+
4
+ class << self
5
+ def request(verb, path, **data)
6
+ new.public_send(verb, path, data)
7
+ end
8
+ end
9
+
10
+ attr_reader :connection
11
+
12
+ attr_reader :url_prefix
13
+ private :url_prefix
14
+
15
+ def initialize
16
+ @url_prefix = "/public/v1"
17
+ @connection = Faraday.new(PandaDoc.configuration.endpoint) do |conn|
18
+ conn.authorization :Bearer, PandaDoc.configuration.access_token
19
+ conn.request :json
20
+ conn.response :json, content_type: /\bjson$/
21
+ conn.adapter Faraday.default_adapter
22
+ end
23
+ end
24
+
25
+ def post(path, **data)
26
+ connection.post(normalized_path(path), data)
27
+ end
28
+
29
+ def get(path, **data)
30
+ connection.get(normalized_path(path), data)
31
+ end
32
+
33
+ private
34
+
35
+ def normalized_path(path)
36
+ url_prefix + normalize_path(path)
37
+ end
38
+
39
+ def normalize_path(path)
40
+ Faraday::Utils.normalize_path(path)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,23 @@
1
+ module PandaDoc
2
+ class Configuration
3
+ attr_accessor :access_token
4
+
5
+ def endpoint
6
+ "https://api.pandadoc.com"
7
+ end
8
+ end
9
+
10
+ class << self
11
+ def configuration
12
+ @configuration ||= Configuration.new
13
+ end
14
+
15
+ def configuration=(config)
16
+ @configuration = config
17
+ end
18
+
19
+ def configure
20
+ yield configuration
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ module PandaDoc
2
+ module Document
3
+ extend self
4
+
5
+ def create(data)
6
+ respond(ApiClient.request(:post, "/documents", data))
7
+ end
8
+
9
+ def send(uuid, **data)
10
+ respond(ApiClient.request(:post, "/documents/#{uuid}/send", data))
11
+ end
12
+
13
+ def session(uuid, **data)
14
+ respond(
15
+ ApiClient.request(:post, "/documents/#{uuid}/session", data),
16
+ type: :session
17
+ )
18
+ end
19
+
20
+ private
21
+
22
+ def respond(response, type: :document)
23
+ return FailureResult.new(response) unless response.success?
24
+
25
+ SuccessResult.new(
26
+ ResponseFactory.new(type).build.from_hash(response.body)
27
+ )
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,16 @@
1
+ module PandaDoc
2
+ class FailureResult
3
+ extend Forwardable
4
+ def_delegators :response, :status, :success?
5
+
6
+ attr_reader :error
7
+
8
+ attr_reader :response
9
+ private :response
10
+
11
+ def initialize(response)
12
+ @response = response
13
+ @error = Responses::Error.new(Objects::Error.new).from_hash(response.body)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module PandaDoc
2
+ module Objects
3
+ class Document
4
+ include Virtus.model
5
+
6
+ attribute :uuid, String
7
+ attribute :status, String
8
+ attribute :name, String
9
+ attribute :recipients, Array[Objects::Recipient]
10
+ attribute :created_at, DateTime
11
+ attribute :updated_at, DateTime
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module PandaDoc
2
+ module Objects
3
+ class Error
4
+ include Virtus.model
5
+
6
+ attribute :type, String
7
+ attribute :message, String
8
+ attribute :code, String
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module PandaDoc
2
+ module Objects
3
+ class Recipient
4
+ include Virtus.model
5
+
6
+ attribute :email, String
7
+ attribute :first_name, String
8
+ attribute :last_name, String
9
+ attribute :recipient_type, String
10
+ attribute :has_completed, Axiom::Types::Boolean
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ module PandaDoc
2
+ module Objects
3
+ class Session
4
+ include Virtus.model
5
+
6
+ attribute :id, String
7
+ attribute :expires_at, DateTime
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,28 @@
1
+ module PandaDoc
2
+ class ResponseFactory
3
+ attr_reader :type
4
+ private :type
5
+
6
+ def initialize(type)
7
+ @type = type.capitalize
8
+ end
9
+
10
+ def build
11
+ response_class.new(object_class.new)
12
+ end
13
+
14
+ private
15
+
16
+ def response_class
17
+ class_for("Responses")
18
+ end
19
+
20
+ def object_class
21
+ class_for("Objects")
22
+ end
23
+
24
+ def class_for(namespace)
25
+ Object.const_get("PandaDoc::#{namespace}::#{type}")
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ module PandaDoc
2
+ module Responses
3
+ class Document < Representable::Decorator
4
+ include Representable::Hash
5
+
6
+ property :uuid
7
+ property :status
8
+ property :name
9
+ property :created_at, as: :date_created
10
+ property :updated_at, as: :date_modified
11
+
12
+ collection :recipients, class: PandaDoc::Objects::Recipient do
13
+ property :email
14
+ property :first_name
15
+ property :last_name
16
+ property :recipient_type
17
+ property :has_completed
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ module PandaDoc
2
+ module Responses
3
+ class Error < Representable::Decorator
4
+ include Representable::Hash
5
+
6
+ property :type
7
+
8
+ nested :detail do
9
+ property :message
10
+ property :code
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ module PandaDoc
2
+ module Responses
3
+ class Session < Representable::Decorator
4
+ include Representable::Hash
5
+
6
+ property :id
7
+ property :expires_at
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,26 @@
1
+ module PandaDoc
2
+ class SuccessResult
3
+ attr_reader :object
4
+ private :object
5
+
6
+ def initialize(object)
7
+ @object = object
8
+ end
9
+
10
+ def success?
11
+ true
12
+ end
13
+
14
+ def method_missing(method_name, *arguments, &block)
15
+ if object.respond_to?(method_name)
16
+ object.send(method_name, *arguments, &block)
17
+ else
18
+ super
19
+ end
20
+ end
21
+
22
+ def respond_to_missing?(method_name, include_private = false)
23
+ object.respond_to?(method_name) || super
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module PandaDoc
2
+ VERSION = "0.0.1"
3
+ end
data/lib/panda_doc.rb ADDED
@@ -0,0 +1,26 @@
1
+ require "forwardable"
2
+
3
+ require "faraday"
4
+ require "faraday_middleware"
5
+ require "virtus"
6
+ require "representable/hash"
7
+
8
+ require "panda_doc/api_client"
9
+ require "panda_doc/configuration"
10
+ require "panda_doc/failure_result"
11
+ require "panda_doc/success_result"
12
+ require "panda_doc/document"
13
+ require "panda_doc/response_factory"
14
+ require "panda_doc/objects/recipient"
15
+ require "panda_doc/objects/document"
16
+ require "panda_doc/objects/error"
17
+ require "panda_doc/objects/session"
18
+ require "panda_doc/responses/document"
19
+ require "panda_doc/responses/error"
20
+ require "panda_doc/responses/session"
21
+
22
+ require "panda_doc/version"
23
+
24
+ module PandaDoc
25
+ # Your code goes here...
26
+ end
data/panda_doc.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'panda_doc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "panda_doc"
8
+ spec.version = PandaDoc::VERSION
9
+ spec.platform = Gem::Platform::RUBY
10
+ spec.authors = ["Igor Pstyga"]
11
+ spec.email = ["igor.pstyga@gmail.com"]
12
+
13
+ spec.summary = %q{Ruby wrapper for PandaDoc.com API}
14
+ spec.description = spec.summary
15
+ spec.homepage = "https://github.com/opti/panda_doc"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "bin"
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.required_ruby_version = "~> 2.2"
24
+ spec.add_dependency "faraday", "~> 0.9.2"
25
+ spec.add_dependency "faraday_middleware", "~> 0.10.0"
26
+ spec.add_dependency "virtus", "~> 1.0", ">= 1.0.5"
27
+ spec.add_dependency "representable", ">= 3.0.0"
28
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: panda_doc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Igor Pstyga
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-03 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.9.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.10.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.10.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: virtus
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 1.0.5
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '1.0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.0.5
61
+ - !ruby/object:Gem::Dependency
62
+ name: representable
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 3.0.0
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 3.0.0
75
+ description: Ruby wrapper for PandaDoc.com API
76
+ email:
77
+ - igor.pstyga@gmail.com
78
+ executables:
79
+ - console
80
+ - setup
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - ".gitignore"
85
+ - ".rspec"
86
+ - ".travis.yml"
87
+ - CHANGELOG.md
88
+ - Gemfile
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
92
+ - bin/console
93
+ - bin/setup
94
+ - lib/panda_doc.rb
95
+ - lib/panda_doc/api_client.rb
96
+ - lib/panda_doc/configuration.rb
97
+ - lib/panda_doc/document.rb
98
+ - lib/panda_doc/failure_result.rb
99
+ - lib/panda_doc/objects/document.rb
100
+ - lib/panda_doc/objects/error.rb
101
+ - lib/panda_doc/objects/recipient.rb
102
+ - lib/panda_doc/objects/session.rb
103
+ - lib/panda_doc/response_factory.rb
104
+ - lib/panda_doc/responses/document.rb
105
+ - lib/panda_doc/responses/error.rb
106
+ - lib/panda_doc/responses/session.rb
107
+ - lib/panda_doc/success_result.rb
108
+ - lib/panda_doc/version.rb
109
+ - panda_doc.gemspec
110
+ homepage: https://github.com/opti/panda_doc
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '2.2'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.5.1
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Ruby wrapper for PandaDoc.com API
134
+ test_files: []