def v1_api_init(self,domain = None, realm = None, consumer_key = None, consumer_secret = None): V1_API_CRED_PATH=self.env['V1_API_CRED_PATH'] f = open(V1_API_CRED_PATH, "r") creds = simplejson.loads(f.read()) f.close() ox = ox3apiclient.Client( email = creds['email'], password = creds['password'], domain = domain or urlparse(creds['api_url']).hostname, realm = realm or creds['realm'], consumer_key = consumer_key or creds['api_key'], consumer_secret = consumer_secret or creds['api_secret'], request_token_url = "%sapi/index/initiate" % creds['sso_url'], access_token_url = "%sapi/index/token" % creds['sso_url'], authorization_url = "%slogin/process" % creds['sso_url'] ) ox.logon(creds['email'], creds['password']) return ox
def _get_client(self, get_return=None, put_return=None, post_return=None, options_return=None, delete_return=None): ex_resp = self._build_mock_response() with patch('ox3apiclient.requests.Session') as mock_requests_session: with patch('ox3apiclient.Client.log_request') as mock_client_log_request: mock_requests_session.return_value.get.return_value = get_return or ex_resp mock_requests_session.return_value.post.return_value = post_return or ex_resp mock_requests_session.return_value.put.return_value = put_return or ex_resp mock_requests_session.return_value.options.return_value = options_return or ex_resp mock_requests_session.return_value.delete.return_value = delete_return or ex_resp mock_client_log_request.return_value = None return ox3apiclient.Client( email=self.email, password=self.password, domain=self.domain, realm=self.realm, consumer_key=self.consumer_key, consumer_secret=self.consumer_secret, request_token_url=self.request_token_url, access_token_url=self.access_token_url, authorization_url=self.authorization_url)
def setUp(self): self.email = '*****@*****.**' self.password = '******' self.domain = 'uidomain.com' self.realm = 'uidomain_realm' self.consumer_key = '1fc5c9ae...' self.consumer_secret = '7c664d68...' self.request_token_url = 'https://ex-sso.openx.org/api/index/initiate' self.access_token_url = 'https://ex-sso.openx.org/api/index/token' self.authorization_url = 'https://ex-sso.openx.org/api/login/process' self.api_path_v1 = '/ox/3.0' self.api_path_v2 = '/ox/4.0' self.url = 'https://www.example.com' with nested( patch('ox3apiclient.requests.Session'), patch('ox3apiclient.Client.log_request') ) as (self.mock_requests_session, self.mock_client_log_request): self.mock_requests_session.return_value.get.return_value = self.ex_resp self.mock_requests_session.return_value.post.return_value = self.ex_resp self.mock_requests_session.return_value.put.return_value = self.ex_resp self.mock_requests_session.return_value.options.return_value = self.ex_resp self.mock_requests_session.return_value.delete.return_value = self.ex_resp self.mock_client_log_request.return_value = None self.client = ox3apiclient.Client( email=self.email, password=self.password, domain=self.domain, realm=self.realm, consumer_key=self.consumer_key, consumer_secret=self.consumer_secret, request_token_url=self.request_token_url, access_token_url=self.access_token_url, authorization_url=self.authorization_url)
import requests import json import my_creds # LOAD CREDS FROM 'my_creds.py' - in the Python lib dir email = my_creds.email password = my_creds.password domain = my_creds.domain realm = my_creds.realm consumer_key = my_creds.consumer_key consumer_secret = my_creds.consumer_secret ox = ox3apiclient.Client(email=email, password=password, domain=domain, realm=realm, consumer_key=consumer_key, consumer_secret=consumer_secret, api_path='/data/1.0') ox.logon(email, password) ox.logger.setLevel(logging.DEBUG) ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) ox.logger.addHandler(ch) list_dates = ['2019-12-02', '2019-12-03', '2019-12-04'] #let 's start with the first 2 dates for report_date in list_dates[0:2]: