def image_watermark(self, image_url, watermark_url, format=None, height=None, opacity=None, position=None, width=None): """Does a POST request to /image-watermark. Watermark one image with another image. See: https://www.neutrinoapi.com/api/image-watermark/ Args: image_url (string): The URL to the source image watermark_url (string): The URL to the watermark image format (string, optional): The output image format, can be either png or jpg height (int, optional): If set resize the resulting image to this height (preserving aspect ratio) opacity (int, optional): The opacity of the watermark (0 to 100) position (string, optional): The position of the watermark image, possible values are: center, top-left, top-center, top-right, bottom-left, bottom-center, bottom-right width (int, optional): If set resize the resulting image to this width (preserving aspect ratio) Returns: binary: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # The base uri for api requests query_builder = Configuration.BASE_URI # Prepare query string for API call query_builder += "/image-watermark" # Process optional query parameters query_parameters = { "user-id": self.__user_id, "api-key": self.__api_key } query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters) # Validate and preprocess url query_url = APIHelper.clean_url(query_builder) # Prepare headers headers = { "user-agent": "APIMATIC 2.0" } # Prepare parameters parameters = { "image-url": image_url, "watermark-url": watermark_url, "format": format if format is not None else "png", "height": height, "opacity": opacity if opacity is not None else 50, "position": position if position is not None else "center", "width": width } # The body will be multipart data, so set the header headers['Content-Type'] = 'multipart/form-data' # Prepare and invoke the API call request to fetch the response response = unirest.post(query_url, headers=headers, params=parameters) # Error handling using HTTP status codes if response.code < 200 or response.code > 206: # 200 = HTTP OK raise APIException("HTTP Response Not OK", response.code, response.body) return response.body
def html_to_pdf(self, content, html_width=None, margin=None, title=None): """Does a POST request to /html-to-pdf. Convert HTML content into PDF documents. See: https://www.neutrinoapi.com/api/html-to-pdf/ Args: content (string): The HTML content. This can be either a URL to load HTML from or an actual HTML content string html_width (int, optional): The width (in px) to render the HTML document at margin (int, optional): The PDF document margin (in mm) title (string, optional): The PDF document title Returns: binary: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # The base uri for api requests query_builder = Configuration.BASE_URI # Prepare query string for API call query_builder += "/html-to-pdf" # Process optional query parameters query_parameters = { "user-id": self.__user_id, "api-key": self.__api_key } query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters) # Validate and preprocess url query_url = APIHelper.clean_url(query_builder) # Prepare headers headers = { "user-agent": "APIMATIC 2.0" } # Prepare parameters parameters = { "content": content, "html-width": html_width if html_width is not None else 1024, "margin": margin if margin is not None else 10, "title": title } # The body will be multipart data, so set the header headers['Content-Type'] = 'multipart/form-data' # Prepare and invoke the API call request to fetch the response response = unirest.post(query_url, headers=headers, params=parameters) # Error handling using HTTP status codes if response.code < 200 or response.code > 206: # 200 = HTTP OK raise APIException("HTTP Response Not OK", response.code, response.body) return response.body
def image_resize(self, height, image_url, width, format=None): """Does a POST request to /image-resize. Resize an image and output as either JPEG or PNG. See: https://www.neutrinoapi.com/api/image-resize/ Args: height (int): Height to resize to (in px) image_url (string): The URL to the source image width (int): Width to resize to (in px) format (string, optional): The output image format, can be either png or jpg Returns: binary: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # The base uri for api requests query_builder = Configuration.BASE_URI # Prepare query string for API call query_builder += "/image-resize" # Process optional query parameters query_parameters = { "user-id": self.__user_id, "api-key": self.__api_key } query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters) # Validate and preprocess url query_url = APIHelper.clean_url(query_builder) # Prepare headers headers = { "user-agent": "APIMATIC 2.0" } # Prepare parameters parameters = { "height": height, "image-url": image_url, "width": width, "format": format if format is not None else "png" } # The body will be multipart data, so set the header headers['Content-Type'] = 'multipart/form-data' # Prepare and invoke the API call request to fetch the response response = unirest.post(query_url, headers=headers, params=parameters) # Error handling using HTTP status codes if response.code < 200 or response.code > 206: # 200 = HTTP OK raise APIException("HTTP Response Not OK", response.code, response.body) return response.body
def ip_blocklist(self, ip): """Does a POST request to /ip-blocklist. The IP Blocklist API will detect potentially malicious or dangerous IP addresses. See: https://www.neutrinoapi.com/api/ip-blocklist/ Args: ip (string): An IPv4 address Returns: IPBlocklistResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # The base uri for api requests query_builder = Configuration.BASE_URI # Prepare query string for API call query_builder += "/ip-blocklist" # Process optional query parameters query_parameters = { "user-id": self.__user_id, "api-key": self.__api_key } query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters) # Validate and preprocess url query_url = APIHelper.clean_url(query_builder) # Prepare headers headers = { "user-agent": "APIMATIC 2.0", "accept": "application/json" } # Prepare parameters parameters = { "ip": ip, "output-case": output_case } # The body will be multipart data, so set the header headers['Content-Type'] = 'multipart/form-data' # Prepare and invoke the API call request to fetch the response response = unirest.post(query_url, headers=headers, params=parameters) # Error handling using HTTP status codes if response.code < 200 or response.code > 206: # 200 = HTTP OK raise APIException("HTTP Response Not OK", response.code, response.body) # Try to cast response to desired type if isinstance(response.body, dict): # Response is already in a dictionary, return the object return IPBlocklistResponse(**response.body) # If we got here then an error occured while trying to parse the response raise APIException("Invalid JSON returned", response.code, response.body)
def url_info(self, fetch_content, url): """Does a POST request to /url-info. Parse, analyze and retrieve content from the supplied URL. See: https://www.neutrinoapi.com/api/url-info/ Args: fetch_content (bool): If this URL responds with html, text, json or xml then return the response. This option is useful if you want to perform further processing on the URL content url (string): The URL to process Returns: URLInfoResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # The base uri for api requests query_builder = Configuration.BASE_URI # Prepare query string for API call query_builder += "/url-info" # Process optional query parameters query_parameters = { "user-id": self.__user_id, "api-key": self.__api_key } query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters) # Validate and preprocess url query_url = APIHelper.clean_url(query_builder) # Prepare headers headers = { "user-agent": "APIMATIC 2.0", "accept": "application/json" } # Prepare parameters parameters = { "fetch-content": fetch_content, "output-case": output_case, "url": url } # The body will be multipart data, so set the header headers['Content-Type'] = 'multipart/form-data' # Prepare and invoke the API call request to fetch the response response = unirest.post(query_url, headers=headers, params=parameters) # Error handling using HTTP status codes if response.code < 200 or response.code > 206: # 200 = HTTP OK raise APIException("HTTP Response Not OK", response.code, response.body) # Try to cast response to desired type if isinstance(response.body, dict): # Response is already in a dictionary, return the object return URLInfoResponse(**response.body) # If we got here then an error occured while trying to parse the response raise APIException("Invalid JSON returned", response.code, response.body)
def bad_word_filter(self, content, censor_character=None): """Does a POST request to /bad-word-filter. Detect bad words, swear words and profanity in a given text. See: https://www.neutrinoapi.com/api/bad-word-filter/ Args: content (string): The text content to check. This can be either a URL to load content from or an actual content string censor_character (string, optional): The character to use to censor out the bad words found Returns: BadWordFilterResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # The base uri for api requests query_builder = Configuration.BASE_URI # Prepare query string for API call query_builder += "/bad-word-filter" # Process optional query parameters query_parameters = { "user-id": self.__user_id, "api-key": self.__api_key } query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters) # Validate and preprocess url query_url = APIHelper.clean_url(query_builder) # Prepare headers headers = { "user-agent": "APIMATIC 2.0", "accept": "application/json" } # Prepare parameters parameters = { "content": content, "output-case": output_case, "censor-character": censor_character } # The body will be multipart data, so set the header headers['Content-Type'] = 'multipart/form-data' # Prepare and invoke the API call request to fetch the response response = unirest.post(query_url, headers=headers, params=parameters) # Error handling using HTTP status codes if response.code < 200 or response.code > 206: # 200 = HTTP OK raise APIException("HTTP Response Not OK", response.code, response.body) # Try to cast response to desired type if isinstance(response.body, dict): # Response is already in a dictionary, return the object return BadWordFilterResponse(**response.body) # If we got here then an error occured while trying to parse the response raise APIException("Invalid JSON returned", response.code, response.body)
def ip_info(self, ip, reverse_lookup=None): """Does a POST request to /ip-info. Get location information about an IP address and do reverse DNS (PTR) lookups. See: https://www.neutrinoapi.com/api/ip-info/ Args: ip (string): The IP address reverse_lookup (bool, optional): Do reverse DNS (PTR) lookup. This option can add extra delay to the request so only use it if you need it Returns: IPInfoResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # The base uri for api requests query_builder = Configuration.BASE_URI # Prepare query string for API call query_builder += "/ip-info" # Process optional query parameters query_parameters = { "user-id": self.__user_id, "api-key": self.__api_key } query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters) # Validate and preprocess url query_url = APIHelper.clean_url(query_builder) # Prepare headers headers = { "user-agent": "APIMATIC 2.0", "accept": "application/json" } # Prepare parameters parameters = { "ip": ip, "output-case": output_case, "reverse-lookup": reverse_lookup if reverse_lookup is not None else False } # The body will be multipart data, so set the header headers['Content-Type'] = 'multipart/form-data' # Prepare and invoke the API call request to fetch the response response = unirest.post(query_url, headers=headers, params=parameters) # Error handling using HTTP status codes if response.code < 200 or response.code > 206: # 200 = HTTP OK raise APIException("HTTP Response Not OK", response.code, response.body) # Try to cast response to desired type if isinstance(response.body, dict): # Response is already in a dictionary, return the object return IPInfoResponse(**response.body) # If we got here then an error occured while trying to parse the response raise APIException("Invalid JSON returned", response.code, response.body)
def phone_playback(self, audio_url, number): """Does a POST request to /phone-playback. Make an automated call to any valid phone number and playback an audio message. See: https://www.neutrinoapi.com/api/phone-playback/ Args: audio_url (string): A URL to a valid audio file. Accepted audio formats are: MP3, WAV, OGG number (string): The phone number to call. Must be valid international format Returns: PhonePlaybackResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # The base uri for api requests query_builder = Configuration.BASE_URI # Prepare query string for API call query_builder += "/phone-playback" # Process optional query parameters query_parameters = { "user-id": self.__user_id, "api-key": self.__api_key } query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters) # Validate and preprocess url query_url = APIHelper.clean_url(query_builder) # Prepare headers headers = { "user-agent": "APIMATIC 2.0", "accept": "application/json" } # Prepare parameters parameters = { "audio-url": audio_url, "number": number, "output-case": output_case } # The body will be multipart data, so set the header headers['Content-Type'] = 'multipart/form-data' # Prepare and invoke the API call request to fetch the response response = unirest.post(query_url, headers=headers, params=parameters) # Error handling using HTTP status codes if response.code < 200 or response.code > 206: # 200 = HTTP OK raise APIException("HTTP Response Not OK", response.code, response.body) # Try to cast response to desired type if isinstance(response.body, dict): # Response is already in a dictionary, return the object return PhonePlaybackResponse(**response.body) # If we got here then an error occured while trying to parse the response raise APIException("Invalid JSON returned", response.code, response.body)
def sms_verify(self, number, code_length=None, country_code=None, language_code=None, security_code=None): """Does a POST request to /sms-verify. Send a unique security code to any mobile device via SMS. See: https://www.neutrinoapi.com/api/sms-verify/ Args: number (string): The phone number to send a verification code to code_length (int, optional): The number of digits to use in the security code (must be between 4 and 12) country_code (string, optional): ISO 2-letter country code, assume numbers are based in this country. If not set numbers are assumed to be in international format (with or without the leading + sign) language_code (string, optional): The language to send the verification code in, available languages are: de - German, en - English, es - Spanish, fr - Fench, it - Italian, pt - Portuguese, ru - Russian security_code (int, optional): ass in your own security code. This is useful if you have implemented TOTP or similar 2FA methods. If not set then we will generate a secure random code (only numerical security codes are currently supported) Returns: SMSVerifyResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # The base uri for api requests query_builder = Configuration.BASE_URI # Prepare query string for API call query_builder += "/sms-verify" # Process optional query parameters query_parameters = { "user-id": self.__user_id, "api-key": self.__api_key } query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters) # Validate and preprocess url query_url = APIHelper.clean_url(query_builder) # Prepare headers headers = { "user-agent": "APIMATIC 2.0", "accept": "application/json" } # Prepare parameters parameters = { "number": number, "output-case": output_case, "code-length": code_length if code_length is not None else 5, "country-code": country_code, "language-code": language_code if language_code is not None else "en", "security-code": security_code } # The body will be multipart data, so set the header headers['Content-Type'] = 'multipart/form-data' # Prepare and invoke the API call request to fetch the response response = unirest.post(query_url, headers=headers, params=parameters) # Error handling using HTTP status codes if response.code < 200 or response.code > 206: # 200 = HTTP OK raise APIException("HTTP Response Not OK", response.code, response.body) # Try to cast response to desired type if isinstance(response.body, dict): # Response is already in a dictionary, return the object return SMSVerifyResponse(**response.body) # If we got here then an error occured while trying to parse the response raise APIException("Invalid JSON returned", response.code, response.body)
def verify_security_code(self, security_code): """Does a POST request to /verify-security-code. Check if a security code from one of the verify APIs is valid. See: https://www.neutrinoapi.com/api/verify-security-code/ Args: security_code (int): The security code to verify Returns: VerifySecurityCodeResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # The base uri for api requests query_builder = Configuration.BASE_URI # Prepare query string for API call query_builder += "/verify-security-code" # Process optional query parameters query_parameters = { "user-id": self.__user_id, "api-key": self.__api_key } query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters) # Validate and preprocess url query_url = APIHelper.clean_url(query_builder) # Prepare headers headers = { "user-agent": "APIMATIC 2.0", "accept": "application/json" } # Prepare parameters parameters = { "output-case": output_case, "security-code": security_code } # The body will be multipart data, so set the header headers['Content-Type'] = 'multipart/form-data' # Prepare and invoke the API call request to fetch the response response = unirest.post(query_url, headers=headers, params=parameters) # Error handling using HTTP status codes if response.code < 200 or response.code > 206: # 200 = HTTP OK raise APIException("HTTP Response Not OK", response.code, response.body) # Try to cast response to desired type if isinstance(response.body, dict): # Response is already in a dictionary, return the object return VerifySecurityCodeResponse(**response.body) # If we got here then an error occured while trying to parse the response raise APIException("Invalid JSON returned", response.code, response.body)
def hlr_lookup(self, number, country_code=None): """Does a POST request to /hlr-lookup. Mobile network HLR lookup service. See: https://www.neutrinoapi.com/api/hlr-lookup/ Args: number (string): A phone number country_code (string, optional): ISO 2-letter country code, assume numbers are based in this country. If not set numbers are assumed to be in international format (with or without the leading + sign) Returns: HLRLookupResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # The base uri for api requests query_builder = Configuration.BASE_URI # Prepare query string for API call query_builder += "/hlr-lookup" # Process optional query parameters query_parameters = { "user-id": self.__user_id, "api-key": self.__api_key } query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters) # Validate and preprocess url query_url = APIHelper.clean_url(query_builder) # Prepare headers headers = { "user-agent": "APIMATIC 2.0", "accept": "application/json" } # Prepare parameters parameters = { "number": number, "output-case": output_case, "country-code": country_code } # The body will be multipart data, so set the header headers['Content-Type'] = 'multipart/form-data' # Prepare and invoke the API call request to fetch the response response = unirest.post(query_url, headers=headers, params=parameters) # Error handling using HTTP status codes if response.code < 200 or response.code > 206: # 200 = HTTP OK raise APIException("HTTP Response Not OK", response.code, response.body) # Try to cast response to desired type if isinstance(response.body, dict): # Response is already in a dictionary, return the object return HLRLookupResponse(**response.body) # If we got here then an error occured while trying to parse the response raise APIException("Invalid JSON returned", response.code, response.body)
def html_extract(self, content, tag, attribute=None, base_url=None): """Does a POST request to /html-extract-tags. Extract HTML tag contents or attributes from complex HTML or XHTML content. See: https://www.neutrinoapi.com/api/html-extract-tags/ Args: content (string): The HTML content. This can be either a URL to load HTML from or an actual HTML content string tag (string): The HTML tag(s) to extract data from. This can just be a simple tag name like 'img' OR a CSS/jQuery style selector attribute (string, optional): If set, then extract data from the specified tag attribute. If not set, then data will be extracted from the tags inner content base_url (string, optional): The base URL to replace into realive links Returns: HTMLExtractResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # The base uri for api requests query_builder = Configuration.BASE_URI # Prepare query string for API call query_builder += "/html-extract-tags" # Process optional query parameters query_parameters = { "user-id": self.__user_id, "api-key": self.__api_key } query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters) # Validate and preprocess url query_url = APIHelper.clean_url(query_builder) # Prepare headers headers = { "user-agent": "APIMATIC 2.0", "accept": "application/json" } # Prepare parameters parameters = { "content": content, "output-case": output_case, "tag": tag, "attribute": attribute, "base-url": base_url } # The body will be multipart data, so set the header headers['Content-Type'] = 'multipart/form-data' # Prepare and invoke the API call request to fetch the response response = unirest.post(query_url, headers=headers, params=parameters) # Error handling using HTTP status codes if response.code < 200 or response.code > 206: # 200 = HTTP OK raise APIException("HTTP Response Not OK", response.code, response.body) # Try to cast response to desired type if isinstance(response.body, dict): # Response is already in a dictionary, return the object return HTMLExtractResponse(**response.body) # If we got here then an error occured while trying to parse the response raise APIException("Invalid JSON returned", response.code, response.body)
def html_clean(self, content, output_type): """Does a POST request to /html-clean. Clean and sanitize untrusted HTML. See: https://www.neutrinoapi.com/api/html-clean/ Args: content (string): The HTML content. This can be either a URL to load HTML from or an actual HTML content string output_type (string): The level of sanitization, possible values are: plain-text, simple-text, basic-html, basic-html-with-images, advanced-html Returns: binary: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # The base uri for api requests query_builder = Configuration.BASE_URI # Prepare query string for API call query_builder += "/html-clean" # Process optional query parameters query_parameters = { "user-id": self.__user_id, "api-key": self.__api_key } query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters) # Validate and preprocess url query_url = APIHelper.clean_url(query_builder) # Prepare headers headers = { "user-agent": "APIMATIC 2.0" } # Prepare parameters parameters = { "content": content, "output-type": output_type } # The body will be multipart data, so set the header headers['Content-Type'] = 'multipart/form-data' # Prepare and invoke the API call request to fetch the response response = unirest.post(query_url, headers=headers, params=parameters) # Error handling using HTTP status codes if response.code < 200 or response.code > 206: # 200 = HTTP OK raise APIException("HTTP Response Not OK", response.code, response.body) return response.body
def email_validate(self, email, fix_typos=None): """Does a POST request to /email-validate. Parse, validate and clean an email address. See: https://www.neutrinoapi.com/api/email-validate/ Args: email (string): The email address fix_typos (bool, optional): Automatically attempt to fix typos in the address Returns: EmailValidateResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # The base uri for api requests query_builder = Configuration.BASE_URI # Prepare query string for API call query_builder += "/email-validate" # Process optional query parameters query_parameters = { "user-id": self.__user_id, "api-key": self.__api_key } query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters) # Validate and preprocess url query_url = APIHelper.clean_url(query_builder) # Prepare headers headers = { "user-agent": "APIMATIC 2.0", "accept": "application/json" } # Prepare parameters parameters = { "email": email, "output-case": output_case, "fix-typos": fix_typos if fix_typos is not None else False } # The body will be multipart data, so set the header headers['Content-Type'] = 'multipart/form-data' # Prepare and invoke the API call request to fetch the response response = unirest.post(query_url, headers=headers, params=parameters) # Error handling using HTTP status codes if response.code < 200 or response.code > 206: # 200 = HTTP OK raise APIException("HTTP Response Not OK", response.code, response.body) # Try to cast response to desired type if isinstance(response.body, dict): # Response is already in a dictionary, return the object return EmailValidateResponse(**response.body) # If we got here then an error occured while trying to parse the response raise APIException("Invalid JSON returned", response.code, response.body)
def qr_code(self, content, bg_color=None, fg_color=None, height=None, width=None): """Does a POST request to /qr-code. Generate a QR code as a PNG image. See: https://www.neutrinoapi.com/api/qr-code/ Args: content (string): The content to encode into the QR code (e.g. a URL or a phone number) bg_color (string, optional): The QR code background color (you should always use a light color for this) fg_color (string, optional): The QR code foreground color (you should always use a dark color for this) height (int, optional): The height of the QR code (in px) width (int, optional): The width of the QR code (in px) Returns: binary: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # The base uri for api requests query_builder = Configuration.BASE_URI # Prepare query string for API call query_builder += "/qr-code" # Process optional query parameters query_parameters = { "width": width if width is not None else 250, "user-id": self.__user_id, "api-key": self.__api_key } query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters) # Validate and preprocess url query_url = APIHelper.clean_url(query_builder) # Prepare headers headers = { "user-agent": "APIMATIC 2.0" } # Prepare parameters parameters = { "content": content, "bg-color": bg_color if bg_color is not None else "#ffffff", "fg-color": fg_color if fg_color is not None else "#000000", "height": height if height is not None else 250 } # The body will be multipart data, so set the header headers['Content-Type'] = 'multipart/form-data' # Prepare and invoke the API call request to fetch the response response = unirest.post(query_url, headers=headers, params=parameters) # Error handling using HTTP status codes if response.code < 200 or response.code > 206: # 200 = HTTP OK raise APIException("HTTP Response Not OK", response.code, response.body) return response.body
def geocode_reverse(self, latitude, longitude, language_code=None): """Does a POST request to /geocode-reverse. Reverse geocoding is the process of taking a coordinate (latitude and longitude) and mapping this to a real world address or location. See: https://www.neutrinoapi.com/api/geocode-reverse/ Args: latitude (double): The location latitude longitude (double): The location longitude language_code (string, optional): The language to display results in Returns: GeocodeReverseResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # The base uri for api requests query_builder = Configuration.BASE_URI # Prepare query string for API call query_builder += "/geocode-reverse" # Process optional query parameters query_parameters = { "user-id": self.__user_id, "api-key": self.__api_key } query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters) # Validate and preprocess url query_url = APIHelper.clean_url(query_builder) # Prepare headers headers = { "user-agent": "APIMATIC 2.0", "accept": "application/json" } # Prepare parameters parameters = { "latitude": latitude, "longitude": longitude, "output-case": output_case, "language-code": language_code if language_code is not None else "en" } # The body will be multipart data, so set the header headers['Content-Type'] = 'multipart/form-data' # Prepare and invoke the API call request to fetch the response response = unirest.post(query_url, headers=headers, params=parameters) # Error handling using HTTP status codes if response.code < 200 or response.code > 206: # 200 = HTTP OK raise APIException("HTTP Response Not OK", response.code, response.body) # Try to cast response to desired type if isinstance(response.body, dict): # Response is already in a dictionary, return the object return GeocodeReverseResponse(**response.body) # If we got here then an error occured while trying to parse the response raise APIException("Invalid JSON returned", response.code, response.body)
def bin_lookup(self, bin_number, customer_ip=None): """Does a POST request to /bin-lookup. Perform a BIN (Bank Identification Number) or IIN (Issuer Identification Number) lookup. See: https://www.neutrinoapi.com/api/bin-lookup/ Args: bin_number (string): The BIN or IIN number (the first 6 digits of a credit card number) customer_ip (string, optional): Pass in a customers remote IP address. The API will then determine the country of the IP address and match it against the BIN country. This feature is designed for fraud prevention and detection checks. Returns: BINLookupResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # The base uri for api requests query_builder = Configuration.BASE_URI # Prepare query string for API call query_builder += "/bin-lookup" # Process optional query parameters query_parameters = { "user-id": self.__user_id, "api-key": self.__api_key } query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters) # Validate and preprocess url query_url = APIHelper.clean_url(query_builder) # Prepare headers headers = { "user-agent": "APIMATIC 2.0", "accept": "application/json" } # Prepare parameters parameters = { "bin-number": bin_number, "output-case": output_case, "customer-ip": customer_ip } # The body will be multipart data, so set the header headers['Content-Type'] = 'multipart/form-data' # Prepare and invoke the API call request to fetch the response response = unirest.post(query_url, headers=headers, params=parameters) # Error handling using HTTP status codes if response.code < 200 or response.code > 206: # 200 = HTTP OK raise APIException("HTTP Response Not OK", response.code, response.body) # Try to cast response to desired type if isinstance(response.body, dict): # Response is already in a dictionary, return the object return BINLookupResponse(**response.body) # If we got here then an error occured while trying to parse the response raise APIException("Invalid JSON returned", response.code, response.body)
def code_highlight(self, content, mtype, add_keyword_links=None): """Does a POST request to /code-highlight. Code highlight will take raw source code and convert into nicely formatted HTML with syntax and keyword highlighting. See: https://www.neutrinoapi.com/api/code-highlight/ Args: content (string): The source content. This can be either a URL to load from or an actual content string mtype (string): The code type. See the API docs for all supported types add_keyword_links (bool, optional): Add links on source code keywords to the relevant language documentation Returns: binary: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # The base uri for api requests query_builder = Configuration.BASE_URI # Prepare query string for API call query_builder += "/code-highlight" # Process optional query parameters query_parameters = { "user-id": self.__user_id, "api-key": self.__api_key } query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters) # Validate and preprocess url query_url = APIHelper.clean_url(query_builder) # Prepare headers headers = { "user-agent": "APIMATIC 2.0" } # Prepare parameters parameters = { "content": content, "type": mtype, "add-keyword-links": add_keyword_links if add_keyword_links is not None else False } # The body will be multipart data, so set the header headers['Content-Type'] = 'multipart/form-data' # Prepare and invoke the API call request to fetch the response response = unirest.post(query_url, headers=headers, params=parameters) # Error handling using HTTP status codes if response.code < 200 or response.code > 206: # 200 = HTTP OK raise APIException("HTTP Response Not OK", response.code, response.body) return response.body