signatureio 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in signatureio.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Scott Motte
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
+ # Signatureio Ruby Bindings
2
+
3
+ This gem is a wrapper for Signature.io's API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'signatureio'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install signatureio
18
+
19
+ Then in your application initialize the gem:
20
+
21
+ $ Signatureio.secret_api_key = "your_secret_api_key"
22
+ $ Signatureio.public_api_key = "your_public_api_key"
23
+
24
+ ## Usage
25
+
26
+ ### Create Document
27
+
28
+ $ Signatureio::Document.create(:url => "https://www.signature.io/pdfs/sign-below.pdf")
29
+
30
+ Replace the url with a url of the PDF or Microsoft Word file you choose.
31
+
32
+ ### Retrieve Document
33
+
34
+ $ Signatureio::Document.retrieve("id_of_document")
35
+
36
+ ### List Documents
37
+
38
+ $ Signatureio::Document.all
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. export SIGNATURE_SECRET_API_KEY="your_secret_api_key"
45
+ 4. export SIGNATURE_PUBLIC_API_KEY="your_public_api_key"
46
+ 5. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 6. Push to the branch (`git push origin my-new-feature`)
48
+ 7. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ module Signatureio
2
+ class Document
3
+ #
4
+ # Api calls
5
+ #
6
+ def self.create(attrs={})
7
+ response = Signatureio.request.post "documents.json", attrs
8
+ response.body.to_ostruct_recursive
9
+ end
10
+
11
+ def self.retrieve(id=nil)
12
+ response = Signatureio.request.get "documents/#{id}.json"
13
+ response.body.to_ostruct_recursive
14
+ end
15
+
16
+ def self.all
17
+ response = Signatureio.request.get "documents.json"
18
+ response.body.to_ostruct_recursive
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ # https://gist.github.com/2710460
2
+ class Hash
3
+ # options:
4
+ # :exclude => [keys] - keys need to be symbols
5
+ def to_ostruct_recursive(options = {})
6
+ convert_to_ostruct_recursive(self, options)
7
+ end
8
+
9
+ def with_sym_keys
10
+ self.inject({}) { |memo, (k,v)| memo[k.to_sym] = v; memo }
11
+ end
12
+
13
+ private
14
+
15
+ def convert_to_ostruct_recursive(obj, options)
16
+ result = obj
17
+ if result.is_a? Hash
18
+ result = result.dup.with_sym_keys
19
+ result.each do |key, val|
20
+ result[key] = convert_to_ostruct_recursive(val, options) unless options[:exclude].try(:include?, key)
21
+ end
22
+ result = OpenStruct.new result
23
+ elsif result.is_a? Array
24
+ result = result.map { |r| convert_to_ostruct_recursive(r, options) }
25
+ end
26
+ return result
27
+ end
28
+ end
@@ -0,0 +1,57 @@
1
+ class Object
2
+ # Invokes the method identified by the symbol +method+, passing it any arguments
3
+ # and/or the block specified, just like the regular Ruby <tt>Object#send</tt> does.
4
+ #
5
+ # *Unlike* that method however, a +NoMethodError+ exception will *not* be raised
6
+ # and +nil+ will be returned instead, if the receiving object is a +nil+ object or NilClass.
7
+ #
8
+ # If try is called without a method to call, it will yield any given block with the object.
9
+ #
10
+ # Please also note that +try+ is defined on +Object+, therefore it won't work with
11
+ # subclasses of +BasicObject+. For example, using try with +SimpleDelegator+ will
12
+ # delegate +try+ to target instead of calling it on delegator itself.
13
+ #
14
+ # ==== Examples
15
+ #
16
+ # Without +try+
17
+ # @person && @person.name
18
+ # or
19
+ # @person ? @person.name : nil
20
+ #
21
+ # With +try+
22
+ # @person.try(:name)
23
+ #
24
+ # +try+ also accepts arguments and/or a block, for the method it is trying
25
+ # Person.try(:find, 1)
26
+ # @people.try(:collect) {|p| p.name}
27
+ #
28
+ # Without a method argument try will yield to the block unless the receiver is nil.
29
+ # @person.try { |p| "#{p.first_name} #{p.last_name}" }
30
+ #--
31
+ # +try+ behaves like +Object#send+, unless called on +NilClass+.
32
+ def try(*a, &b)
33
+ if a.empty? && block_given?
34
+ yield self
35
+ else
36
+ __send__(*a, &b)
37
+ end
38
+ end
39
+ end
40
+
41
+ class NilClass
42
+ # Calling +try+ on +nil+ always returns +nil+.
43
+ # It becomes specially helpful when navigating through associations that may return +nil+.
44
+ #
45
+ # === Examples
46
+ #
47
+ # nil.try(:name) # => nil
48
+ #
49
+ # Without +try+
50
+ # @person && !@person.children.blank? && @person.children.first.name
51
+ #
52
+ # With +try+
53
+ # @person.try(:children).try(:first).try(:name)
54
+ def try(*args)
55
+ nil
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module Signatureio
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,76 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "signatureio/extensions/try"
4
+ require "signatureio/extensions/recursive_openstruct"
5
+ require "signatureio/version"
6
+ require "signatureio/document"
7
+
8
+ module Signatureio
9
+ extend self
10
+
11
+ def request=(request)
12
+ @request = request
13
+ end
14
+
15
+ def request
16
+ @request
17
+ end
18
+
19
+ def secret_api_key=(secret_api_key)
20
+ @secret_api_key = secret_api_key
21
+ setup_request!
22
+
23
+ @secret_api_key
24
+ end
25
+
26
+ def secret_api_key
27
+ return @secret_api_key if @secret_api_key
28
+ "missing_secret_api_key"
29
+ end
30
+
31
+ def public_api_key=(public_api_key)
32
+ @public_api_key = public_api_key
33
+ setup_request!
34
+
35
+ @public_api_key
36
+ end
37
+
38
+ def public_api_key
39
+ return @public_api_key if @public_api_key
40
+ "missing_public_api_key"
41
+ end
42
+
43
+ def api_version=(api_version)
44
+ @api_version = api_version
45
+ setup_request!
46
+
47
+ @api_version
48
+ end
49
+
50
+ def api_version
51
+ return @api_version if @api_version
52
+ 0
53
+ end
54
+
55
+ def api_endpoint
56
+ ["https://www.signature.io/api/v", api_version].join
57
+ end
58
+
59
+ private
60
+
61
+ def setup_request!
62
+ options = {
63
+ headers: {'Accept' => "application/json"},
64
+ ssl: {:verify => false},
65
+ url: Signatureio.api_endpoint
66
+ }
67
+
68
+ Signatureio.request = ::Faraday::Connection.new(options) do |builder|
69
+ builder.use ::Faraday::Request::UrlEncoded
70
+ builder.use ::FaradayMiddleware::ParseJson
71
+ builder.adapter ::Faraday.default_adapter
72
+ end
73
+
74
+ Signatureio.request.basic_auth(Signatureio.secret_api_key, '')
75
+ end
76
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'signatureio/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "signatureio"
8
+ gem.version = Signatureio::VERSION
9
+ gem.authors = ["scottmotte"]
10
+ gem.email = ["scott@scottmotte.com"]
11
+ gem.description = %q{This gem is a wrapper for Signature.io's API.}
12
+ gem.summary = %q{Use this wrapper gem to query Signature.io's API, create signable documents, view signed documents, and more.}
13
+ gem.homepage = "https://www.signature.io"
14
+
15
+ gem.add_development_dependency "faraday"
16
+ gem.add_development_dependency "faraday_middleware"
17
+ gem.add_development_dependency "pry"
18
+ gem.add_development_dependency "rake"
19
+ gem.add_development_dependency "rspec"
20
+
21
+ gem.files = `git ls-files`.split($/)
22
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
23
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
24
+ gem.require_paths = ["lib"]
25
+ end
@@ -0,0 +1,115 @@
1
+ require 'spec_helper'
2
+
3
+ describe Signatureio::Document do
4
+ let(:subject) { Signatureio::Document }
5
+ let(:url) { "https://www.signature.io/pdfs/sign-below.pdf" }
6
+
7
+ context "incorrect secret api key" do
8
+ before do
9
+ Signatureio.secret_api_key = "incorrect_secret_api_key"
10
+ end
11
+
12
+ describe "attempt .create" do
13
+ before do
14
+ @response = subject.create({:url => url})
15
+ end
16
+
17
+ it do
18
+ @response.success.should be_false
19
+ @response.error.message.should_not be_empty
20
+ end
21
+ end
22
+
23
+ describe "attempt .retrieve" do
24
+ before do
25
+ @response = subject.retrieve("1234")
26
+ end
27
+
28
+ it do
29
+ @response.success.should be_false
30
+ @response.error.message.should_not be_empty
31
+ end
32
+ end
33
+ end
34
+
35
+ context "correct secret api key" do
36
+ before do
37
+ set_secret_and_public_api_keys!
38
+ end
39
+
40
+ describe ".create" do
41
+ before do
42
+ @response = subject.create(attrs)
43
+ end
44
+
45
+ context "default" do
46
+ let(:attrs) { {:url => url} }
47
+
48
+ it do
49
+ @response.success.should be_true
50
+ @response.document.id.should_not be_empty
51
+ end
52
+ end
53
+
54
+ context "blank url" do
55
+ let(:attrs) { {:url => nil} }
56
+
57
+ it do
58
+ @response.success.should be_false
59
+ @response.error.message.should_not be_empty
60
+ end
61
+ end
62
+
63
+ context "invalid url" do
64
+ let(:attrs) { {:url => "noexisturl"} }
65
+
66
+ it do
67
+ @response.success.should be_false
68
+ @response.error.message.should_not be_empty
69
+ end
70
+ end
71
+ end
72
+
73
+ describe ".retrieve" do
74
+ before do
75
+ response = subject.create({:url => url})
76
+ @id = response.document.id
77
+ end
78
+
79
+ context "default" do
80
+ before do
81
+ @response = subject.retrieve(@id)
82
+ end
83
+
84
+ it do
85
+ @response.success.should be_true
86
+ @response.document.id.should eq @id
87
+ end
88
+ end
89
+
90
+ context "incorrect id" do
91
+ before do
92
+ @response = subject.retrieve("1234")
93
+ end
94
+
95
+ it do
96
+ @response.success.should be_false
97
+ @response.error.message.should_not be_empty
98
+ end
99
+ end
100
+ end
101
+
102
+ describe ".all" do
103
+ before do
104
+ @response = subject.all
105
+ end
106
+
107
+ context "default" do
108
+ it do
109
+ @response.success.should be_true
110
+ @response.documents.count.should >= 1
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Signatureio do
4
+ it { Signatureio::VERSION.should eq "0.0.1" }
5
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Signatureio do
4
+ subject { Signatureio }
5
+
6
+ describe "defaults" do
7
+ before do
8
+ subject.secret_api_key = nil
9
+ subject.public_api_key = nil
10
+ subject.api_version = nil
11
+ end
12
+
13
+ it { subject.api_endpoint.should eq "https://www.signature.io/api/v0" }
14
+ it { subject.api_version.should eq 0 }
15
+ it { subject.secret_api_key.should eq "missing_secret_api_key" }
16
+ it { subject.public_api_key.should eq "missing_public_api_key" }
17
+ end
18
+
19
+ describe "setting values" do
20
+ let(:secret_api_key) { "sk_1234" }
21
+ let(:public_api_key) { "pk_5678" }
22
+ let(:api_version) { 1 }
23
+
24
+ before do
25
+ subject.secret_api_key = secret_api_key
26
+ subject.public_api_key = public_api_key
27
+ subject.api_version = api_version
28
+ end
29
+
30
+ it { subject.api_version.should eq api_version }
31
+ it { subject.public_api_key.should eq public_api_key }
32
+ it { subject.secret_api_key.should eq secret_api_key }
33
+ it { subject.api_endpoint.should eq "https://www.signature.io/api/v1" }
34
+ end
35
+ end
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'pry'
4
+ require 'signatureio'
5
+
6
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
7
+
8
+ RSpec.configure do |config|
9
+ config.before(:suite) do
10
+ # FakeWeb.allow_net_connect = false
11
+ set_secret_and_public_api_keys!
12
+ end
13
+
14
+ # config.after(:suite) do
15
+ # FakeWeb.allow_net_connect = true
16
+ # end
17
+ end
18
+
19
+ def set_secret_and_public_api_keys!
20
+ # These keys come form rspec@signature.io person.
21
+ Signatureio.secret_api_key = ENV['SIGNATURE_SECRET_API_KEY']
22
+ Signatureio.public_api_key = ENV['SIGNATURE_PUBLIC_API_KEY']
23
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: signatureio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - scottmotte
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: faraday_middleware
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: pry
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: This gem is a wrapper for Signature.io's API.
95
+ email:
96
+ - scott@scottmotte.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - .rspec
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - lib/signatureio.rb
108
+ - lib/signatureio/document.rb
109
+ - lib/signatureio/extensions/recursive_openstruct.rb
110
+ - lib/signatureio/extensions/try.rb
111
+ - lib/signatureio/version.rb
112
+ - signatureio.gemspec
113
+ - spec/signatureio/document_spec.rb
114
+ - spec/signatureio/version_spec.rb
115
+ - spec/signatureio_spec.rb
116
+ - spec/spec_helper.rb
117
+ homepage: https://www.signature.io
118
+ licenses: []
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ segments:
130
+ - 0
131
+ hash: -3089883217917200588
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ segments:
139
+ - 0
140
+ hash: -3089883217917200588
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 1.8.24
144
+ signing_key:
145
+ specification_version: 3
146
+ summary: Use this wrapper gem to query Signature.io's API, create signable documents,
147
+ view signed documents, and more.
148
+ test_files:
149
+ - spec/signatureio/document_spec.rb
150
+ - spec/signatureio/version_spec.rb
151
+ - spec/signatureio_spec.rb
152
+ - spec/spec_helper.rb