Class: Barion::Config
- Inherits:
-
Object
- Object
- Barion::Config
- Includes:
- Singleton
- Defined in:
- lib/barion/config.rb
Overview
Encloses all Barion related configuration
Instance Attribute Summary collapse
-
#acronym ⇒ String
The acronym set up in the initalizer.
-
#default_payee ⇒ String?
Set this to the registered email address of your shop.
-
#pixel_id ⇒ Object
Returns the value of attribute pixel_id.
- #poskey ⇒ Object
-
#publickey ⇒ String?
Set this to the string provided by Barion registration.
Instance Method Summary collapse
-
#endpoint ⇒ Object
Returns the REST client endpoint based on the current environment.
-
#item_class ⇒ Class
Returns the item class set in the initializer.
-
#item_class=(class_name) ⇒ Object
Sets the class used for item representation.
-
#reset ⇒ Object
Resets all configuration options to
nil. -
#rest_client_class ⇒ Class
Returns the class used for making REST calls to the Barion API.
-
#rest_client_class=(class_name) ⇒ Object
Sets the class used for making REST calls to the Barion API.
-
#sandbox ⇒ Boolean
Returns the current sandbox mode setting.
-
#sandbox=(val) ⇒ Object
Sets the sandbox mode.
-
#sandbox? ⇒ Boolean
Returns the current sandbox mode setting.
-
#user_class ⇒ Class
Returns the user class set in the initializer.
-
#user_class=(class_name) ⇒ Object
Sets the user class used for user authentication.
Instance Attribute Details
#acronym ⇒ String
The acronym set up in the initalizer
36 37 38 |
# File 'lib/barion/config.rb', line 36 def acronym @acronym || '' end |
#default_payee ⇒ String?
Set this to the registered email address of your shop
17 18 19 |
# File 'lib/barion/config.rb', line 17 def default_payee @default_payee end |
#pixel_id ⇒ Object
Returns the value of attribute pixel_id.
25 26 27 |
# File 'lib/barion/config.rb', line 25 def pixel_id @pixel_id end |
#poskey ⇒ Object
30 31 32 |
# File 'lib/barion/config.rb', line 30 def poskey @_poskey || nil end |
#publickey ⇒ String?
Set this to the string provided by Barion registration
13 14 15 |
# File 'lib/barion/config.rb', line 13 def publickey @publickey end |
Instance Method Details
#endpoint ⇒ Object
Returns the REST client endpoint based on the current environment.
Determines the environment by checking if the sandbox mode is enabled. If sandbox mode is enabled, the test environment URL is used; otherwise, the production environment URL is used.
109 110 111 112 |
# File 'lib/barion/config.rb', line 109 def endpoint env = sandbox? ? :test : :prod rest_client_class.new ::Barion::BASE_URL[env] end |
#item_class ⇒ Class
Returns the item class set in the initializer.
This method returns nil until the initializer is installed.
154 155 156 157 158 159 |
# File 'lib/barion/config.rb', line 154 def item_class # This is nil before the initializer is installed. return nil if @_item_class.nil? @_item_class.constantize end |
#item_class=(class_name) ⇒ Object
Sets the class used for item representation.
141 142 143 144 145 146 147 |
# File 'lib/barion/config.rb', line 141 def item_class=(class_name) unless class_name.is_a?(String) raise ArgumentError, "::Barion.config.item_class must be set to a ::String, got #{class_name.inspect}" end @_item_class = class_name end |
#reset ⇒ Object
Resets all configuration options to nil.
It is useful when you want to restore the default configuration as the class is a Singleton.
188 189 190 191 192 193 194 195 196 197 |
# File 'lib/barion/config.rb', line 188 def reset @_poskey = nil @_sandbox = nil @_user_class = nil @_item_class = nil @_rest_client_class = nil @acronym = nil @pixel_id = nil @publickey = nil end |
#rest_client_class ⇒ Class
Returns the class used for making REST calls to the Barion API.
If it was not set explicitly, it defaults to ‘::RestClient::Resource`.
166 167 168 |
# File 'lib/barion/config.rb', line 166 def rest_client_class (@_rest_client_class || '::RestClient::Resource').constantize end |
#rest_client_class=(class_name) ⇒ Object
Sets the class used for making REST calls to the Barion API.
The class set with this method is used for making REST calls to the Barion API. It should be set to a class that responds to the same methods as ‘::RestClient::Resource`.
177 178 179 180 181 182 183 |
# File 'lib/barion/config.rb', line 177 def rest_client_class=(class_name) unless class_name.is_a?(String) raise ArgumentError, "::Barion::Config.rest_client_class must be set to a ::String, got #{class_name.inspect}" end @_rest_client_class = class_name end |
#sandbox ⇒ Boolean
Returns the current sandbox mode setting. Delegates to the sandbox? method to determine the current state.
57 58 59 |
# File 'lib/barion/config.rb', line 57 def sandbox sandbox? end |
#sandbox=(val) ⇒ Object
Sets the sandbox mode.
75 76 77 |
# File 'lib/barion/config.rb', line 75 def sandbox=(val) @_sandbox = !!val end |
#sandbox? ⇒ Boolean
Returns the current sandbox mode setting.
If the sandbox mode was not set explicitly, it defaults to true.
66 67 68 69 |
# File 'lib/barion/config.rb', line 66 def sandbox? @_sandbox = true if @_sandbox.nil? @_sandbox end |
#user_class ⇒ Class
Returns the user class set in the initializer.
131 132 133 134 135 136 |
# File 'lib/barion/config.rb', line 131 def user_class # This is nil before the initializer is installed. return nil if @_user_class.nil? @_user_class.constantize end |
#user_class=(class_name) ⇒ Object
Sets the user class used for user authentication.
Validates that the provided user class is a string.
120 121 122 123 124 125 126 |
# File 'lib/barion/config.rb', line 120 def user_class=(class_name) unless class_name.is_a?(String) raise ArgumentError, "::Barion:.config.user_class must be set to a ::String, got #{class_name.inspect}" end @_user_class = class_name end |