bs2 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 807e398d374f47dd9dbbaf9b3846541ce23ab5d87fa4fb4aaa5ad82605f8e640
4
- data.tar.gz: b120f0b40bec65084a7bed921fde8fc61cf24d1f31cc2d3d56fdb077dafa7fb1
3
+ metadata.gz: 25d9e1c0dcc8b4b732aa793f762784256a95cde29ab13792b8db440e124fc274
4
+ data.tar.gz: 5ac162b6cd968b00f89fddac349e828b1be01dfa14da4572d84ecca28c7fefca
5
5
  SHA512:
6
- metadata.gz: 4f718fa861c3ace6662235aa7165553f6e42f0a88a784f19951d5208a070e12ba04c18d9071b897a98263d535e372855f9b413c53a433b0bf2b8e6cd5385e69b
7
- data.tar.gz: 1f6d0f3ae1a081c927187eebae653e048b5914b016030509c680d601a88f92284f58d797bcfa258f9e24364d9c10f7ffe78d937f005ca776b29ea5b230af605e
6
+ metadata.gz: 370f8651e9efa390d3fac5ff5c988aae1907c9a2b35c86114dd4a40cf7b09faf6414d020d51876094b9cd155cb9c3a0ce988c6d0838182738e2df9446adb8b15
7
+ data.tar.gz: ec550f4bc20608a304407ed41654484699d582d92c3d26b8e5c3e1b4f6c1dc42d7949461751ad4420d5ea8e68332e381d9b752e86165b67f9c2fad6268864708
@@ -1,10 +1,9 @@
1
- name: Ruby Gem
1
+ name: Publish
2
2
 
3
3
  on:
4
4
  push:
5
- branches: [ master ]
6
- pull_request:
7
- branches: [ master ]
5
+ paths:
6
+ - lib/bs2/version.rb
8
7
 
9
8
  jobs:
10
9
  build:
@@ -17,6 +16,13 @@ jobs:
17
16
  uses: actions/setup-ruby@v1
18
17
  with:
19
18
  ruby-version: 2.6.x
19
+ - name: Bundle
20
+ run: |
21
+ gem install bundler:2.2.4
22
+ bundle
23
+
24
+ - name: Test
25
+ run: bundle exec rake test
20
26
 
21
27
  - name: Publish to RubyGems
22
28
  run: |
@@ -0,0 +1,26 @@
1
+ name: Test
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ build:
11
+ name: Build + Test
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Set up Ruby 2.6
17
+ uses: actions/setup-ruby@v1
18
+ with:
19
+ ruby-version: 2.6.x
20
+ - name: Bundle
21
+ run: |
22
+ gem install bundler:2.2.4
23
+ bundle
24
+
25
+ - name: Test
26
+ run: bundle exec rake test
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in bs2.gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bs2 (0.1.0)
4
+ bs2 (0.3.0)
5
5
  faraday_middleware
6
6
 
7
7
  GEM
@@ -12,26 +12,45 @@ GEM
12
12
  byebug (11.1.3)
13
13
  crack (0.4.5)
14
14
  rexml
15
- faraday (1.3.0)
15
+ faraday (1.10.3)
16
+ faraday-em_http (~> 1.0)
17
+ faraday-em_synchrony (~> 1.0)
18
+ faraday-excon (~> 1.1)
19
+ faraday-httpclient (~> 1.0)
20
+ faraday-multipart (~> 1.0)
16
21
  faraday-net_http (~> 1.0)
17
- multipart-post (>= 1.2, < 3)
18
- ruby2_keywords
22
+ faraday-net_http_persistent (~> 1.0)
23
+ faraday-patron (~> 1.0)
24
+ faraday-rack (~> 1.0)
25
+ faraday-retry (~> 1.0)
26
+ ruby2_keywords (>= 0.0.4)
27
+ faraday-em_http (1.0.0)
28
+ faraday-em_synchrony (1.0.0)
29
+ faraday-excon (1.1.0)
30
+ faraday-httpclient (1.0.1)
31
+ faraday-multipart (1.0.4)
32
+ multipart-post (~> 2)
19
33
  faraday-net_http (1.0.1)
20
- faraday_middleware (1.0.0)
34
+ faraday-net_http_persistent (1.2.0)
35
+ faraday-patron (1.0.0)
36
+ faraday-rack (1.0.0)
37
+ faraday-retry (1.0.3)
38
+ faraday_middleware (1.2.0)
21
39
  faraday (~> 1.0)
22
40
  hashdiff (1.0.1)
23
41
  minitest (5.14.4)
24
- multipart-post (2.1.1)
42
+ multipart-post (2.3.0)
25
43
  public_suffix (4.0.6)
26
44
  rake (12.3.3)
27
45
  rexml (3.2.4)
28
- ruby2_keywords (0.0.4)
46
+ ruby2_keywords (0.0.5)
29
47
  webmock (3.11.2)
30
48
  addressable (>= 2.3.6)
31
49
  crack (>= 0.3.2)
32
50
  hashdiff (>= 0.4.0, < 2.0.0)
33
51
 
34
52
  PLATFORMS
53
+ ruby
35
54
  x86_64-linux
36
55
 
37
56
  DEPENDENCIES
@@ -42,4 +61,4 @@ DEPENDENCIES
42
61
  webmock
43
62
 
44
63
  BUNDLED WITH
45
- 2.2.4
64
+ 2.2.32
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rake/testtask"
3
5
 
@@ -7,4 +9,4 @@ Rake::TestTask.new(:test) do |t|
7
9
  t.test_files = FileList["test/**/*_test.rb"]
8
10
  end
9
11
 
10
- task :default => :test
12
+ task default: :test
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require "bs2"
data/bs2.gemspec CHANGED
@@ -1,4 +1,6 @@
1
- require_relative 'lib/bs2/version'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/bs2/version"
2
4
 
3
5
  Gem::Specification.new do |spec|
4
6
  spec.name = "bs2"
@@ -6,8 +8,8 @@ Gem::Specification.new do |spec|
6
8
  spec.authors = ["Emerson Almeida"]
7
9
  spec.email = ["emersona@megafono.host"]
8
10
 
9
- spec.summary = %q{BS2 Ruby SDK}
10
- spec.description = %q{Gem to integration your ruby app with BS2}
11
+ spec.summary = "BS2 Ruby SDK"
12
+ spec.description = "Gem to integration your ruby app with BS2"
11
13
  spec.homepage = "https://github.com/megafono/bs2-ruby"
12
14
  spec.license = "MIT"
13
15
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
@@ -20,12 +22,12 @@ Gem::Specification.new do |spec|
20
22
 
21
23
  # Specify which files should be added to the gem when it is released.
22
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
24
26
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
27
  end
26
28
  spec.bindir = "exe"
27
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
30
  spec.require_paths = ["lib"]
29
31
 
30
- spec.add_dependency 'faraday_middleware'
32
+ spec.add_dependency "faraday_middleware"
31
33
  end
data/lib/bs2/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BS2
2
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
3
5
  end
data/lib/bs2.rb CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bs2/version"
2
4
  require "base64"
3
- require 'forwardable'
5
+ require "forwardable"
4
6
  require "bundler/setup"
5
7
  require "logger"
6
8
  require "faraday_middleware"
@@ -30,8 +32,7 @@ module BS2
30
32
  end
31
33
 
32
34
  private
33
-
34
- attr_writer :configuration, :connection
35
+ attr_writer :configuration, :connection
35
36
  end
36
37
 
37
38
 
@@ -49,16 +50,18 @@ module BS2
49
50
  conn.response :logger, BS2.configuration.logger, { headers: true, bodies: json }
50
51
  conn.adapter Faraday.default_adapter
51
52
 
52
- conn.authorization('Bearer', @access_token)
53
+ conn.authorization("Bearer", @access_token)
53
54
  end
54
55
  end
55
56
 
56
- def generate_pdf(id, filename)
57
+ def generate_pdf(id)
57
58
  connector = create_connector(false)
58
59
 
59
60
  response = connector.get("/pj/forintegration/cobranca/v1/boletos/#{id}/imprimivel")
60
61
 
61
- File.open(filename, 'wb') { |fp| fp.write(response.body) }
62
+ return false unless response.success?
63
+
64
+ response.body
62
65
  end
63
66
 
64
67
  def fetch_billet(id)
@@ -81,11 +84,17 @@ module BS2
81
84
  resp.body
82
85
  end
83
86
 
87
+ def create_billet_v2(data)
88
+ create_connector.post("/pj/forintegration/cobranca/v2/boletos/simplificado", data)
89
+ end
90
+
84
91
  def create_billet(data)
85
92
  connector = create_connector
86
93
 
87
94
  resp = connector.post("/pj/forintegration/cobranca/v1/boletos/simplificado", data)
88
95
 
96
+ return false unless resp.success?
97
+
89
98
  resp.body
90
99
  end
91
100
 
@@ -95,22 +104,22 @@ module BS2
95
104
  conn.basic_auth(BS2.configuration.api_key, BS2.configuration.api_secret)
96
105
  conn.response :json
97
106
  conn.adapter Faraday.default_adapter
98
- # conn.response :logger, BS2.configuration.logger, { headers: true, bodies: true }
107
+ conn.response :logger, BS2.configuration.logger, { headers: true, bodies: true }
99
108
  end
100
109
 
101
110
  # TODO: test connection errors
102
111
  response = connection.post("/auth/oauth/v2/token", {
103
112
  grant_type: "password",
104
113
  scope: "forintegration",
105
- username: BS2.configuration.username || "d",
106
- password: BS2.configuration.password || "e"
107
- }.map { |(key, value)| "#{key}=#{value}" }.join("&"), { 'Accept': 'application/json' })
114
+ username: BS2.configuration.username,
115
+ password: BS2.configuration.password
116
+ }.map { |(key, value)| "#{key}=#{value}" }.join("&"), { 'Accept': "application/json" })
108
117
 
109
118
  body = response.body
110
- @access_token = body.fetch('access_token')
111
- @token_type = body.fetch('token_type')
112
- @expires_in = Time.now + body.fetch('expires_in').to_i
113
- @refresh_token = body.fetch('refresh_token')
119
+ @access_token = body.fetch("access_token")
120
+ @token_type = body.fetch("token_type")
121
+ @expires_in = Time.now + body.fetch("expires_in").to_i
122
+ @refresh_token = body.fetch("refresh_token")
114
123
 
115
124
  true
116
125
  end
@@ -120,7 +129,7 @@ module BS2
120
129
  attr_accessor :api_key, :api_secret, :username, :password, :env, :logger
121
130
 
122
131
  def env
123
- @env || 'sandbox'
132
+ @env || "sandbox"
124
133
  end
125
134
 
126
135
  def endpoint
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bs2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emerson Almeida
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-18 00:00:00.000000000 Z
11
+ date: 2023-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday_middleware
@@ -31,7 +31,8 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - ".github/workflows/gem-push.yml"
34
+ - ".github/workflows/publish.yml"
35
+ - ".github/workflows/test.yml"
35
36
  - ".gitignore"
36
37
  - ".travis.yml"
37
38
  - CODE_OF_CONDUCT.md
@@ -52,7 +53,7 @@ metadata:
52
53
  homepage_uri: https://github.com/megafono/bs2-ruby
53
54
  source_code_uri: https://github.com/megafono/bs2-ruby
54
55
  changelog_uri: https://github.com/megafono/bs2-ruby/files/CHANGELOG.md
55
- post_install_message:
56
+ post_install_message:
56
57
  rdoc_options: []
57
58
  require_paths:
58
59
  - lib
@@ -67,8 +68,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
68
  - !ruby/object:Gem::Version
68
69
  version: '0'
69
70
  requirements: []
70
- rubygems_version: 3.0.3
71
- signing_key:
71
+ rubygems_version: 3.2.32
72
+ signing_key:
72
73
  specification_version: 4
73
74
  summary: BS2 Ruby SDK
74
75
  test_files: []