siba_api 0.1.1 → 0.1.3

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: 0407b762bb94232363d947d76afaead1441da284c7b7e1aab71a8d9cb4322604
4
- data.tar.gz: ca5290b3e621ada85990432ccb2544ee5d2548a9369e4e0d1ddf1368ccb89603
3
+ metadata.gz: b8d53139f0b7019f8f461bf5e10bbf72ee8f1bb4ab848682acff014a21a75a36
4
+ data.tar.gz: 5735aab02771c80e56e392099c1aa770640b65c565f9cced69359c609b288ebb
5
5
  SHA512:
6
- metadata.gz: 551cb36918ce40eaf0f8cfa53cd1c874049f3ce68115f051366d2ad667ec73df669457eff3900f696b9fad2deaaae3b8deab5a4ac744313ec31ca0305ed549c6
7
- data.tar.gz: a6d141af352dfc63ca5b73955ff68746244387581a807262e0736b535762505aba82efb4cb9637e1d4b97406645396f8074f11efc18dfdff99606d1a226fbac9
6
+ metadata.gz: b27c3f86f69d3a8ea0dddd7e95ff784129d7d17ac5f4e89811cf31693143fe00c13b5ab859beca477249ecd8e82d57e657a1fb7a73d6498fe6a53d7f8f5820e2
7
+ data.tar.gz: 358d01d1732f0b91c30c664c27f264bcc9d572512723344a71a38f6d09c02548711f590fe6dd357d96f0aa049b5ae77aa04f208d1221306507f84e68260cca2d
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/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,18 +76,20 @@ 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
83
+ globals.ssl_verify_mode :none # NOTE: As of 2024.07.15 ssl validation is failing
84
+ # TEST: openssl s_client -showcerts -verify 5 -connect siba.sef.pt:443 < /dev/null
70
85
  end
71
86
  end
72
87
 
73
88
  def request(operation:, params: {})
74
89
  default_params = {
75
- UnidadeHoteleira: @current_options[:hotel_unit],
76
- Estabelecimento: @current_options[:establishment],
77
- ChaveAcesso: @current_options[:access_key]
90
+ UnidadeHoteleira: config.hotel_unit,
91
+ Estabelecimento: config.establishment,
92
+ ChaveAcesso: config.access_key
78
93
  }
79
94
 
80
95
  response = client.call(operation.to_sym, message: default_params.merge(params))
@@ -112,24 +127,5 @@ module SIBAApi
112
127
  def response_successful?(response)
113
128
  response.successful? and (response.http.code == HTTP_OK_CODE)
114
129
  end
115
-
116
- # Responds to attribute query or attribute clear
117
- #
118
- # @api private
119
- def method_missing(method_name, *args, &block)
120
- # :nodoc:
121
- case method_name.to_s
122
- when /^(.*)\?$/
123
- !send(Regexp.last_match(1).to_s).nil?
124
- when /^clear_(.*)$/
125
- send("#{Regexp.last_match(1)}=", nil)
126
- else
127
- super
128
- end
129
- end
130
-
131
- def respond_to_missing?(method_name, include_private = false)
132
- method_name.to_s.start_with?('clear_') || super
133
- end
134
130
  end
135
131
  end
@@ -86,7 +86,7 @@ module SIBAApi
86
86
  # <Email_Contacto>teste.teste@sef.pt</Email_Contacto>
87
87
  # </Unidade_Hoteleira>
88
88
  def build_hotel_unit
89
- @hotel_unit_info
89
+ config.hotel_unit_info
90
90
  end
91
91
 
92
92
  # <Numero_Ficheiro>97</Numero_Ficheiro>
@@ -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.1'
4
+ VERSION = '0.1.3'
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.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dinis
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-27 00:00:00.000000000 Z
11
+ date: 2024-07-15 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
@@ -84,7 +94,7 @@ metadata:
84
94
  homepage_uri: https://github.com/dlage/siba_api
85
95
  source_code_uri: https://github.com/dlage/siba_api
86
96
  changelog_uri: https://github.com/dlage/siba_api/blob/master/CHANGELOG.md
87
- post_install_message:
97
+ post_install_message:
88
98
  rdoc_options: []
89
99
  require_paths:
90
100
  - lib
@@ -99,8 +109,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
109
  - !ruby/object:Gem::Version
100
110
  version: '0'
101
111
  requirements: []
102
- rubygems_version: 3.2.33
103
- signing_key:
112
+ rubygems_version: 3.3.7
113
+ signing_key:
104
114
  specification_version: 4
105
115
  summary: SEF SIBA API Wrapper for Local Accommodation Bulletin submission.
106
116
  test_files: []
@@ -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