siba_api 0.1.0 → 0.1.2

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: 7bbba86823deead2120faa71d5277a25da5a1e4ca99b9b1c60f25fb7fda70678
4
- data.tar.gz: cc0f1f091f4deae42e93d167b56e6704f4df42caf5bbf91933f0e50e8afd75a3
3
+ metadata.gz: 2929ab1ae6f928a97b601d83ea4d871b1959e2848a2bc92b0399246fc14363bc
4
+ data.tar.gz: a31566a2a8674a88f43ae8d5165767f5ec46e9df0a8b026a8bf3a675e2adfcf1
5
5
  SHA512:
6
- metadata.gz: 1f452bf2a48e5b6af0cd9b1d7abea1633d495350b8063a19a48c24be246f9fc6ee13ea9cb05f0a34b01784e8bc7cf830696c9879c169bf6723ff18101cc822da
7
- data.tar.gz: fe4feceba7c8f50a01582aecc811b9ae7bbc080425dfad1b9005023ee31f97e16e03af17e8304da0089f83f3cc60c70d57aeadd789f0c6894a266eec472d3781
6
+ metadata.gz: 1438b3ca259ab15f0af6cf20c14107aaddc0a4dabfec1efb8456517d83bd0d9a819fc5781c8b213f2032dfd66f035f96482101a74cb6e53b02b762ad1227c6f5
7
+ data.tar.gz: 177a6e089009cbad1efe1cf4b02b861ffd9208e19274976c7db0669dd522ad8f9c26cdd38e4c36d796146717378764e678455a2342eb96d4a482925703e33dd2
data/.irbrc CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'irb'
2
4
  require 'irb/completion'
3
5
  require 'rubygems'
data/.rubocop.yml CHANGED
@@ -12,3 +12,10 @@ Layout/LineLength:
12
12
  AllCops:
13
13
  TargetRubyVersion: 2.4.0
14
14
  NewCops: enable
15
+
16
+ Metrics/BlockLength:
17
+ Exclude:
18
+ - 'Rakefile'
19
+ - '**/*.rake'
20
+ - 'test/**/*.rb'
21
+ - 'spec/**/*.rb'
data/Gemfile CHANGED
@@ -5,8 +5,6 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in siba_api.gemspec
6
6
  gemspec
7
7
 
8
- gem 'dotenv', '~> 2.7'
9
-
10
8
  group :test do
11
9
  gem 'rake', '~> 13.0'
12
10
  gem 'rspec', '~> 3.0'
data/Gemfile.lock CHANGED
@@ -1,62 +1,68 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- siba_api (0.1.0)
5
- gyoku (~> 1.0)
6
- savon (~> 2.12)
4
+ siba_api (0.1.1)
5
+ dry-configurable (~> 0.12)
6
+ gyoku (~> 1.4.0)
7
+ savon (~> 2.13)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
11
- addressable (2.7.0)
12
- public_suffix (>= 2.0.2, < 5.0)
12
+ addressable (2.8.1)
13
+ public_suffix (>= 2.0.2, < 6.0)
13
14
  akami (1.3.1)
14
15
  gyoku (>= 0.4.0)
15
16
  nokogiri
16
17
  ast (2.4.2)
17
18
  builder (3.2.4)
19
+ concurrent-ruby (1.1.10)
18
20
  crack (0.4.5)
19
21
  rexml
20
- diff-lcs (1.4.4)
21
- dotenv (2.7.6)
22
+ diff-lcs (1.5.0)
23
+ dry-configurable (0.16.1)
24
+ dry-core (~> 0.6)
25
+ zeitwerk (~> 2.6)
26
+ dry-core (0.9.1)
27
+ concurrent-ruby (~> 1.0)
28
+ zeitwerk (~> 2.6)
22
29
  gyoku (1.4.0)
23
30
  builder (>= 2.1.2)
24
31
  rexml (~> 3.0)
25
32
  hashdiff (1.0.1)
26
- httpi (2.5.0)
33
+ httpi (3.0.1)
27
34
  rack
28
- socksify
29
35
  mail (2.7.1)
30
36
  mini_mime (>= 0.1.1)
31
37
  mini_mime (1.1.2)
32
- nokogiri (1.13.8-aarch64-linux)
38
+ nokogiri (1.13.9-aarch64-linux)
33
39
  racc (~> 1.4)
34
- nokogiri (1.13.8-x86_64-linux)
40
+ nokogiri (1.13.9-x86_64-linux)
35
41
  racc (~> 1.4)
36
42
  nori (2.6.0)
37
- parallel (1.20.1)
38
- parser (3.0.0.0)
43
+ parallel (1.22.1)
44
+ parser (3.1.2.1)
39
45
  ast (~> 2.4.1)
40
- public_suffix (4.0.6)
46
+ public_suffix (5.0.0)
41
47
  racc (1.6.0)
42
- rack (2.2.4)
43
- rainbow (3.0.0)
44
- rake (13.0.3)
45
- regexp_parser (2.1.1)
46
- rexml (3.2.4)
47
- rspec (3.10.0)
48
- rspec-core (~> 3.10.0)
49
- rspec-expectations (~> 3.10.0)
50
- rspec-mocks (~> 3.10.0)
51
- rspec-core (3.10.1)
52
- rspec-support (~> 3.10.0)
53
- rspec-expectations (3.10.1)
48
+ rack (3.0.0)
49
+ rainbow (3.1.1)
50
+ rake (13.0.6)
51
+ regexp_parser (2.6.0)
52
+ rexml (3.2.5)
53
+ rspec (3.12.0)
54
+ rspec-core (~> 3.12.0)
55
+ rspec-expectations (~> 3.12.0)
56
+ rspec-mocks (~> 3.12.0)
57
+ rspec-core (3.12.0)
58
+ rspec-support (~> 3.12.0)
59
+ rspec-expectations (3.12.0)
54
60
  diff-lcs (>= 1.2.0, < 2.0)
55
- rspec-support (~> 3.10.0)
56
- rspec-mocks (3.10.2)
61
+ rspec-support (~> 3.12.0)
62
+ rspec-mocks (3.12.0)
57
63
  diff-lcs (>= 1.2.0, < 2.0)
58
- rspec-support (~> 3.10.0)
59
- rspec-support (3.10.2)
64
+ rspec-support (~> 3.12.0)
65
+ rspec-support (3.12.0)
60
66
  rubocop (0.93.1)
61
67
  parallel (~> 1.10)
62
68
  parser (>= 2.7.1.5)
@@ -66,10 +72,10 @@ GEM
66
72
  rubocop-ast (>= 0.6.0)
67
73
  ruby-progressbar (~> 1.7)
68
74
  unicode-display_width (>= 1.4.0, < 2.0)
69
- rubocop-ast (1.4.1)
70
- parser (>= 2.7.1.5)
75
+ rubocop-ast (1.23.0)
76
+ parser (>= 3.1.1.0)
71
77
  ruby-progressbar (1.11.0)
72
- savon (2.13.0)
78
+ savon (2.13.1)
73
79
  akami (~> 1.2)
74
80
  builder (>= 2.1.2)
75
81
  gyoku (~> 1.2)
@@ -78,24 +84,23 @@ GEM
78
84
  nokogiri (>= 1.8.1)
79
85
  nori (~> 2.4)
80
86
  wasabi (~> 3.4)
81
- socksify (1.7.1)
82
- unicode-display_width (1.7.0)
83
- vcr (6.0.0)
84
- wasabi (3.7.0)
87
+ unicode-display_width (1.8.0)
88
+ vcr (6.1.0)
89
+ wasabi (3.8.0)
85
90
  addressable
86
- httpi (~> 2.0)
91
+ httpi (~> 3.0)
87
92
  nokogiri (>= 1.4.2)
88
- webmock (3.12.2)
89
- addressable (>= 2.3.6)
93
+ webmock (3.18.1)
94
+ addressable (>= 2.8.0)
90
95
  crack (>= 0.3.2)
91
96
  hashdiff (>= 0.4.0, < 2.0.0)
97
+ zeitwerk (2.6.1)
92
98
 
93
99
  PLATFORMS
94
100
  aarch64-linux
95
101
  x86_64-linux
96
102
 
97
103
  DEPENDENCIES
98
- dotenv (~> 2.7)
99
104
  rake (~> 13.0)
100
105
  rspec (~> 3.0)
101
106
  rubocop (~> 0.80)
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # SIBA API Wrapper
2
2
 
3
+ ![main workflow](https://github.com/dlage/siba_api/actions/workflows/main.yml/badge.svg)
4
+
3
5
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library
4
6
  into a gem. Put your Ruby code in the file `lib/siba_api`. To experiment with that code, run `bin/console` for an
5
7
  interactive prompt.
data/lib/siba_api/api.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'api_exceptions'
4
- require_relative 'configuration'
5
4
  require_relative 'constants'
6
5
  require_relative 'http_status_codes'
6
+ require 'dry-configurable'
7
7
 
8
8
  module SIBAApi
9
9
  # Core class responsible for api interface operations
@@ -11,22 +11,8 @@ module SIBAApi
11
11
  include ApiExceptions
12
12
  include Constants
13
13
  include HttpStatusCodes
14
+ include Dry::Configurable
14
15
 
15
- attr_reader(*SIBAApi.configuration.property_names)
16
-
17
- attr_accessor :current_options, :last_response
18
-
19
- # Callback to update current configuration options
20
- class_eval do
21
- SIBAApi.configuration.property_names.each do |key|
22
- define_method "#{key}=" do |arg|
23
- instance_variable_set("@#{key}", arg)
24
- current_options.merge!({ "#{key}": arg })
25
- end
26
- end
27
- end
28
-
29
- API_WSDL = 'https://siba.sef.pt/bawsdev/boletinsalojamento.asmx?wsdl'
30
16
  HTTP_STATUS_MAPPING = {
31
17
  HTTP_BAD_REQUEST_CODE => BadRequestError,
32
18
  HTTP_UNAUTHORIZED_CODE => UnauthorizedError,
@@ -36,15 +22,42 @@ module SIBAApi
36
22
  'default' => ApiError
37
23
  }.freeze
38
24
 
25
+ setting :follow_redirects, default: true
26
+
27
+ # The value sent in the http header for 'User-Agent' if none is set
28
+ setting :user_agent, default: "SIBAApi API Ruby Gem #{SIBAApi::VERSION}"
29
+
30
+ # By default uses the Faraday connection options if none is set
31
+ setting :connection_options, default: {}
32
+
33
+ # Add Faraday::RackBuilder to overwrite middleware
34
+ setting :stack
35
+
36
+ # WSDL to use for SIBA API
37
+ setting :wsdl, default: API_WSDL, reader: true
38
+
39
+ # Hotel unit
40
+ setting :hotel_unit, default: API_HOTEL_UNIT, reader: true
41
+
42
+ # API Key
43
+ setting :access_key, default: API_ACCESS_KEY, reader: true
44
+
45
+ # Establishment to use
46
+ setting :establishment, default: API_ESTABLISHMENT, reader: true
47
+
48
+ # Hotel Unit complete information
49
+ setting :hotel_unit_info, default: API_HOTEL_UNIT_INFO, reader: true
50
+
51
+ attr_accessor :last_response
52
+
39
53
  # Create new API
40
54
  #
41
55
  # @api public
42
56
  def initialize(options = {}, &block)
43
- opts = SIBAApi.configuration.fetch.merge(options)
44
- @current_options = opts
45
-
46
- SIBAApi.configuration.property_names.each do |key|
47
- send("#{key}=", opts[key])
57
+ configure do |c|
58
+ options.each_key do |key|
59
+ c.send("#{key}=", options[key])
60
+ end
48
61
  end
49
62
 
50
63
  yield_or_eval(&block) if block_given?
@@ -63,7 +76,7 @@ module SIBAApi
63
76
 
64
77
  def client
65
78
  @client ||= Savon.client do |globals|
66
- globals.wsdl @wsdl
79
+ globals.wsdl config.wsdl
67
80
  globals.log true
68
81
  globals.log_level :debug
69
82
  globals.convert_request_keys_to :camelcase
@@ -72,36 +85,26 @@ module SIBAApi
72
85
 
73
86
  def request(operation:, params: {})
74
87
  default_params = {
75
- UnidadeHoteleira: @current_options[:hotel_unit],
76
- Estabelecimento: @current_options[:establishment],
77
- ChaveAcesso: @current_options[:access_key]
88
+ UnidadeHoteleira: config.hotel_unit,
89
+ Estabelecimento: config.establishment,
90
+ ChaveAcesso: config.access_key
78
91
  }
79
92
 
80
93
  response = client.call(operation.to_sym, message: default_params.merge(params))
81
94
  self.last_response = response
82
95
 
96
+ process_operation_response(operation, response)
97
+ end
98
+
99
+ def process_operation_response(operation, response)
83
100
  if response_successful?(response)
84
101
  result = response.body["#{operation}_response".to_sym]["#{operation}_result".to_sym]
85
102
  return response if result == '0'
86
-
87
- parsed_response = parse_response(result)
88
- raise error_class(response.http.code), "Code: #{parsed_response[:codigo_retorno]}, response: #{response.body}, description: #{parsed_response[:descricao]}"
89
103
  end
90
104
 
91
105
  raise error_class(response.http.code), "Code: #{response.http.code}, response: #{response.body}"
92
106
  end
93
107
 
94
- # Error:
95
- # {:erros_ba=>
96
- # {:retorno_ba=>
97
- # {:linha=>"0",
98
- # :codigo_retorno=>"75",
99
- # :descricao=>
100
- # "Linha XML 6. -->The element 'Unidade_Hoteleira' in namespace 'http://sef.pt/BAws' has incomplete content. List of possible elements expected: 'Abreviatura' in namespace 'http://sef.pt/BAws'."},
101
- # :@xmlns=>"http://www.sef.pt/BAws"}}
102
- #
103
- # Success:
104
- #
105
108
  def parse_response(result)
106
109
  inner_response = Nori.new(convert_tags_to: ->(tag) { tag.snakecase.to_sym }).parse(
107
110
  result
@@ -122,24 +125,5 @@ module SIBAApi
122
125
  def response_successful?(response)
123
126
  response.successful? and (response.http.code == HTTP_OK_CODE)
124
127
  end
125
-
126
- # Responds to attribute query or attribute clear
127
- #
128
- # @api private
129
- def method_missing(method_name, *args, &block)
130
- # :nodoc:
131
- case method_name.to_s
132
- when /^(.*)\?$/
133
- !!send(Regexp.last_match(1).to_s)
134
- when /^clear_(.*)$/
135
- send("#{Regexp.last_match(1)}=", nil)
136
- else
137
- super
138
- end
139
- end
140
-
141
- def respond_to_missing?(method_name, include_private = false)
142
- method_name.to_s.start_with?('clear_') || super
143
- end
144
128
  end
145
129
  end
@@ -46,21 +46,7 @@ module SIBAApi
46
46
  # 'Data_Saida' => '20220831',
47
47
  # 'Local_Residencia_Origem' => 'Place of Residence',
48
48
  def deliver_bulletins(file_number, bulletins = [], _global_params = {})
49
- logger = Logger.new $stderr
50
- logger.level = Logger::DEBUG
51
- bulletins_xml = Gyoku.xml(
52
- {
53
- 'MovimentoBAL' => {
54
- 'Unidade_Hoteleira' => build_hotel_unit,
55
- 'Boletim_Alojamento' => build_bulletins(bulletins),
56
- 'Envio' => build_control_data(file_number),
57
- :@xmlns => 'http://sef.pt/BAws'
58
- }
59
- },
60
- pretty_print: true
61
- )
62
- logger.debug(bulletins_xml)
63
- bulletins_encoded = Base64.encode64(bulletins_xml)
49
+ bulletins_encoded = build_encoded_bulletins_xml(file_number, bulletins)
64
50
  response = request(
65
51
  operation: :entrega_boletins_alojamento,
66
52
  params: {
@@ -72,6 +58,19 @@ module SIBAApi
72
58
 
73
59
  protected
74
60
 
61
+ def build_encoded_bulletins_xml(file_number, bulletins)
62
+ bulletins_xml = Gyoku.xml(
63
+ {
64
+ 'MovimentoBAL' => {
65
+ 'Unidade_Hoteleira' => build_hotel_unit, 'Boletim_Alojamento' => build_bulletins(bulletins),
66
+ 'Envio' => build_control_data(file_number), :@xmlns => 'http://sef.pt/BAws'
67
+ }
68
+ },
69
+ pretty_print: true
70
+ )
71
+ Base64.encode64(bulletins_xml)
72
+ end
73
+
75
74
  # <Unidade_Hoteleira>
76
75
  # <Codigo_Unidade_Hoteleira>121212121</Codigo_Unidade_Hoteleira>
77
76
  # <Estabelecimento>00</Estabelecimento>
@@ -87,33 +86,17 @@ module SIBAApi
87
86
  # <Email_Contacto>teste.teste@sef.pt</Email_Contacto>
88
87
  # </Unidade_Hoteleira>
89
88
  def build_hotel_unit
90
- @hotel_unit_info
89
+ config.hotel_unit_info
91
90
  end
92
91
 
93
92
  # <Numero_Ficheiro>97</Numero_Ficheiro>
94
93
  # <Data_Movimento>2008-05-20T00:00:00</Data_Movimento>
95
94
  def build_control_data(file_number)
96
- {
97
- 'Numero_Ficheiro' => file_number,
98
- 'Data_Movimento' => DateTime.now.strftime('%FT%T')
99
- }
95
+ { 'Numero_Ficheiro' => file_number, 'Data_Movimento' => DateTime.now.strftime('%FT%T') }
100
96
  end
101
97
 
102
98
  def build_bulletins(bulletins = [])
103
- translation_hash = {
104
- surname: 'Apelido',
105
- name: 'Nome',
106
- nationality: 'Nacionalidade',
107
- birthdate: 'Data_Nascimento',
108
- place_of_birth: 'Local_Nascimento',
109
- id_document: 'Documento_Identificacao',
110
- document_country: 'Pais_Emissor_Documento',
111
- document_type: 'Tipo_Documento',
112
- start_date: 'Data_Entrada',
113
- end_date: 'Data_Saida',
114
- origin_country: 'Pais_Residencia_Origem',
115
- origin_place: 'Local_Residencia_Origem'
116
- }
99
+ translation_hash = bulletin_translation_hash
117
100
  translated_bulletins = []
118
101
  bulletins.each do |b|
119
102
  bt = {}
@@ -125,18 +108,25 @@ module SIBAApi
125
108
  translated_bulletins
126
109
  end
127
110
 
111
+ def bulletin_translation_hash
112
+ {
113
+ surname: 'Apelido', name: 'Nome', nationality: 'Nacionalidade',
114
+ birthdate: 'Data_Nascimento', place_of_birth: 'Local_Nascimento',
115
+ id_document: 'Documento_Identificacao', document_country: 'Pais_Emissor_Documento',
116
+ document_type: 'Tipo_Documento',
117
+ start_date: 'Data_Entrada', end_date: 'Data_Saida',
118
+ origin_country: 'Pais_Residencia_Origem', origin_place: 'Local_Residencia_Origem'
119
+ }
120
+ end
121
+
128
122
  def process_response(response)
129
123
  result = response
130
124
  case result
131
125
  when Hash
132
126
  result.transform_keys!(&:to_sym)
133
- result.each_value do |r|
134
- process_response(r)
135
- end
127
+ result.each_value { |r| process_response(r) }
136
128
  when Array
137
- result.each do |r|
138
- process_response(r)
139
- end
129
+ result.each { |r| process_response(r) }
140
130
  end
141
131
  result
142
132
  end
@@ -58,5 +58,29 @@ module SIBAApi
58
58
  PARAM_START_PAGE = 'start_page'
59
59
 
60
60
  PARAM_INCLUDE_RELATED = 'include_related_objects'
61
+
62
+ # Default API config constants
63
+ API_WSDL = 'https://siba.sef.pt/bawsdev/boletinsalojamento.asmx?wsdl'
64
+
65
+ API_HOTEL_UNIT = '121212121'
66
+
67
+ API_HOTEL_UNIT_INFO = {
68
+ 'Codigo_Unidade_Hoteleira' => '121212121',
69
+ 'Estabelecimento' => '00',
70
+ 'Nome' => 'Hotel teste',
71
+ 'Abreviatura' => 'teste',
72
+ 'Morada' => 'Rua da Alegria, 172',
73
+ 'Localidade' => 'Portalegre',
74
+ 'Codigo_Postal' => '1000',
75
+ 'Zona_Postal' => '234',
76
+ 'Telefone' => '214017744',
77
+ 'Fax' => '214017766',
78
+ 'Nome_Contacto' => 'Nuno teste',
79
+ 'Email_Contacto' => 'teste.teste@sef.pt'
80
+ }.freeze
81
+
82
+ API_ACCESS_KEY = '999999999'
83
+
84
+ API_ESTABLISHMENT = '00'
61
85
  end
62
86
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SIBAApi
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.2'
5
5
  end
data/lib/siba_api.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'savon'
4
3
  require_relative 'siba_api/version'
4
+ require 'savon'
5
5
 
6
6
  # Base module for SIBA API Wrapper
7
7
  module SIBAApi
@@ -12,35 +12,6 @@ module SIBAApi
12
12
  LIBDIR = File.expand_path(LIBNAME.to_s, __dir__)
13
13
 
14
14
  class << self
15
- # The client configuration
16
- #
17
- # @return [Configuration]
18
- #
19
- # @api public
20
- def configuration
21
- @configuration ||= Configuration.new
22
- end
23
-
24
- alias config configuration
25
-
26
- # Configure options
27
- #
28
- # @example
29
- # SIBAApi.configure do |c|
30
- # c.some_option = true
31
- # end
32
- #
33
- # @yield the configuration block
34
- # @yieldparam configuration [SIBAApi::Configuration]
35
- # the configuration instance
36
- #
37
- # @return [nil]
38
- #
39
- # @api public
40
- def configure
41
- yield configuration
42
- end
43
-
44
15
  # Alias for SIBAApi::Client.new
45
16
  #
46
17
  # @param [Hash] options
@@ -69,20 +40,15 @@ module SIBAApi
69
40
  def method_missing(method_name, *args, &block)
70
41
  if new.respond_to?(method_name)
71
42
  new.send(method_name, *args, &block)
72
- elsif configuration.respond_to?(method_name)
73
- SIBAApi.configuration.send(method_name, *args, &block)
74
43
  else
75
44
  super.respond_to_missing?
76
45
  end
77
46
  end
78
47
 
79
48
  def respond_to_missing?(method_name, include_private = false)
80
- new.respond_to?(method_name, include_private) ||
81
- configuration.respond_to?(method_name) ||
82
- super(method_name, include_private)
49
+ new.respond_to?(method_name, include_private) || super(method_name, include_private)
83
50
  end
84
51
  end
85
52
  end
86
53
 
87
54
  require_relative 'siba_api/client'
88
- require_relative 'siba_api/configuration'
data/siba_api.gemspec CHANGED
@@ -30,10 +30,10 @@ Gem::Specification.new do |spec|
30
30
  spec.require_paths = ['lib']
31
31
 
32
32
  # Uncomment to register a new dependency of your gem
33
- spec.add_dependency 'gyoku', '~> 1.0'
34
- spec.add_dependency 'savon', '~> 2.12'
33
+ spec.add_dependency 'gyoku', '~> 1.4.0'
34
+ spec.add_dependency 'savon', '~> 2.13'
35
35
 
36
- # spec.add_dependency 'dry-configurable', '~> 0.12.1'
36
+ spec.add_dependency 'dry-configurable', '~> 0.12'
37
37
 
38
38
  # For more information and examples about making a new gem, checkout our
39
39
  # guide at: https://bundler.io/guides/creating_gem.html
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: siba_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dinis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-23 00:00:00.000000000 Z
11
+ date: 2022-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gyoku
@@ -16,28 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: 1.4.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.0'
26
+ version: 1.4.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: savon
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.12'
33
+ version: '2.13'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.12'
40
+ version: '2.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dry-configurable
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.12'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.12'
41
55
  description: A gem that implements functions from the SIBA API.
42
56
  email:
43
57
  - dinis@lage.pw
@@ -64,12 +78,8 @@ files:
64
78
  - docker-compose.yml
65
79
  - lib/siba_api.rb
66
80
  - lib/siba_api/api.rb
67
- - lib/siba_api/api/config.rb
68
- - lib/siba_api/api/config/property.rb
69
- - lib/siba_api/api/config/property_set.rb
70
81
  - lib/siba_api/api_exceptions.rb
71
82
  - lib/siba_api/client.rb
72
- - lib/siba_api/configuration.rb
73
83
  - lib/siba_api/constants.rb
74
84
  - lib/siba_api/http_status_codes.rb
75
85
  - lib/siba_api/version.rb
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SIBAApi
4
- class API
5
- class Config
6
- # Property objects provide an interface for configuration options
7
- class Property
8
- attr_reader :name, :default, :required
9
-
10
- def initialize(name, options)
11
- @name = name
12
- @default = options.fetch(:default, nil)
13
- @required = options.fetch(:required, nil)
14
- @options = options
15
- end
16
-
17
- # @api private
18
- def define_accessor_methods(properties)
19
- properties.define_reader_method(self, name, :public)
20
- properties.define_writer_method(self, "#{name}=", :public)
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,119 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'set'
4
-
5
- module SIBAApi
6
- class API
7
- class Config
8
- # Class responsible for storing configuration properties
9
- class PropertySet
10
- include Enumerable
11
-
12
- attr_reader :parent, :properties
13
-
14
- # Initialize an PropertySet
15
- #
16
- # @param [Object] parent
17
- # @param [Set] properties
18
- #
19
- # @return [undefined]
20
- #
21
- # @api private
22
- def initialize(parent = nil, properties = Set.new)
23
- @parent = parent
24
- @properties = properties
25
- @map = {}
26
- end
27
-
28
- # Iterate over properties
29
- #
30
- # @yield [property]
31
- #
32
- # @yieldparam [Property] property
33
- #
34
- # @return [self]
35
- #
36
- # @api public
37
- def each
38
- return to_enum unless block_given?
39
-
40
- @map.each { |name, property| yield property if name.is_a?(Symbol) }
41
- self
42
- end
43
-
44
- # Adds property to the set
45
- #
46
- # @example
47
- # properties_set << property
48
- #
49
- # @param [Property] property
50
- #
51
- # @return [self]
52
- #
53
- # @api public
54
- def <<(property)
55
- properties << property
56
- update_map(property.name, property.default)
57
- property.define_accessor_methods(self)
58
- self
59
- end
60
-
61
- # Access property by name
62
- #
63
- # @api public
64
- def [](name)
65
- @map[name]
66
- end
67
- alias fetch []
68
-
69
- # Set property value by name
70
- #
71
- # @api public
72
- def []=(name, property)
73
- update_map(name, property)
74
- end
75
-
76
- # Update map with index
77
- #
78
- # @api private
79
- def update_map(name, property)
80
- @map[name.to_sym] = @map[name.to_s.freeze] = property
81
- end
82
-
83
- # Convert properties to a hash of property names and
84
- # corresponding values
85
- #
86
- # @api public
87
- def to_hash
88
- properties.each_with_object({}) do |property, props|
89
- name = property.name
90
- props[name] = self[name]
91
- end
92
- end
93
-
94
- # Check if properties exist
95
- #
96
- # @api public
97
- def empty?
98
- @map.empty?
99
- end
100
-
101
- # @api private
102
- def define_reader_method(property, method_name, visibility)
103
- property_set = self
104
- parent.send(:define_method, method_name) { property_set[property.name] }
105
- parent.send(visibility, method_name)
106
- end
107
-
108
- # @api private
109
- def define_writer_method(property, method_name, visibility)
110
- property_set = self
111
- parent.send(:define_method, method_name) do |value|
112
- property_set[property.name] = value
113
- end
114
- parent.send(visibility, method_name)
115
- end
116
- end
117
- end
118
- end
119
- end
@@ -1,101 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'config/property'
4
- require_relative 'config/property_set'
5
-
6
- module SIBAApi
7
- class API
8
- # A base class for constructing api configuration
9
- class Config
10
- # Defines a property on an object's class or instance
11
- #
12
- # @example
13
- # class Configuration < Api::Config
14
- # property :adapter, default: :net_http
15
- # property :user, required: true
16
- # end
17
- #
18
- # @param [Symbol] name
19
- # the name of a property
20
- #
21
- # @param [#to_hash] options
22
- # the extra options
23
- #
24
- # @return [self]
25
- #
26
- # @api public
27
- def self.property(name, options = {})
28
- property_set << Property.new(name, options)
29
- update_subclasses(name, options)
30
- self
31
- end
32
-
33
- def self.update_subclasses(name, options)
34
- @subclasses.each { |klass| klass.property(name, options) } if defined?(@subclasses) && @subclasses
35
- end
36
-
37
- # Check if property is defined
38
- #
39
- # @param [Symbol] name
40
- # the name to check
41
- #
42
- # @return [Boolean]
43
- #
44
- # @api public
45
- def self.property?(name)
46
- property_set.include?(name)
47
- end
48
-
49
- class << self
50
- attr_reader :property_set
51
- end
52
-
53
- instance_variable_set('@property_set', PropertySet.new(self))
54
-
55
- def self.inherited(descendant)
56
- super
57
- (@subclasses ||= Set.new) << descendant
58
- descendant.instance_variable_set(
59
- '@property_set',
60
- PropertySet.new(descendant, property_set.properties.dup)
61
- )
62
- end
63
-
64
- def property_names
65
- self.class.property_set.properties.map(&:name)
66
- end
67
-
68
- def self.property_names
69
- property_set.properties.map(&:name)
70
- end
71
-
72
- # Fetch all the properties and their values
73
- #
74
- # @return [Hash[Symbol]]
75
- #
76
- # @api public
77
- def fetch(value = nil)
78
- if value
79
- self.class.property_set[value]
80
- else
81
- self.class.property_set.to_hash
82
- end
83
- end
84
-
85
- # Provide access to properties
86
- #
87
- # @example
88
- # config.call do |config|
89
- # config.adapter = :net_http
90
- # end
91
- #
92
- # @return [self]
93
- #
94
- # @api private
95
- def call(&block)
96
- block.call(self) if block_given?
97
- self
98
- end
99
- end
100
- end
101
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'api/config'
4
- require_relative 'version'
5
-
6
- module SIBAApi
7
- # Stores the configuration
8
- class Configuration < API::Config
9
- property :follow_redirects, default: true
10
-
11
- # The value sent in the http header for 'User-Agent' if none is set
12
- property :user_agent, default: "SIBAApi API Ruby Gem #{SIBAApi::VERSION}"
13
-
14
- # By default uses the Faraday connection options if none is set
15
- property :connection_options, default: {}
16
-
17
- # Add Faraday::RackBuilder to overwrite middleware
18
- property :stack
19
-
20
- # WSDL to use for SIBA API
21
- property :wsdl, default: 'https://siba.sef.pt/bawsdev/boletinsalojamento.asmx?wsdl'
22
-
23
- # Hotel unit
24
- property :hotel_unit, default: '121212121'
25
-
26
- # API Key
27
- property :access_key, default: '999999999'
28
-
29
- # Establishment to use
30
- property :establishment, default: '00'
31
-
32
- # Hotel Unit complete information
33
- property :hotel_unit_info, default: {
34
- 'Codigo_Unidade_Hoteleira' => '121212121',
35
- 'Estabelecimento' => '00',
36
- 'Nome' => 'Hotel teste',
37
- 'Abreviatura' => 'teste',
38
- 'Morada' => 'Rua da Alegria, 172',
39
- 'Localidade' => 'Portalegre',
40
- 'Codigo_Postal' => '1000',
41
- 'Zona_Postal' => '234',
42
- 'Telefone' => '214017744',
43
- 'Fax' => '214017766',
44
- 'Nome_Contacto' => 'Nuno teste',
45
- 'Email_Contacto' => 'teste.teste@sef.pt'
46
- }
47
- end
48
- end