import requests

from . constants import BASE_URL
from . exceptions import SocketLabsUnauthorized


class SocketLabs():

    def __init__(self, username=None, password=None, serverid=None):

        self._username = username
        self._password = password
        self._serverid = serverid

    def failedMessages(self, **kwargs):

        url = BASE_URL + '/messagesFailed'

        headers = {'Accept': 'application/json'}
        params = {'serverId': self._serverid, 'type': 'json'}

        # Apply any custom parameters passed in
        for key, value in kwargs.items():
            params[key] = value

        r = requests.get(url, params=params, headers=headers,
                         auth=(self._username, self._password))

        if r.status_code == 200:
            return r.json()
        else:
            raise SocketLabsUnauthorized(r)

import requests

from . constants import BASE_URL
from . exceptions import SocketLabsUnauthorized


class SocketLabs():

    def __init__(self, username, password, serverid):

        if username is None:
            raise RuntimeError("username not defined")
        if password is None:
            raise RuntimeError("password not defined")
        if serverid is None:
            raise RuntimeError("serverid not defined")

        self._username = username
        self._password = password
        self._serverid = serverid

    def failedMessages(self, **kwargs):

        url = BASE_URL + '/messagesFailed'

        headers = {'Accept': 'application/json'}
        params = {'serverId': self._serverid, 'type': 'json'}

        # Apply any custom parameters passed in
        for key, value in kwargs.items():
            params[key] = value

        r = requests.get(url, params=params, headers=headers,
                         auth=(self._username, self._password))

        if r.status_code == 200:
            return r.json()
        else:
            raise SocketLabsUnauthorized(r)

Add checks for username/password/serverid being defined
Add checks for username/password/serverid being defined

  import requests
  
  from . constants import BASE_URL
  from . exceptions import SocketLabsUnauthorized
  
  
  class SocketLabs():
  
-     def __init__(self, username=None, password=None, serverid=None):
+     def __init__(self, username, password, serverid):
+ 
+         if username is None:
+             raise RuntimeError("username not defined")
+         if password is None:
+             raise RuntimeError("password not defined")
+         if serverid is None:
+             raise RuntimeError("serverid not defined")
  
          self._username = username
          self._password = password
          self._serverid = serverid
  
      def failedMessages(self, **kwargs):
  
          url = BASE_URL + '/messagesFailed'
  
          headers = {'Accept': 'application/json'}
          params = {'serverId': self._serverid, 'type': 'json'}
  
          # Apply any custom parameters passed in
          for key, value in kwargs.items():
              params[key] = value
  
          r = requests.get(url, params=params, headers=headers,
                           auth=(self._username, self._password))
  
          if r.status_code == 200:
              return r.json()
          else:
              raise SocketLabsUnauthorized(r)
  
Add checks for username/password/serverid being defined
## Code Before:
import requests

from . constants import BASE_URL
from . exceptions import SocketLabsUnauthorized


class SocketLabs():

    def __init__(self, username=None, password=None, serverid=None):

        self._username = username
        self._password = password
        self._serverid = serverid

    def failedMessages(self, **kwargs):

        url = BASE_URL + '/messagesFailed'

        headers = {'Accept': 'application/json'}
        params = {'serverId': self._serverid, 'type': 'json'}

        # Apply any custom parameters passed in
        for key, value in kwargs.items():
            params[key] = value

        r = requests.get(url, params=params, headers=headers,
                         auth=(self._username, self._password))

        if r.status_code == 200:
            return r.json()
        else:
            raise SocketLabsUnauthorized(r)

## Instruction:
Add checks for username/password/serverid being defined
## Code After:
import requests

from . constants import BASE_URL
from . exceptions import SocketLabsUnauthorized


class SocketLabs():

    def __init__(self, username, password, serverid):

        if username is None:
            raise RuntimeError("username not defined")
        if password is None:
            raise RuntimeError("password not defined")
        if serverid is None:
            raise RuntimeError("serverid not defined")

        self._username = username
        self._password = password
        self._serverid = serverid

    def failedMessages(self, **kwargs):

        url = BASE_URL + '/messagesFailed'

        headers = {'Accept': 'application/json'}
        params = {'serverId': self._serverid, 'type': 'json'}

        # Apply any custom parameters passed in
        for key, value in kwargs.items():
            params[key] = value

        r = requests.get(url, params=params, headers=headers,
                         auth=(self._username, self._password))

        if r.status_code == 200:
            return r.json()
        else:
            raise SocketLabsUnauthorized(r)
