superfaktura 0.9.1 → 0.9.6

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: 98f14939657dd3c7ddb4d39714b8b0b39e101e988d84a9d011e6931f25ae122f
4
- data.tar.gz: cea7cf5b52c8092f862b391f3bbb9dc818f673bc3693fe6d2901165ebf85d4ed
3
+ metadata.gz: 1eb28dc05047ea0544cbca451fb5f8b35646c6f75c064a14756f0fbd1b6f4b6b
4
+ data.tar.gz: 7fef90b8606d61505394e104b3be710ce03591a91f5e0beb820834df96c85d04
5
5
  SHA512:
6
- metadata.gz: 463af4001e8d10bd019dc0e92b33f9aec0e4863485ad0e720df8b3ad7a886caabe134415b4908e7952f0bc51c782d4a40483dc23b2691644982b81284502e4be
7
- data.tar.gz: a8a1d0c3b20573366c1919cb5719ecb6a1042e18132e8e4f0e747b1e934709f8b9b7ef227b2c157514f26815a4f7d39c3a015f021f4661d0f8d8d0e2b06a1c68
6
+ metadata.gz: 79f972ad659323ba0ad8d41cfbfc04476f76523ee3b6bc50eef2bcd8bec4f921bef798b7e02fd9fbe028ef9657820a15b8f3a0cce8da7ff4cb865fecbb860b6e
7
+ data.tar.gz: ae3f6f428cdfd2e33efbbfdca47feb46ef350d9caf8e0715eddba08af7033b0be8a167a40d0904c8f9efcc2d8b768270819fea7c2a8b1503c86acb0a70404cb7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- superfaktura (0.9.1)
4
+ superfaktura (0.9.6)
5
5
  faraday (~> 1)
6
6
  faraday_middleware (~> 1)
7
7
 
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.com/lubosch/superfaktura.svg?branch=master)](https://travis-ci.com/lubosch/superfaktura)
2
+ [![Coverage Status](https://codecov.io/gh/lubosch/superfaktura/branch/master/graph/badge.svg)](https://codecov.io/gh/lubosch/superfaktura)
1
3
  # Superfaktura
2
4
 
3
5
  Gem for easy integration with http://superfaktura.sk/
@@ -22,8 +24,10 @@ Or install it yourself as:
22
24
 
23
25
  ```
24
26
  Superfaktura.configure do |config|
25
- config.email = Rails.application.config_for(:superfaktura)[:email]
26
- config.token = Rails.application.config_for(:superfaktura)[:token]
27
+ config.email = Rails.application.config_for(:superfaktura)[:email] # registration email
28
+ config.token = Rails.application.config_for(:superfaktura)[:token] # api key
29
+ # for sandbox create an account with the same email at https://sandbox.superfaktura.sk/
30
+ # config.sandbox = !Rails.env.production?
27
31
  end
28
32
  ```
29
33
 
@@ -35,10 +39,22 @@ Initialize `exponea.rb` with this settings:
35
39
 
36
40
  ### Create invoice
37
41
  ```
38
- Superfaktura::CreateInvoice.call(attributes)
42
+ Superfaktura::Invoices.create(attributes)
39
43
  ```
40
44
  - **attributes**: hash for adding invoice. More info here: https://github.com/superfaktura/docs/blob/master/invoice.md#add-invoice
41
45
 
46
+ ### Download invoice
47
+ ```
48
+ Superfaktura::Invoices.download(id, locale: :en)
49
+ ```
50
+ - **id**: superfaktura id
51
+ - **locale**: locale, iso2. More info in Superfaktura::Locales::LANGUAGES
52
+
53
+ ### Check connection
54
+ ```
55
+ Superfaktura::CheckConnection.call : Boolean
56
+ ```
57
+
42
58
  ## Development
43
59
 
44
60
  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.
data/changelog.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.6
4
+ Add sandbox
5
+
6
+ ## 0.9.5
7
+ Update readme
8
+
9
+ ## 0.9.4
10
+ Update readme
11
+
12
+ ## 0.9.3
13
+ Rework invoice download
14
+
15
+ ## 0.9.2
16
+ Adds download invoice option + locales mapper
17
+
3
18
  ## 0.9.1
4
19
  Adds api status check
5
20
 
data/lib/superfaktura.rb CHANGED
@@ -4,8 +4,9 @@ require 'faraday_middleware'
4
4
 
5
5
  require 'superfaktura/version'
6
6
  require 'superfaktura/configuration'
7
+ require 'superfaktura/locales'
7
8
  require 'superfaktura/base_api'
8
- require 'superfaktura/create_invoice'
9
+ require 'superfaktura/invoices'
9
10
  require 'superfaktura/check_connection'
10
11
 
11
12
  module Superfaktura
@@ -1,9 +1,10 @@
1
1
  module Superfaktura
2
2
  class BaseApi
3
3
  SUPERFAKTURA_URL = 'https://moja.superfaktura.sk'.freeze
4
+ SANDBOX_SUPERFAKTURA_URL = 'https://sandbox.superfaktura.sk'.freeze
4
5
 
5
6
  def self.client
6
- Faraday.new(url: SUPERFAKTURA_URL) do |builder|
7
+ Faraday.new(url: superfaktura_url) do |builder|
7
8
  builder.request :url_encoded
8
9
  builder.request :json
9
10
  builder.response :json
@@ -12,12 +13,21 @@ module Superfaktura
12
13
  end
13
14
  end
14
15
 
16
+ def self.file_client
17
+ Faraday.new(url: superfaktura_url) do |builder|
18
+ builder.request :url_encoded
19
+ builder.request :json
20
+
21
+ builder.adapter Faraday.default_adapter
22
+ end
23
+ end
24
+
15
25
  def self.request(uri, method = 'POST', payload = nil)
16
26
  response = client.public_send(method.downcase.to_sym) do |request|
17
27
  request.headers['Authorization'] = "SFAPI email=#{Superfaktura.config.email}&apikey=#{Superfaktura.config.token}"
18
28
 
19
29
  request.url(uri)
20
- request.body = "data=#{payload.to_json}"
30
+ request.body = "data=#{payload.to_json}" if payload
21
31
  end
22
32
  raise Superfaktura::Error, response.body['error_message'] unless response.body['error'].zero?
23
33
 
@@ -28,8 +38,21 @@ module Superfaktura
28
38
  request(path, 'POST', payload)
29
39
  end
30
40
 
31
- def self.get(path, payload)
41
+ def self.get(path, payload = nil)
32
42
  request(path, 'GET', payload)
33
43
  end
44
+
45
+ def self.superfaktura_url
46
+ Superfaktura.config.sandbox ? SANDBOX_SUPERFAKTURA_URL : SUPERFAKTURA_URL
47
+ end
48
+
49
+ def self.file(uri)
50
+ response = file_client.get(uri) do |request|
51
+ request.headers['Authorization'] = "SFAPI email=#{Superfaktura.config.email}&apikey=#{Superfaktura.config.token}"
52
+ end
53
+ raise Superfaktura::Error, response.body['error_message'] unless response.status == 200
54
+
55
+ response.body
56
+ end
34
57
  end
35
58
  end
@@ -1,10 +1,11 @@
1
1
  module Superfaktura
2
2
  class Configuration
3
- attr_accessor :email, :token
3
+ attr_accessor :email, :token, :sandbox
4
4
 
5
5
  def initialize
6
6
  @email = ENV['SUPERFAKTURA_EMAIL']
7
7
  @token = ENV['SUPERFAKTURA_TOKEN']
8
+ @sandbox = ENV['SUPERFAKTURA_SANDBOX'] == 'true' ? true : false
8
9
  end
9
10
  end
10
11
  end
@@ -0,0 +1,11 @@
1
+ module Superfaktura
2
+ class Invoices < BaseApi
3
+ def self.create(attributes)
4
+ post('/invoices/create', attributes)
5
+ end
6
+
7
+ def self.download(id, locale: :en)
8
+ file("/#{Superfaktura::Locales.iso2_to_iso3(locale)}/invoices/pdf/#{id}")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ module Superfaktura
2
+ class Locales
3
+ LANGUAGES = {
4
+ en: 'eng',
5
+ sk: 'slo',
6
+ hu: 'hun',
7
+ cs: 'cze',
8
+ de: 'deu',
9
+ hr: 'hrv',
10
+ it: 'ita',
11
+ pl: 'pol',
12
+ ro: 'rom',
13
+ ru: 'rus',
14
+ sl: 'slv',
15
+ es: 'spa',
16
+ uk: 'ukr'
17
+ }.freeze
18
+
19
+ def self.iso2_to_iso3(iso2)
20
+ LANGUAGES[iso2.to_sym] || 'eng'
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Superfaktura
2
- VERSION = '0.9.1'.freeze
2
+ VERSION = '0.9.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superfaktura
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lubomir Vnenk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-15 00:00:00.000000000 Z
11
+ date: 2021-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -149,6 +149,8 @@ files:
149
149
  - lib/superfaktura/check_connection.rb
150
150
  - lib/superfaktura/configuration.rb
151
151
  - lib/superfaktura/create_invoice.rb
152
+ - lib/superfaktura/invoices.rb
153
+ - lib/superfaktura/locales.rb
152
154
  - lib/superfaktura/version.rb
153
155
  - superfaktura.gemspec
154
156
  homepage: https://github.com/lubosch/superfaktura