credigy 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b8f333acad2906f210ab492a6d4a7957270c051
4
+ data.tar.gz: 230622d4ac9ea9da97469a2cfe9c828da9883152
5
+ SHA512:
6
+ metadata.gz: fd312378cab085db1910c92273827c3b491bce24a646f29176f74202287e3eee45e1ad1dbfedfc7ebaed68fae00bfd178b7d3aaeb93dcd58daefa166f7d5bd10
7
+ data.tar.gz: b6210e21cdb419820480a44c7a544077bb2cfbb59718ee459005e696f4afaf359ccb61d58c056e54d784e7d59c7fc88bc3b66476b8dbead051bc15a9965db221
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ .tags*
14
+ .DS_Store
15
+ Gemfile.lock
16
+ *.gem
17
+ .pryrc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,3 @@
1
+ ### 0.1.0 (09/10/2018)
2
+
3
+ * Cria a gem
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in credigy.gemspec
6
+ gemspec
7
+
8
+ group :test do
9
+ gem 'coveralls', require: false
10
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Glauco Custódio
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.
@@ -0,0 +1,108 @@
1
+ # Credigy
2
+
3
+ [![Build Status](https://travis-ci.org/glaucocustodio/credigy.svg?branch=master)](https://travis-ci.org/glaucocustodio/credigy)
4
+ [![Coverage Status](https://coveralls.io/repos/github/glaucocustodio/credigy/badge.svg)](https://coveralls.io/github/glaucocustodio/credigy)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/e87c5a00b82c525bb7de/maintainability)](https://codeclimate.com/github/glaucocustodio/credigy/maintainability)
6
+
7
+ Um cliente (não oficial) para o serviço SOAP da Credigy.
8
+
9
+ Consulte o [manual](https://github.com/glaucocustodio/credigy/blob/master/lib/manual/WebServiceCredigyV1.6.pdf) para mais informações.
10
+
11
+ ## Instalação
12
+
13
+ Adicione a linha no seu Gemfile
14
+
15
+ ```ruby
16
+ gem 'credigy'
17
+ ```
18
+
19
+ Execute:
20
+
21
+ $ bundle
22
+
23
+ Ou instale você mesmo:
24
+
25
+ $ gem install credigy
26
+
27
+ ## Chamadas implementadas
28
+
29
+ - [Login](#login)
30
+ - [AcceptLegalTerms](#acceptlegalterms)
31
+ - [GeneratePromise](#generatepromise)
32
+ - [GetAccounts](#getaccounts)
33
+ - [GetEmails](#getemails)
34
+ - [GetProviders](#getproviders)
35
+ - [SaveEmail](#saveemail)
36
+
37
+ ### Login
38
+
39
+ ```ruby
40
+ response = Credigy::Login.new(user: 'user', password: '123456', cpf: '987654321').call
41
+ authorization_token = response.authorization_token
42
+ ```
43
+
44
+ ### AcceptLegalTerms
45
+
46
+ ```ruby
47
+ Credigy::LegalTermsAcceptance.new(authorization_token).call
48
+ ```
49
+
50
+ ### GeneratePromise
51
+
52
+ ```ruby
53
+ Credigy::Promise.new(
54
+ authorization_token,
55
+ accounts: ['123'], installments: 3, first_installment_date: Date.today, agreement_value: 1580.7
56
+ ).call
57
+ ```
58
+
59
+ ### GetAccounts
60
+
61
+ ```ruby
62
+ response = Credigy::Account.new(authorization_token).call
63
+ response.all # array de contas
64
+ ```
65
+
66
+ ### GetEmails
67
+
68
+ ```ruby
69
+ response = Credigy::Email.new(authorization_token).call
70
+ response.all # array de emails
71
+ ```
72
+
73
+ ### GetProviders
74
+
75
+ ```ruby
76
+ response = Credigy::Provider.new(authorization_token).call
77
+ response.all # array de provedores
78
+ ```
79
+
80
+ ### SaveEmail
81
+
82
+ ```ruby
83
+ Credigy::EmailCreation.new(authorization_token, address: 'foo@test.com').call
84
+ ```
85
+
86
+ ## Configuração (opcional)
87
+
88
+ É possível configurar o comportamento dessa gem via:
89
+
90
+ ```ruby
91
+ Credigy.configure do |config|
92
+ config.verbose = true # default é false
93
+ config.env = :production # qualquer outro symbol será considerado ambiente de desenvolvimento
94
+ config.wsdl = 'http://proxy.meusite.com/wsdl' # caso queira adicionar um proxy
95
+ end
96
+ ```
97
+
98
+ Se estiver no Rails, esse arquivo pode ser colocado em `config/initializers/credigy.rb`.
99
+
100
+ ## Development
101
+
102
+ 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.
103
+
104
+ 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).
105
+
106
+ ## License
107
+
108
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "credigy"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -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,29 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "credigy/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "credigy"
7
+ spec.version = Credigy::VERSION
8
+ spec.authors = ["Glauco Custódio"]
9
+ spec.email = ["glauco.custodio@gmail.com"]
10
+
11
+ spec.summary = %q{Um cliente (não oficial) para o serviço SOAP da Credigy}
12
+ spec.description = %q{Um cliente (não oficial) para o serviço SOAP da Credigy}
13
+ spec.homepage = "https://github.com/glaucocustodio/credigy"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency 'savon', '~> 2'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "pry-nav"
29
+ end
@@ -0,0 +1,13 @@
1
+ require "credigy/version"
2
+
3
+ require "credigy/config"
4
+ require "credigy/account"
5
+ require "credigy/email"
6
+ require "credigy/email_creation"
7
+ require "credigy/login"
8
+ require "credigy/promise"
9
+ require "credigy/provider"
10
+ require "credigy/legal_terms_acceptance"
11
+
12
+ module Credigy
13
+ end
@@ -0,0 +1,10 @@
1
+ require_relative './authorized'
2
+ require_relative './account_response'
3
+
4
+ module Credigy
5
+ class Account < Authorized
6
+ def operation
7
+ :get_accounts
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ require_relative './response'
2
+
3
+ module Credigy
4
+ class AccountResponse < Response
5
+ def all
6
+ Array(body[:accounts][:account])
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ require_relative './request'
2
+
3
+ module Credigy
4
+ class Authorized < Request
5
+ attr_reader :authorization_token
6
+
7
+ def initialize(authorization_token)
8
+ @authorization_token = authorization_token
9
+ end
10
+
11
+ def soap_header
12
+ { 'cred:AuthenticationToken' => { 'cred:Token' => authorization_token } }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,34 @@
1
+ module Credigy
2
+ class << self
3
+ attr_accessor :configuration
4
+ end
5
+
6
+ def self.configure
7
+ self.configuration ||= Configuration.new
8
+ yield(configuration)
9
+ end
10
+
11
+ class Configuration
12
+ attr_accessor :verbose, :env
13
+ attr_writer :wsdl
14
+
15
+ def initialize
16
+ @verbose = false
17
+ @env = :dev
18
+ end
19
+
20
+ def production_env?
21
+ env == :production
22
+ end
23
+
24
+ def wsdl
25
+ return @wsdl if @wsdl
26
+
27
+ if production_env?
28
+ 'https://www.credigy.com.br/CredigyWSP/CredigyAgenciesWSS.asmx?WSDL'.freeze
29
+ else
30
+ 'https://www.credigy.com.br/CredigyWST/CredigyAgenciesWSS.asmx?WSDL'.freeze
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,10 @@
1
+ require_relative './authorized'
2
+ require_relative './email_response'
3
+
4
+ module Credigy
5
+ class Email < Authorized
6
+ def operation
7
+ :get_emails
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ require_relative './authorized'
2
+ require_relative './email_creation_response'
3
+
4
+ module Credigy
5
+ class EmailCreation < Authorized
6
+ attr_reader :address
7
+
8
+ def initialize(authorization_token, address:)
9
+ @authorization_token, @address = authorization_token, address
10
+ end
11
+
12
+ def operation
13
+ :save_email
14
+ end
15
+
16
+ def message
17
+ { 'cred:emailAddress' => address }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,6 @@
1
+ require_relative './response'
2
+
3
+ module Credigy
4
+ class EmailCreationResponse < Response
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ require_relative './response'
2
+
3
+ module Credigy
4
+ class EmailResponse < Response
5
+ def all
6
+ Array(body[:emails][:email])
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ require_relative './authorized'
2
+ require_relative './legal_terms_acceptance_response'
3
+
4
+ module Credigy
5
+ class LegalTermsAcceptance < Authorized
6
+ def operation
7
+ :accept_legal_terms
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ require_relative './response'
2
+
3
+ module Credigy
4
+ class LegalTermsAcceptanceResponse < Response
5
+ end
6
+ end
@@ -0,0 +1,26 @@
1
+ require_relative './request'
2
+ require_relative './login_response'
3
+
4
+ module Credigy
5
+ class Login < Request
6
+ attr_reader :user, :password, :cpf
7
+
8
+ def initialize(user:, password:, cpf:)
9
+ @user, @password, @cpf = user, password, cpf
10
+ end
11
+
12
+ def operation
13
+ :login
14
+ end
15
+
16
+ def soap_header
17
+ {
18
+ 'cred:AuthenticationLogin' => { 'cred:Username' => user, 'cred:Password' => password }
19
+ }
20
+ end
21
+
22
+ def message
23
+ { 'debtorNumber' => cpf }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ require_relative './response'
2
+
3
+ module Credigy
4
+ class LoginResponse < Response
5
+ def name
6
+ body[:name].strip
7
+ end
8
+
9
+ def authorization_token
10
+ body[:authorization_token]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ require_relative './authorized'
2
+ require_relative './promise_response'
3
+
4
+ module Credigy
5
+ class Promise < Authorized
6
+ attr_reader :params
7
+
8
+ # * <tt>authorization_token</tt> - token de autorização
9
+ #
10
+ # ==== Params
11
+ # * <tt>:accounts</tt> - um array de ids de contas. Ex: ['123', '456']
12
+ # * <tt>:installments</tt> - numero de parcelas da promessa
13
+ # * <tt>:first_installment_date</tt> - primeira data de vencimento
14
+ # * <tt>:agreement_value</tt> - valor do acordo
15
+ def initialize(authorization_token, **params)
16
+ @authorization_token = authorization_token
17
+ @params = params
18
+ end
19
+
20
+ def operation
21
+ :generate_promise
22
+ end
23
+
24
+ def message
25
+ {
26
+ 'cred:Accounts' => params[:accounts],
27
+ 'cred:TotalInstallments' => params[:installments],
28
+ 'cred:FirstInstallmentDate' => params[:first_installment_date],
29
+ 'cred:TotalAgreementAmount' => params[:agreement_value]
30
+ }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,6 @@
1
+ require_relative './response'
2
+
3
+ module Credigy
4
+ class PromiseResponse < Response
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ require_relative './authorized'
2
+ require_relative './provider_response'
3
+
4
+ module Credigy
5
+ class Provider < Authorized
6
+ def operation
7
+ :get_providers
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ require_relative './response'
2
+
3
+ module Credigy
4
+ class ProviderResponse < Response
5
+ def all
6
+ Array(body[:providers][:provider])
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,51 @@
1
+ require 'savon'
2
+
3
+ module Credigy
4
+ class Request
5
+ def call
6
+ response_class.new(response, self).tap do |response|
7
+ raise "Falha ao chamar operação #{operation}: #{response.body}" unless response.success?
8
+ end
9
+ end
10
+
11
+ def response_class
12
+ Object.const_get("#{self.class}Response")
13
+ end
14
+
15
+ def response
16
+ client.call(operation, message: message)
17
+ end
18
+
19
+ def client
20
+ @client ||= Savon.client(config_options)
21
+ end
22
+
23
+ def operation
24
+ raise NotImplementedError
25
+ end
26
+
27
+ def message
28
+ {}
29
+ end
30
+
31
+ def config_options
32
+ basic_config.merge(extra_config_options)
33
+ end
34
+
35
+ def basic_config
36
+ { wsdl: wsdl, log: Credigy.configuration.verbose }
37
+ end
38
+
39
+ def extra_config_options
40
+ { soap_header: soap_header, env_namespace: :soapenv, namespace_identifier: :cred }
41
+ end
42
+
43
+ def soap_header
44
+ {}
45
+ end
46
+
47
+ def wsdl
48
+ Credigy.configuration.wsdl
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,18 @@
1
+ module Credigy
2
+ class Response
3
+ extend Forwardable
4
+ def_delegator :raw_response, :success?
5
+
6
+ attr_reader :raw_response, :requester
7
+
8
+ def initialize(raw_response, requester)
9
+ @raw_response = raw_response
10
+ @requester = requester
11
+ end
12
+
13
+ def body
14
+ raw_response
15
+ .body["#{requester.operation}_response".to_sym]["#{requester.operation}_result".to_sym]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Credigy
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: credigy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Glauco Custódio
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: savon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-nav
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Um cliente (não oficial) para o serviço SOAP da Credigy
84
+ email:
85
+ - glauco.custodio@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CHANGELOG.md
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - credigy.gemspec
102
+ - lib/credigy.rb
103
+ - lib/credigy/account.rb
104
+ - lib/credigy/account_response.rb
105
+ - lib/credigy/authorized.rb
106
+ - lib/credigy/config.rb
107
+ - lib/credigy/email.rb
108
+ - lib/credigy/email_creation.rb
109
+ - lib/credigy/email_creation_response.rb
110
+ - lib/credigy/email_response.rb
111
+ - lib/credigy/legal_terms_acceptance.rb
112
+ - lib/credigy/legal_terms_acceptance_response.rb
113
+ - lib/credigy/login.rb
114
+ - lib/credigy/login_response.rb
115
+ - lib/credigy/promise.rb
116
+ - lib/credigy/promise_response.rb
117
+ - lib/credigy/provider.rb
118
+ - lib/credigy/provider_response.rb
119
+ - lib/credigy/request.rb
120
+ - lib/credigy/response.rb
121
+ - lib/credigy/version.rb
122
+ - lib/manual/WebServiceCredigyV1.6.pdf
123
+ homepage: https://github.com/glaucocustodio/credigy
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.6.11
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Um cliente (não oficial) para o serviço SOAP da Credigy
147
+ test_files: []