Skip to content

Commit

Permalink
Feat: Moved some methods from blink_api to parent
Browse files Browse the repository at this point in the history
  • Loading branch information
mpedreira committed Oct 8, 2024
1 parent 43aece1 commit 85d95a3
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 125 deletions.
125 changes: 0 additions & 125 deletions app/classes/adapters/blink_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# pylint: disable=C0301
# -*- coding: utf-8 -*-
"""Module for using Blink Cameras through API"""

Expand All @@ -17,27 +16,6 @@ class BlinkAPI (Blink):
Blink (class): parent class
"""

def __init__(self, config):
"""
Init method for BlinkAPI
Args:
config (class):
This parameter includes the configuration needed for use this module.
It is defined in config_WHATEVER.py in adapters folder
Returns:
None:
"""
self.config = config
self.server = self.config.endpoints['BLINK']
self.client_id = ''
self.account_id = ''
self.token_auth = ''
self.basic_info = {}
self.basic_info['account'] = {}
self.basic_info['account']['tier'] = 'prod'

def __set_token__(self):
self.set_tier(self.config.session['TIER'])
self.set_account_id(self.config.session['ACCOUNT_ID'])
Expand All @@ -54,98 +32,6 @@ def __get_basics__(self):
self.get_client_id()
self.get_account_id()

def get_client_id(self):
"""
Taking the basic information of the blink account,
gets the client ID
Returns:
int: Returns the client_id that is the identification of
the aplication in the blink account
"""
self.client_id = self.basic_info['account']['client_id']
return self.client_id

def get_account_id(self):
"""
Taking the basic information of the blink account,
gets the account ID
Returns:
int : Returns the account_id that is the identification of
the account in the blink account
"""
self.account_id = self.basic_info['account']['account_id']
return self.account_id

def get_token_auth(self):
"""
Taking the basic information of the blink account,
gets the token auth
Returns:
str: Returns de API token for the client
"""
self.token_auth = self.basic_info['auth']['token']
return self.token_auth

def set_client_id(self, client_id):
"""
Sets the client ID
Args:
clientID (str): Once you have the client ID, you dont need to
re-login(with 2FA) again until the token expires. You can use
the one you created
Returns:
str: Returns the client_id defined
"""
self.client_id = client_id
return self.client_id

def set_token_auth(self, token_auth):
"""
Sets the token auth
Args:
token_auth (str): Once you have the token_auth, you dont need to
re-login(with 2FA) again until the token expires. You can use
the one you created
Returns:
str: Returns the token_auth defined
"""
self.token_auth = token_auth
return self.token_auth

def set_account_id(self, account_id):
"""
Sets the account ID
Args:
accountID (str): Once you have the account ID, you dont need to
re-login(with 2FA) again until the token expires. You can use
the one you created
Returns:
str: Returns the account_id defined
"""
self.account_id = account_id
return self.account_id

def set_tier(self, tier):
"""
Sets the tier of the account
Args:
tier (str): Tier defined in the basic information of the account
Returns:
str: Returns the tier defined
"""
self.basic_info['account']['tier'] = tier
return self.basic_info['account']['tier']

def __prepare_http_request__(self):
"""
The http requests are almost the same in this integration
Expand Down Expand Up @@ -312,17 +198,6 @@ def disarm_network(self, network_id):
http_instance.post_request()
return self.__get_response_to_request__(http_instance)

def get_server(self):
"""
Gets the server for the account
Returns:
str: returns the uri where you should do the requests
"""
tier = self.basic_info['account']['tier']
self.server = self.server.replace('prod', tier)
return self.server

def get_login(self):
"""
Login in the server
Expand Down
124 changes: 124 additions & 0 deletions app/classes/blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,127 @@

class Blink ():
""" Intending of following Hexagonal Architecture, this class is the core"""

def __init__(self, config):
"""
Init method for BlinkAPI
Args:
config (class):
This parameter includes the configuration needed for use this module.
It is defined in config_WHATEVER.py in adapters folder
Returns:
None:
"""
self.config = config
self.server = self.config.endpoints['BLINK']
self.client_id = ''
self.account_id = ''
self.token_auth = ''
self.basic_info = {}
self.basic_info['account'] = {}
self.basic_info['account']['tier'] = 'prod'

def get_client_id(self):
"""
Taking the basic information of the blink account,
gets the client ID
Returns:
int: Returns the client_id that is the identification of
the aplication in the blink account
"""
self.client_id = self.basic_info['account']['client_id']
return self.client_id

def get_account_id(self):
"""
Taking the basic information of the blink account,
gets the account ID
Returns:
int : Returns the account_id that is the identification of
the account in the blink account
"""
self.account_id = self.basic_info['account']['account_id']
return self.account_id

def get_token_auth(self):
"""
Taking the basic information of the blink account,
gets the token auth
Returns:
str: Returns de API token for the client
"""
self.token_auth = self.basic_info['auth']['token']
return self.token_auth

def set_client_id(self, client_id):
"""
Sets the client ID
Args:
clientID (str): Once you have the client ID, you dont need to
re-login(with 2FA) again until the token expires. You can use
the one you created
Returns:
str: Returns the client_id defined
"""
self.client_id = client_id
return self.client_id

def set_token_auth(self, token_auth):
"""
Sets the token auth
Args:
token_auth (str): Once you have the token_auth, you dont need to
re-login(with 2FA) again until the token expires. You can use
the one you created
Returns:
str: Returns the token_auth defined
"""
self.token_auth = token_auth
return self.token_auth

def set_account_id(self, account_id):
"""
Sets the account ID
Args:
accountID (str): Once you have the account ID, you dont need to
re-login(with 2FA) again until the token expires. You can use
the one you created
Returns:
str: Returns the account_id defined
"""
self.account_id = account_id
return self.account_id

def set_tier(self, tier):
"""
Sets the tier of the account
Args:
tier (str): Tier defined in the basic information of the account
Returns:
str: Returns the tier defined
"""
self.basic_info['account']['tier'] = tier
return self.basic_info['account']['tier']

def get_server(self):
"""
Gets the server for the account
Returns:
str: returns the uri where you should do the requests
"""
tier = self.basic_info['account']['tier']
self.server = self.server.replace('prod', tier)
return self.server

0 comments on commit 85d95a3

Please sign in to comment.