signnow-ruby 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 +11 -0
- data/.rspec +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +9 -0
- data/LICENSE +23 -0
- data/README.md +150 -0
- data/Rakefile +8 -0
- data/lib/signnow.rb +119 -0
- data/lib/signnow/authentications/base.rb +57 -0
- data/lib/signnow/authentications/oauth.rb +68 -0
- data/lib/signnow/base.rb +45 -0
- data/lib/signnow/client.rb +29 -0
- data/lib/signnow/document.rb +28 -0
- data/lib/signnow/operations/all.rb +51 -0
- data/lib/signnow/operations/create.rb +35 -0
- data/lib/signnow/operations/delete.rb +42 -0
- data/lib/signnow/operations/download_link.rb +41 -0
- data/lib/signnow/operations/find.rb +43 -0
- data/lib/signnow/operations/show.rb +42 -0
- data/lib/signnow/operations/update.rb +52 -0
- data/lib/signnow/request/base.rb +34 -0
- data/lib/signnow/request/connection.rb +74 -0
- data/lib/signnow/request/helpers.rb +36 -0
- data/lib/signnow/request/info.rb +50 -0
- data/lib/signnow/request/validator.rb +52 -0
- data/lib/signnow/user.rb +31 -0
- data/lib/signnow/version.rb +3 -0
- data/signnow.gemspec +22 -0
- data/spec/signnow/base_spec.rb +12 -0
- data/spec/signnow/client_spec.rb +53 -0
- data/spec/signnow/document_spec.rb +188 -0
- data/spec/signnow/request/base_spec.rb +27 -0
- data/spec/signnow/request/connection_spec.rb +58 -0
- data/spec/signnow/request/info_spec.rb +27 -0
- data/spec/signnow/request/validator_spec.rb +13 -0
- data/spec/signnow/user_spec.rb +86 -0
- data/spec/signnow_spec.rb +45 -0
- data/spec/spec_helper.rb +13 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b06055e99370cf62de7dce20b653a01a098bb39b
|
4
|
+
data.tar.gz: 9ed58ce770ce2437ecb0f9410914716b7aec9ea9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7880020a0c9dd24b52d5d22d3a03fed698cf36ddb3c7b7e373b8d9b23313ae42fee3aa45cfbbe37d1b352d7a683b2ea1a4775d54b6dc60b81d363cc18b0fe5d2
|
7
|
+
data.tar.gz: be414eb7985a9c1151ef47000e3ea434839ba34fe59c9e8e6af8b812fdb73fe4b998fd7d3312086cd21da4609c657340901548bdd67595adbb3eefd19f8ed907
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2012 Andres Bravo
|
4
|
+
Copyright (c) 2012 dkd Internet Service GmbH
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
20
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
21
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
22
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
23
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
SignNow [](https://travis-ci.org/andresbravog/signnow-ruby) [](https://codeclimate.com/github/andresbravog/signnow-ruby) [](https://coveralls.io/r/andresbravog/signnow-ruby)
|
2
|
+
======
|
3
|
+
|
4
|
+
This is a Ruby wrapper for SignNow's API.
|
5
|
+
|
6
|
+
Documentation
|
7
|
+
=====
|
8
|
+
|
9
|
+
We use RubyDoc for documentation.
|
10
|
+
|
11
|
+
Usage
|
12
|
+
======
|
13
|
+
|
14
|
+
First, you've to install the gem
|
15
|
+
|
16
|
+
gem install signnow
|
17
|
+
|
18
|
+
and require it
|
19
|
+
|
20
|
+
require "signnow"
|
21
|
+
|
22
|
+
and set up your api_key
|
23
|
+
|
24
|
+
Signnow.configure do |config|
|
25
|
+
config[:app_id] = "_your_application_app_id_",
|
26
|
+
config[:app_secret] = "_your_application_app_secret_"
|
27
|
+
end
|
28
|
+
|
29
|
+
set the extra ```:use_test_env?``` config option to true if you want to use the [signnow test environment](https://eval.signnow.com)
|
30
|
+
|
31
|
+
Signnow.configure do |config|
|
32
|
+
config[:use_test_env?] = true
|
33
|
+
end
|
34
|
+
|
35
|
+
Oauth
|
36
|
+
=====
|
37
|
+
|
38
|
+
*[SignNow oauth2 API documentation](https://signnow.atlassian.net/wiki/display/SAPI/REST+Endpoints#RESTEndpoints-POST/oauth2)*
|
39
|
+
|
40
|
+
Redirecting the user to the authorize url, You need to provide a redirect url where you will get a code param.
|
41
|
+
|
42
|
+
# Redirect the user to the authorize url
|
43
|
+
redirect_to Signnow::Authentications::Oauth.authorize_url(redirect_uri: your_redirect_url)
|
44
|
+
|
45
|
+
Process the code param in order to get user oauth credentials.
|
46
|
+
|
47
|
+
oauth_credentials = Signnow::Authentications::Oauth.authenticate(code: code)
|
48
|
+
|
49
|
+
=>
|
50
|
+
{
|
51
|
+
access_token: '_user_access_token_',
|
52
|
+
refresh_token: '_user_refresh_token',
|
53
|
+
token_type: 'bearer',
|
54
|
+
scope: '*',
|
55
|
+
last_login: 2013929273,
|
56
|
+
expires_in: 2013929273
|
57
|
+
}
|
58
|
+
|
59
|
+
Store the access token credentials in order to use the Signnow API
|
60
|
+
|
61
|
+
Signnow::User.show(access_token: oauth_credentials.access_token)
|
62
|
+
|
63
|
+
|
64
|
+
Users
|
65
|
+
=====
|
66
|
+
|
67
|
+
*[SignNow users API documentation](https://signnow.atlassian.net/wiki/display/SAPI/REST+Endpoints#RESTEndpoints-/user)*
|
68
|
+
|
69
|
+
Creating a user:
|
70
|
+
|
71
|
+
user = Singnow::User.create(
|
72
|
+
email: 'yournewuser@email.com', # required
|
73
|
+
password: 'new_password', # required
|
74
|
+
first_name: 'john', # optional
|
75
|
+
last_name: 'doe', # optional
|
76
|
+
)
|
77
|
+
|
78
|
+
Store the acess_token
|
79
|
+
|
80
|
+
token = user.access_token
|
81
|
+
|
82
|
+
Generate a client with the access token
|
83
|
+
|
84
|
+
client = Signnow::Client.new(token)
|
85
|
+
|
86
|
+
Showing a user:
|
87
|
+
|
88
|
+
client.perform! |token|
|
89
|
+
Singnow::User.show(access_token: token)
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
Documents
|
94
|
+
=====
|
95
|
+
|
96
|
+
*[SignNow documents API documentation](https://signnow.atlassian.net/wiki/display/SAPI/REST+Endpoints#RESTEndpoints-/document)*
|
97
|
+
|
98
|
+
List user documents:
|
99
|
+
|
100
|
+
client.perform! |token|
|
101
|
+
Singnow::Document.all(access_token: token)
|
102
|
+
end
|
103
|
+
|
104
|
+
Show a document:
|
105
|
+
|
106
|
+
client.perform! |token|
|
107
|
+
Singnow::Document.show(id: 'document_id', access_token: token)
|
108
|
+
end
|
109
|
+
|
110
|
+
Get a one time download link for a document:
|
111
|
+
|
112
|
+
link =
|
113
|
+
client.perform! |token|
|
114
|
+
Singnow::Document.download_link(id: 'document_id', access_token: token)
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
Documentation
|
119
|
+
=====
|
120
|
+
|
121
|
+
*[SignNow developers page](https://developers.signnow.com)*
|
122
|
+
|
123
|
+
*[SignNow API documentation](https://signnow.atlassian.net/wiki/display/SAPI/REST+Endpoints)*
|
124
|
+
|
125
|
+
|
126
|
+
Requirements
|
127
|
+
=====
|
128
|
+
|
129
|
+
This gem requires at least Ruby 1.9 and faces version 1 of SignNow's API.
|
130
|
+
|
131
|
+
Bugs
|
132
|
+
======
|
133
|
+
|
134
|
+
Please report bugs at http://github.com/andresbravog/signnow-ruby/issues.
|
135
|
+
|
136
|
+
Note on Patches/Pull Requests
|
137
|
+
======
|
138
|
+
|
139
|
+
* Fork the project from http://github.com/andresbravog/signnow-ruby.
|
140
|
+
* Make your feature addition or bug fix.
|
141
|
+
* Add tests for it. This is important so I don't break it in a
|
142
|
+
future version unintentionally.
|
143
|
+
* Commit, do not mess with rakefile, version, or history.
|
144
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
145
|
+
* Send me a pull request. Bonus points for topic branches.
|
146
|
+
|
147
|
+
Copyright
|
148
|
+
======
|
149
|
+
|
150
|
+
Copyright (c) 2012-2013 andresbravog Internet Service GmbH, Andres Bravo. See LICENSE for details.
|
data/Rakefile
ADDED
data/lib/signnow.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "net/https"
|
3
|
+
require "json"
|
4
|
+
require "signnow/version"
|
5
|
+
require 'base64'
|
6
|
+
|
7
|
+
module Signnow
|
8
|
+
DOMAIN_BASE = 'api'
|
9
|
+
TEST_DOMAIN_BASE = 'capi-eval'
|
10
|
+
API_BASE = 'signnow.com'
|
11
|
+
API_BASE_PATH = nil
|
12
|
+
TEST_API_BASE_PATH = 'api'
|
13
|
+
API_VERSION = 'v1'
|
14
|
+
ROOT_PATH = File.dirname(__FILE__)
|
15
|
+
|
16
|
+
@@configuration = {}
|
17
|
+
|
18
|
+
autoload :Base, "signnow/base"
|
19
|
+
autoload :User, "signnow/user"
|
20
|
+
autoload :Document, "signnow/document"
|
21
|
+
autoload :Client, "signnow/client"
|
22
|
+
|
23
|
+
module Authentications
|
24
|
+
autoload :Base, "signnow/authentications/base"
|
25
|
+
autoload :Oauth, "signnow/authentications/oauth"
|
26
|
+
end
|
27
|
+
|
28
|
+
module Operations
|
29
|
+
autoload :All, "signnow/operations/all"
|
30
|
+
autoload :Create, "signnow/operations/create"
|
31
|
+
autoload :Delete, "signnow/operations/delete"
|
32
|
+
autoload :Find, "signnow/operations/find"
|
33
|
+
autoload :Show, "signnow/operations/show"
|
34
|
+
autoload :DownloadLink, "signnow/operations/download_link"
|
35
|
+
autoload :Update, "signnow/operations/update"
|
36
|
+
end
|
37
|
+
|
38
|
+
module Request
|
39
|
+
autoload :Base, "signnow/request/base"
|
40
|
+
autoload :Connection, "signnow/request/connection"
|
41
|
+
autoload :Helpers, "signnow/request/helpers"
|
42
|
+
autoload :Info, "signnow/request/info"
|
43
|
+
autoload :Validator, "signnow/request/validator"
|
44
|
+
end
|
45
|
+
|
46
|
+
class SignnowError < StandardError; end
|
47
|
+
class AuthenticationError < SignnowError; end
|
48
|
+
class APIError < SignnowError; end
|
49
|
+
class NotFound < SignnowError; end
|
50
|
+
class InvalidToken < APIError; end
|
51
|
+
class EmptyDocuments < APIError; end
|
52
|
+
|
53
|
+
# Returns the set api key
|
54
|
+
#
|
55
|
+
# @return [String] The api key
|
56
|
+
def self.encoded_app_credentials
|
57
|
+
return unless configuration[:app_id] && configuration[:app_secret]
|
58
|
+
configuration[:encoded_app_credentials] ||=
|
59
|
+
Base64.strict_encode64("#{configuration[:app_id]}:#{configuration[:app_secret]}")
|
60
|
+
end
|
61
|
+
|
62
|
+
# Use thisfunciotn with a block to add app credentials configuration
|
63
|
+
# Example:
|
64
|
+
#
|
65
|
+
# Signnow.configure do |config|
|
66
|
+
# config[:app_id] = 'your_app_id'
|
67
|
+
# config[:app_secret] = 'your_app_secret'
|
68
|
+
# end
|
69
|
+
def self.configure
|
70
|
+
return unless block_given?
|
71
|
+
yield(configuration)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Returns configuration hash
|
75
|
+
# @return [Hash]
|
76
|
+
def self.configuration
|
77
|
+
@@configuration
|
78
|
+
end
|
79
|
+
|
80
|
+
# Makes a request against the Signnow API
|
81
|
+
#
|
82
|
+
# @param [Symbol] http_method The http method to use, must be one of :get, :post, :put and :delete
|
83
|
+
# @param [String] domain The API domain to use
|
84
|
+
# @param [String] api_url The API url to use
|
85
|
+
# @param [Hash] data The data to send, e.g. used when creating new objects.
|
86
|
+
# @return [Array] The parsed JSON response.
|
87
|
+
def self.request(http_method, domain, api_url, data, options={})
|
88
|
+
info = Request::Info.new(http_method, domain, api_url, data, options)
|
89
|
+
Request::Base.new(info).perform
|
90
|
+
end
|
91
|
+
|
92
|
+
# Returns the domain base of the api depending on the env
|
93
|
+
#
|
94
|
+
def self.domain
|
95
|
+
if configuration[:use_test_env?]
|
96
|
+
TEST_DOMAIN_BASE
|
97
|
+
else
|
98
|
+
DOMAIN_BASE
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Returns the api base path depending on the env
|
103
|
+
#
|
104
|
+
def self.base_path
|
105
|
+
if configuration[:use_test_env?]
|
106
|
+
TEST_API_BASE_PATH
|
107
|
+
else
|
108
|
+
API_BASE_PATH
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Returns the api uri
|
113
|
+
#
|
114
|
+
def self.uri
|
115
|
+
uri = "https://#{domain}"
|
116
|
+
base_path && uri += "/#{base_path}"
|
117
|
+
uri
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Signnow
|
2
|
+
module Authentications
|
3
|
+
class Base
|
4
|
+
class << self
|
5
|
+
# Retrieves an oauth token from the Signnow API
|
6
|
+
#
|
7
|
+
# @param [Hash] attributes Attributes to pass to the API
|
8
|
+
# @return [Array] The available objects
|
9
|
+
def authenticate(attributes = {})
|
10
|
+
response = Signnow.request(
|
11
|
+
:post,
|
12
|
+
nil,
|
13
|
+
self.api_authenticate_url,
|
14
|
+
attributes_for_authentication(attributes),
|
15
|
+
options_for_authentication.merge(
|
16
|
+
use_form_data: true
|
17
|
+
)
|
18
|
+
)
|
19
|
+
self.new(response)
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
# URl for the authenticate endpoint
|
25
|
+
# overwrite this in the model if the api is not well named
|
26
|
+
#
|
27
|
+
def api_authenticate_url
|
28
|
+
"#{self.name.split("::").last.downcase}"
|
29
|
+
end
|
30
|
+
|
31
|
+
# Options for the authentication mehtod
|
32
|
+
#
|
33
|
+
# @return [Hash]
|
34
|
+
def options_for_authentication
|
35
|
+
{ auth_type: :basic }
|
36
|
+
end
|
37
|
+
|
38
|
+
# Attributes for the authentication mehtod
|
39
|
+
# overwrite this in the class to add attributes
|
40
|
+
#
|
41
|
+
# @param [Hash] attributes to merge with
|
42
|
+
# @return [Hash]
|
43
|
+
def attributes_for_authentication(attributes={})
|
44
|
+
{}.merge(attributes)
|
45
|
+
end
|
46
|
+
|
47
|
+
def domain
|
48
|
+
if Signnow.configuration[:use_test_env?]
|
49
|
+
'eval'
|
50
|
+
else
|
51
|
+
'www'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Signnow
|
2
|
+
module Authentications
|
3
|
+
class Oauth < Base
|
4
|
+
include Signnow::Operations::Create
|
5
|
+
|
6
|
+
attr_accessor :created, :access_token, :token_type, :expires_in,
|
7
|
+
:refresh_token, :scope, :last_login
|
8
|
+
|
9
|
+
class << self
|
10
|
+
# Returns the redirect url to authorize
|
11
|
+
#
|
12
|
+
# @param [Hash] options
|
13
|
+
# @option options [String] redirect_url () redirect url to receive the code param
|
14
|
+
def authorize_url(options = {})
|
15
|
+
protocol = "https"
|
16
|
+
base_url = "#{protocol}://#{domain}.#{API_BASE}"
|
17
|
+
path = "/proxy/index.php/authorize"
|
18
|
+
params = {
|
19
|
+
client_id: Signnow.configuration[:app_id],
|
20
|
+
redirect_uri: options[:redirect_uri],
|
21
|
+
response_type: 'code'
|
22
|
+
}
|
23
|
+
|
24
|
+
"#{base_url}#{path}?#{URI.encode_www_form(params)}"
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def api_authenticate_url
|
30
|
+
"oauth2/token"
|
31
|
+
end
|
32
|
+
|
33
|
+
# Attributes for the authentication mehtod
|
34
|
+
# overwrite this in the class to add attributes
|
35
|
+
#
|
36
|
+
# @param [Hash] attributes to merge with
|
37
|
+
# @return [Hash]
|
38
|
+
def attributes_for_authentication(attributes={})
|
39
|
+
{ grant_type: 'authorization_code' }.merge(attributes)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Initializes the object using the given attributes
|
44
|
+
#
|
45
|
+
# @param [Hash] attributes The attributes to use for initialization
|
46
|
+
def initialize(attributes = {})
|
47
|
+
set_attributes(attributes)
|
48
|
+
parse_timestamps
|
49
|
+
end
|
50
|
+
|
51
|
+
# Sets the attributes
|
52
|
+
#
|
53
|
+
# @param [Hash] attributes The attributes to initialize
|
54
|
+
def set_attributes(attributes)
|
55
|
+
attributes.each_pair do |key, value|
|
56
|
+
instance_variable_set("@#{key}", value)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Parses UNIX timestamps and creates Time objects.
|
61
|
+
def parse_timestamps
|
62
|
+
@created = Time.at(created.to_i) if created
|
63
|
+
@expires_in = Time.at(expires_in.to_i) if expires_in
|
64
|
+
@last_login = Time.at(last_login.to_i) if last_login
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|