Class: Locomotive::Mounter::EngineApi
- Inherits:
-
Object
- Object
- Locomotive::Mounter::EngineApi
- Includes:
- HTTMultiParty
- Defined in:
- lib/locomotive/mounter/engine_api.rb
Class Method Summary collapse
-
.set_token(*args) ⇒ String
Get a new token from the Engine API and set it for this class.
- .teardown ⇒ Object
Class Method Details
.set_token(*args) ⇒ String
Get a new token from the Engine API and set it for this class. It raises an exception if the operation fails. Example of the base uri: locomotivecms.com, nocoffee.fr.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/locomotive/mounter/engine_api.rb', line 20 def self.set_token(*args) _credentials = self.credentials(args) uri = URI _credentials.delete(:uri) self.base_uri uri.to_s self.basic_auth uri.user, uri.password if uri.userinfo response = post('/tokens.json', body: _credentials) #{ email: email, password: password }) if response.code < 400 self.default_params auth_token: response['token'] response['token'] else raise WrongCredentials.new("#{response['message']} (#{response.code})") end end |
.teardown ⇒ Object
37 38 39 40 41 |
# File 'lib/locomotive/mounter/engine_api.rb', line 37 def self.teardown Locomotive::Mounter::EngineApi.[:base_uri] = nil Locomotive::Mounter::EngineApi.[:base_auth] = nil Locomotive::Mounter::EngineApi.[:default_params] = {} end |