viafirma-api 0.0.1 → 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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODUzMjQyZWYzOTkzMTBkZWQ4YTBlM2EzNTA3NTU5ZmMyZTE4YjE3ZA==
4
+ NGQzNmQzM2NhNjQwM2NlYmRjNjc1OWJjMWM5ZDI5ZjVjZDcwM2NhNA==
5
5
  data.tar.gz: !binary |-
6
- ZjRjYTUwZWY0YmQzNDQ4MDMzNjZjNTBmNWNkNTBmY2Y1MjA5YmNmYw==
6
+ NDBlNGIwNTFhZDA5NTBhMTUxMDBlZjliNTQ2NWM1MDUxMzE5MDRjYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTliZjMyYzkwZmJmYTYzNjhhZGY4N2ZkMTVlNWZlZWI1Yzg4NGFjODJmZGZm
10
- YjA3MzE4YTU3NzQyNDA1ZjgyMzA4YjU0NTk3NWM5ZWFhNDg5ODNiNmZjZGI1
11
- NzQ1NmVkZmNjNTM1OGZlMmU0NWMzM2ZjMmIxYWQ2MzAyYTI5MDA=
9
+ NTg5OTY1NThmMTM2ODhkM2Q0YTg5OWM0Y2Y1NGFjYTA0ZDc3NDQ3NDc5ZWUz
10
+ MTRiMWNhMDEwNzU2NzFhZmE4NTM1MmMxMmRlNWViMzA5ZWJlY2FjOTEyY2Zm
11
+ NmQ5ZmQ1NDJkMWY0MmY0YWIyZDZmOTYyNjNhZTgxYTQ1OThjZGY=
12
12
  data.tar.gz: !binary |-
13
- MmFiNDU1OTM0MjQ3MjAyZDBlNzk1ZTAxMWU1ZTY5MjE5OTI4NjQyMzE3ZGQ1
14
- ZDE1ZjRjZWZkYWRlN2QxYTA1ZjBhNzY5MWMxNWVjYTZkMGIxZjU3NzRiYTBl
15
- Y2NlZDEwOTgzYzMyNDQyMDlmZmFlNWY2YzI5NWIxNjE1YTc1NTc=
13
+ OTFjM2FkY2Y3YTg5ODc2MjFlY2I1MjZkMWU1ZDRiNDY2NjBkM2I3MmQyMjIz
14
+ ZGQ5NDBmYTBkNWYwMTdhNDA1OWM0MDJmNjE0ODgyZWI5MjYyZGExMDVhZTAx
15
+ NmNjMWFiODkyMzUwNmY2MDQxZWRiNDcwZWZkYzgxMWFkYmNjNzQ=
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- viafirma-api (0.0.1)
4
+ viafirma-api (0.0.2)
5
5
  activesupport (~> 3.2)
6
6
  savon (~> 2.11)
7
7
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Viafirma::Api
1
+ # ViafirmaApi
2
2
 
3
3
  API for connect and manage e-sign with viafirma platform
4
4
 
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
 
23
23
  Viafirma API facade initialization:
24
24
 
25
- facade = Viafirma::Api::Facade.new(server: <address>, user: <username>, apikey: <apikey>)
25
+ facade = ViafirmaApi::Facade.new(server: <address>, user: <username>, apikey: <apikey>)
26
26
 
27
27
  By default the gem will use the port 80 for the requests, but you can change it with aditional parameter in the initialization hash (`port: <portnumber>`)
28
28
 
@@ -0,0 +1,29 @@
1
+ require 'active_support/core_ext/hash/indifferent_access'
2
+ require 'active_support/core_ext/module/delegation'
3
+ require 'viafirma-api/client'
4
+
5
+ module ViafirmaApi
6
+ class Facade
7
+ delegate :call, to: :@client
8
+
9
+ def initialize(credentials)
10
+ @client = Client.new(credentials.with_indifferent_access)
11
+ end
12
+
13
+ def ping
14
+ @client.call(:ping, message: { param: 'pingResponse' })
15
+ end
16
+
17
+ def prepare_sign_request(person_id, document_name, document_content, return_url, metadata={})
18
+ params = {
19
+ person_id: person_id,
20
+ document_name: document_name,
21
+ document_content: Base64.encode64(document_content),
22
+ return_url: return_url,
23
+ metadatos: metadata
24
+ }
25
+ @client.call(:prepare_sign_request, message: params)
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,39 @@
1
+ require 'savon'
2
+
3
+ module ViafirmaApi
4
+ class Client
5
+
6
+ def initialize(credentials)
7
+ validate(credentials)
8
+ @client = Savon.client(wsdl: self.class.wsdl(credentials), basic_auth: [credentials[:user], credentials[:apikey]])
9
+ end
10
+
11
+ def self.wsdl(credentials)
12
+ "http://#{credentials[:server]}:#{credentials[:port] || 80}/inbox/serviceWS?wsdl"
13
+ end
14
+
15
+ def call(*args)
16
+ response = @client.call(*args)
17
+ parse_response(response.body)
18
+ end
19
+
20
+ def parse_response(response)
21
+ response_key = response.keys.detect{|k,v| k.to_s.end_with?('_response')}
22
+ data = response[response_key][:return]
23
+
24
+ if data[:error]
25
+ raise "#{data[:response_code]}: #{data[:message]}"
26
+ else
27
+ data
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def validate(credentials)
34
+ raise "Server endpoint missing!!" if credentials[:server].blank?
35
+ raise "User can't be blank!!" if credentials[:user].blank?
36
+ raise "Apikey can't be blank!!" if credentials[:apikey].blank?
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module ViafirmaApi
2
+ VERSION = "0.0.2"
3
+ end
@@ -1,10 +1,9 @@
1
1
  require 'spec_helper'
2
- require 'viafirma/api/client'
3
2
 
4
- describe Viafirma::Api::Client do
3
+ describe ViafirmaApi::Client do
5
4
 
6
5
  let(:config){ { server: 'whatever', port: 11, user: 'test', apikey: '123' } }
7
- let(:client){ Viafirma::Api::Client }
6
+ let(:client){ ViafirmaApi::Client }
8
7
 
9
8
  describe "#initialize" do
10
9
  it "should build a well formed client" do
@@ -1,14 +1,14 @@
1
1
  require 'spec_helper'
2
- require 'viafirma/facade'
2
+ require 'viafirma-api'
3
3
 
4
- describe Viafirma::Api::Facade do
4
+ describe ViafirmaApi::Facade do
5
5
 
6
- let(:facade){ Viafirma::Api::Facade }
6
+ let(:facade){ ViafirmaApi::Facade }
7
7
 
8
8
  describe "#prepare_sign_request" do
9
9
 
10
10
  let(:client){ double("Client") }
11
- before(:each){ allow(Viafirma::Api::Client).to receive(:new).and_return(client) }
11
+ before(:each){ allow(ViafirmaApi::Client).to receive(:new).and_return(client) }
12
12
 
13
13
  it "should encode document content before send the soap request" do
14
14
  allow(client).to receive(:call).with(:prepare_sign_request, message: hash_including(document_content: Base64.encode64('content')))
@@ -2,14 +2,12 @@
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
- require 'viafirma/api/version'
6
- require 'viafirma/api/client'
7
- require 'viafirma/facade'
8
-
5
+ require 'viafirma-api/version'
6
+ require 'viafirma-api/client'
9
7
 
10
8
  Gem::Specification.new do |spec|
11
9
  spec.name = "viafirma-api"
12
- spec.version = Viafirma::Api::VERSION
10
+ spec.version = ViafirmaApi::VERSION
13
11
  spec.authors = ["David García Lorigados"]
14
12
  spec.email = ["dglo1985@gmail.com"]
15
13
  spec.summary = %q{API for connect and manage e-sign with viafirma platform}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: viafirma-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David García Lorigados
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-03 00:00:00.000000000 Z
11
+ date: 2016-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,12 +108,12 @@ files:
108
108
  - LICENSE
109
109
  - README.md
110
110
  - Rakefile
111
- - lib/viafirma/api/client.rb
112
- - lib/viafirma/api/version.rb
113
- - lib/viafirma/facade.rb
111
+ - lib/viafirma-api.rb
112
+ - lib/viafirma-api/client.rb
113
+ - lib/viafirma-api/version.rb
114
114
  - spec/client_spec.rb
115
- - spec/facade_spec.rb
116
115
  - spec/spec_helper.rb
116
+ - spec/viafirma-api_spec.rb
117
117
  - viafirma-api.gemspec
118
118
  homepage: ''
119
119
  licenses:
@@ -141,5 +141,5 @@ specification_version: 4
141
141
  summary: API for connect and manage e-sign with viafirma platform
142
142
  test_files:
143
143
  - spec/client_spec.rb
144
- - spec/facade_spec.rb
145
144
  - spec/spec_helper.rb
145
+ - spec/viafirma-api_spec.rb
@@ -1,41 +0,0 @@
1
- require 'savon'
2
-
3
- module Viafirma
4
- module Api
5
- class Client
6
-
7
- def initialize(credentials)
8
- validate(credentials)
9
- @client = Savon.client(wsdl: self.class.wsdl(credentials), basic_auth: [credentials[:user], credentials[:apikey]])
10
- end
11
-
12
- def self.wsdl(credentials)
13
- "http://#{credentials[:server]}:#{credentials[:port] || 80}/inbox/serviceWS?wsdl"
14
- end
15
-
16
- def call(*args)
17
- response = @client.call(*args)
18
- parse_response(response.body)
19
- end
20
-
21
- def parse_response(response)
22
- response_key = response.keys.detect{|k,v| k.to_s.end_with?('_response')}
23
- data = response[response_key][:return]
24
-
25
- if data[:error]
26
- raise "#{data[:response_code]}: #{data[:message]}"
27
- else
28
- data
29
- end
30
- end
31
-
32
- private
33
-
34
- def validate(credentials)
35
- raise "Server endpoint missing!!" if credentials[:server].blank?
36
- raise "User can't be blank!!" if credentials[:user].blank?
37
- raise "Apikey can't be blank!!" if credentials[:apikey].blank?
38
- end
39
- end
40
- end
41
- end
@@ -1,5 +0,0 @@
1
- module Viafirma
2
- module Api
3
- VERSION = "0.0.1"
4
- end
5
- end
@@ -1,30 +0,0 @@
1
- require 'active_support/core_ext/hash/indifferent_access'
2
- require 'active_support/core_ext/module/delegation'
3
-
4
- module Viafirma
5
- module Api
6
- class Facade
7
- delegate :call, to: :@client
8
-
9
- def initialize(credentials)
10
- @client = Client.new(credentials.with_indifferent_access)
11
- end
12
-
13
- def ping
14
- @client.call(:ping, message: { param: 'pingResponse' })
15
- end
16
-
17
- def prepare_sign_request(person_id, document_name, document_content, return_url, metadata={})
18
- params = {
19
- person_id: person_id,
20
- document_name: document_name,
21
- document_content: Base64.encode64(document_content),
22
- return_url: return_url,
23
- metadatos: metadata
24
- }
25
- @client.call(:prepare_sign_request, message: params)
26
- end
27
-
28
- end
29
- end
30
- end