Class: AnPostReturn::Configuration
- Inherits:
-
Object
- Object
- AnPostReturn::Configuration
- Defined in:
- lib/an_post_return/configuration.rb
Instance Attribute Summary collapse
-
#proxy_config ⇒ Object
Returns the value of attribute proxy_config.
-
#sftp_config ⇒ Object
Returns the value of attribute sftp_config.
-
#subscription_key ⇒ Object
Returns the value of attribute subscription_key.
-
#test ⇒ Object
Returns the value of attribute test.
Instance Method Summary collapse
- #api_base_url ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #proxy_configured? ⇒ Boolean
- #proxy_uri ⇒ Object
- #sftp_configured? ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
10 11 12 13 14 15 |
# File 'lib/an_post_return/configuration.rb', line 10 def initialize @test = false @proxy_config = nil @sftp_config = nil @subscription_key = nil end |
Instance Attribute Details
#proxy_config ⇒ Object
Returns the value of attribute proxy_config.
6 7 8 |
# File 'lib/an_post_return/configuration.rb', line 6 def proxy_config @proxy_config end |
#sftp_config ⇒ Object
Returns the value of attribute sftp_config.
7 8 9 |
# File 'lib/an_post_return/configuration.rb', line 7 def sftp_config @sftp_config end |
#subscription_key ⇒ Object
Returns the value of attribute subscription_key.
8 9 10 |
# File 'lib/an_post_return/configuration.rb', line 8 def subscription_key @subscription_key end |
#test ⇒ Object
Returns the value of attribute test.
5 6 7 |
# File 'lib/an_post_return/configuration.rb', line 5 def test @test end |
Instance Method Details
#api_base_url ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/an_post_return/configuration.rb', line 17 def api_base_url if test "https://apim-anpost-mailslabels-nonprod.dev-anpost.com/returnsapi-q/v2" else "https://apim-anpost-mailslabels.anpost.com/returnsapi/v2" end end |
#proxy_configured? ⇒ Boolean
25 26 27 |
# File 'lib/an_post_return/configuration.rb', line 25 def proxy_configured? !proxy_config.nil? end |
#proxy_uri ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/an_post_return/configuration.rb', line 29 def proxy_uri return nil unless proxy_configured? user = proxy_config[:user] password = proxy_config[:password] host = proxy_config[:host] port = proxy_config[:port] uri_string = "http://#{host}:#{port}" if user && password encoded_user = URI.encode_www_form_component(user) encoded_password = URI.encode_www_form_component(password) uri_string = "http://#{encoded_user}:#{encoded_password}@#{host}:#{port}" end URI.parse(uri_string) end |
#sftp_configured? ⇒ Boolean
47 48 49 50 51 52 |
# File 'lib/an_post_return/configuration.rb', line 47 def sftp_configured? return false if sftp_config.nil? required_keys = %i[host username password remote_path] required_keys.all? { |key| sftp_config.key?(key) && !sftp_config[key].nil? } end |