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
@@ -0,0 +1,27 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Signnow::Request::Base do
|
4
|
+
context "#perform" do
|
5
|
+
it "checks for an api key" do
|
6
|
+
Signnow.stub(:encoded_app_credentials).and_return(nil)
|
7
|
+
|
8
|
+
expect{
|
9
|
+
Signnow::Request::Base.new(nil).perform
|
10
|
+
}.to raise_error Signnow::AuthenticationError
|
11
|
+
end
|
12
|
+
|
13
|
+
it "performs an https request" do
|
14
|
+
Signnow.stub(:encoded_app_credentials).and_return("some key")
|
15
|
+
connection = double
|
16
|
+
validator = double
|
17
|
+
Signnow::Request::Connection.stub(:new).and_return(connection)
|
18
|
+
Signnow::Request::Validator.stub(:new).and_return(validator)
|
19
|
+
|
20
|
+
connection.should_receive(:setup_https)
|
21
|
+
connection.should_receive(:request)
|
22
|
+
validator.should_receive(:validated_data_for)
|
23
|
+
|
24
|
+
Signnow::Request::Base.new(nil).perform
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Signnow::Request::Connection do
|
4
|
+
before :each do
|
5
|
+
Signnow.configure do |config|
|
6
|
+
config[:app_id] = 'my_app_id'
|
7
|
+
config[:app_secret] = 'my_app_secret'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#setup_https" do
|
12
|
+
it "creates a https object" do
|
13
|
+
connection = Signnow::Request::Connection.new(nil)
|
14
|
+
|
15
|
+
connection.setup_https
|
16
|
+
|
17
|
+
connection.https.should_not be_nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#request" do
|
22
|
+
it "performs the actual request" do
|
23
|
+
connection = Signnow::Request::Connection.new(nil)
|
24
|
+
connection.setup_https
|
25
|
+
connection.stub(:https_request)
|
26
|
+
|
27
|
+
connection.https.should_receive(:request)
|
28
|
+
|
29
|
+
connection.request
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#https_request" do
|
34
|
+
it "correctly formats the form data" do
|
35
|
+
info = double(
|
36
|
+
http_method: :post,
|
37
|
+
url: "/some/path",
|
38
|
+
data: params,
|
39
|
+
subdomain: Signnow::DOMAIN_BASE,
|
40
|
+
authentication: {
|
41
|
+
type: :basic
|
42
|
+
},
|
43
|
+
use_form_data?: false
|
44
|
+
)
|
45
|
+
connection = Signnow::Request::Connection.new(info)
|
46
|
+
connection.setup_https
|
47
|
+
|
48
|
+
connection.__send__(:https_request).body.downcase.should eq(%{{\"email\":\"abc_abc.com\",\"event_types[0]\":\"user.created\",\"event_types[1]\":\"user.failed\",\"event_types[2]\":\"team.created\",\"event_types[3]\":\"documents.available\"}})
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def params
|
53
|
+
{
|
54
|
+
email: "abc_abc.com",
|
55
|
+
event_types: ["user.created","user.failed", "team.created", "documents.available"]
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Signnow::Request::Info do
|
4
|
+
describe "#url" do
|
5
|
+
it "constructs the url" do
|
6
|
+
info = Signnow::Request::Info.new(:get, nil, "random", {id: 1} )
|
7
|
+
|
8
|
+
info.url.should =~ /random/
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#path_with_params" do
|
13
|
+
it "does nothing when no params" do
|
14
|
+
info = Signnow::Request::Info.new(:get, nil, "random", nil)
|
15
|
+
path = "/path/to/someplace"
|
16
|
+
|
17
|
+
info.path_with_params(path, {}).should eq path
|
18
|
+
end
|
19
|
+
|
20
|
+
it "constructs the path with params" do
|
21
|
+
info = Signnow::Request::Info.new(:get, nil, "random", nil)
|
22
|
+
path = "/path/to/someplace"
|
23
|
+
|
24
|
+
info.path_with_params(path, {random: "stuff"}).should eq "#{path}?random=stuff"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Signnow::Request::Validator do
|
4
|
+
describe "#validated_data_for" do
|
5
|
+
it "validates the data" do
|
6
|
+
info = Signnow::Request::Info.new(:get, nil, "random", OpenStruct.new(id: 1))
|
7
|
+
validator = Signnow::Request::Validator.new info
|
8
|
+
response = OpenStruct.new(body: '{"response":"ok"}', code: 200)
|
9
|
+
|
10
|
+
validator.validated_data_for(response).should eq "response" => "ok"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Signnow::User do
|
4
|
+
let(:valid_attributes) do
|
5
|
+
JSON.parse %{
|
6
|
+
{
|
7
|
+
"id": "23f2f9dc10e0f12883f78e91296207640dede6d1",
|
8
|
+
"first_name": "Test",
|
9
|
+
"last_name": "User",
|
10
|
+
"active": "1",
|
11
|
+
"type": 1,
|
12
|
+
"pro": 0,
|
13
|
+
"created": "1358945328",
|
14
|
+
"emails": ["hola+test@andresbravo.com"],
|
15
|
+
"identity": {
|
16
|
+
"Identified": "No",
|
17
|
+
"Status": "First attempt",
|
18
|
+
"OKToRetry": true
|
19
|
+
},
|
20
|
+
"subscriptions": [],
|
21
|
+
"credits": 0,
|
22
|
+
"has_atticus_access": false,
|
23
|
+
"is_logged_in": true,
|
24
|
+
"teams": []
|
25
|
+
}
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:valid_create_response) do
|
30
|
+
JSON.parse %{
|
31
|
+
{\"id\":\"d0a68ff1d605e23148b411a9405de65b5fff12af\",\"verified\":0,\"email\":\"test@andresbravo.com\"}
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
let (:user) do
|
36
|
+
Signnow::User.new(valid_attributes)
|
37
|
+
end
|
38
|
+
|
39
|
+
let(:user_access_token) { '_user_access_token_' }
|
40
|
+
|
41
|
+
describe "#initialize" do
|
42
|
+
it 'initializes all attributes correctly' do
|
43
|
+
user.email.should eql('hola+test@andresbravo.com')
|
44
|
+
user.id.should eql('23f2f9dc10e0f12883f78e91296207640dede6d1')
|
45
|
+
user.first_name.should eql('Test')
|
46
|
+
user.last_name.should eql('User')
|
47
|
+
user.active.should eql(true)
|
48
|
+
user.type.should eql(1)
|
49
|
+
user.pro.should eql(false)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe ".show" do
|
54
|
+
let(:user_show) { Signnow::User.show(access_token: user_access_token) }
|
55
|
+
before :each do
|
56
|
+
allow(Signnow).to receive(:request).and_return(valid_attributes)
|
57
|
+
end
|
58
|
+
it "makes a new GET request using the correct API endpoint to receive a specific user" do
|
59
|
+
expect(Signnow).to receive(:request).with(:get, nil, "user", {}, { auth_type: :user_token, auth_token: user_access_token })
|
60
|
+
user_show
|
61
|
+
end
|
62
|
+
it 'returns a user with the correct id' do
|
63
|
+
expect(user_show.id).to eql('23f2f9dc10e0f12883f78e91296207640dede6d1')
|
64
|
+
end
|
65
|
+
it 'returns a user with the correct first_name' do
|
66
|
+
expect(user_show.first_name).to eql('Test')
|
67
|
+
end
|
68
|
+
it 'returns a user with the correct last_name' do
|
69
|
+
expect(user_show.last_name).to eql('User')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe ".create" do
|
74
|
+
let(:user_create) { Signnow::User.create(valid_attributes) }
|
75
|
+
before :each do
|
76
|
+
allow(Signnow).to receive(:request).and_return(valid_create_response)
|
77
|
+
end
|
78
|
+
it "makes a new POST request using the correct API endpoint" do
|
79
|
+
expect(Signnow).to receive(:request).with(:post, nil, "user", valid_attributes, { auth_type: :basic })
|
80
|
+
user_create
|
81
|
+
end
|
82
|
+
it 'returns a user with the correct id' do
|
83
|
+
expect(user_create.id).to eql('d0a68ff1d605e23148b411a9405de65b5fff12af')
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Signnow do
|
4
|
+
describe ".request" do
|
5
|
+
context "given no api key exists" do
|
6
|
+
it "raises an authentication error" do
|
7
|
+
Signnow.configure do |config|
|
8
|
+
config[:app_id] = nil
|
9
|
+
config[:app_secret] = nil
|
10
|
+
end
|
11
|
+
expect { Signnow.request(:get, nil, "clients", {}) }.to raise_error(Signnow::AuthenticationError)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with an invalid api key" do
|
16
|
+
before(:each) do
|
17
|
+
Signnow.configure do |config|
|
18
|
+
config[:app_id] = 'my_app_id'
|
19
|
+
config[:app_secret] = 'my_app_secret'
|
20
|
+
end
|
21
|
+
WebMock.stub_request(:any, /#{Signnow::API_BASE}/).to_return(:body => "{}")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "attempts to get a url with one param" do
|
25
|
+
Signnow.request(:get, nil, "user", { param_name: "param_value" })
|
26
|
+
WebMock.should have_requested(:get, "https://#{Signnow::DOMAIN_BASE}.#{Signnow::API_BASE}/user?param_name=param_value")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "attempts to get a url with more than one param" do
|
30
|
+
Signnow.request(:get, nil, "user", { client: "client_id", order: "created_at_desc" })
|
31
|
+
WebMock.should have_requested(:get, "https://#{Signnow::DOMAIN_BASE}.#{Signnow::API_BASE}/user?client=client_id&order=created_at_desc")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "doesn't add a question mark if no params" do
|
35
|
+
Signnow.request(:post, nil, "user", {})
|
36
|
+
WebMock.should have_requested(:post, "https://#{Signnow::DOMAIN_BASE}.#{Signnow::API_BASE}/user")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "uses correct authentication header if basic auth is setted" do
|
40
|
+
Signnow.request(:post, nil, "user", {id: 'new_id'}, { auth_type: :basic })
|
41
|
+
WebMock.should have_requested(:post, "https://#{Signnow.configuration[:app_id]}:#{Signnow.configuration[:app_secret]}@#{Signnow::DOMAIN_BASE}.#{Signnow::API_BASE}/user/new_id")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
3
|
+
require "signnow"
|
4
|
+
require "rspec"
|
5
|
+
require "rspec/autorun"
|
6
|
+
require "webmock/rspec"
|
7
|
+
require "pry"
|
8
|
+
require 'coveralls'
|
9
|
+
|
10
|
+
Coveralls.wear!
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: signnow-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andres Bravo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
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: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: API wrapper for Signnow.
|
56
|
+
email:
|
57
|
+
- hola@andresbravo.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- .travis.yml
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/signnow.rb
|
70
|
+
- lib/signnow/authentications/base.rb
|
71
|
+
- lib/signnow/authentications/oauth.rb
|
72
|
+
- lib/signnow/base.rb
|
73
|
+
- lib/signnow/client.rb
|
74
|
+
- lib/signnow/document.rb
|
75
|
+
- lib/signnow/operations/all.rb
|
76
|
+
- lib/signnow/operations/create.rb
|
77
|
+
- lib/signnow/operations/delete.rb
|
78
|
+
- lib/signnow/operations/download_link.rb
|
79
|
+
- lib/signnow/operations/find.rb
|
80
|
+
- lib/signnow/operations/show.rb
|
81
|
+
- lib/signnow/operations/update.rb
|
82
|
+
- lib/signnow/request/base.rb
|
83
|
+
- lib/signnow/request/connection.rb
|
84
|
+
- lib/signnow/request/helpers.rb
|
85
|
+
- lib/signnow/request/info.rb
|
86
|
+
- lib/signnow/request/validator.rb
|
87
|
+
- lib/signnow/user.rb
|
88
|
+
- lib/signnow/version.rb
|
89
|
+
- signnow.gemspec
|
90
|
+
- spec/signnow/base_spec.rb
|
91
|
+
- spec/signnow/client_spec.rb
|
92
|
+
- spec/signnow/document_spec.rb
|
93
|
+
- spec/signnow/request/base_spec.rb
|
94
|
+
- spec/signnow/request/connection_spec.rb
|
95
|
+
- spec/signnow/request/info_spec.rb
|
96
|
+
- spec/signnow/request/validator_spec.rb
|
97
|
+
- spec/signnow/user_spec.rb
|
98
|
+
- spec/signnow_spec.rb
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
homepage: https://github.com/andresbravog/signnow-ruby
|
101
|
+
licenses: []
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.0.6
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: API wrapper for Signnow.
|
123
|
+
test_files:
|
124
|
+
- spec/signnow/base_spec.rb
|
125
|
+
- spec/signnow/client_spec.rb
|
126
|
+
- spec/signnow/document_spec.rb
|
127
|
+
- spec/signnow/request/base_spec.rb
|
128
|
+
- spec/signnow/request/connection_spec.rb
|
129
|
+
- spec/signnow/request/info_spec.rb
|
130
|
+
- spec/signnow/request/validator_spec.rb
|
131
|
+
- spec/signnow/user_spec.rb
|
132
|
+
- spec/signnow_spec.rb
|
133
|
+
- spec/spec_helper.rb
|