from pagerduty_events_api.pagerduty_rest_client import PagerdutyRestClient


class PagerdutyIncident:
    def __init__(self, service_key, incident_key):
        self.__service_key = service_key
        self.__incident_key = incident_key

    def get_service_key(self):
        return self.__service_key

    def get_incident_key(self):
        return self.__incident_key

    def acknowledge(self):
        payload = {'service_key': self.__service_key,
                   'event_type': 'acknowledge',
                   'incident_key': self.__incident_key}

        PagerdutyRestClient().post(payload)

    def resolve(self):
        payload = {'service_key': self.__service_key,
                   'event_type': 'resolve',
                   'incident_key': self.__incident_key}

        PagerdutyRestClient().post(payload)

from pagerduty_events_api.pagerduty_rest_client import PagerdutyRestClient


class PagerdutyIncident:
    def __init__(self, service_key, incident_key):
        self.__service_key = service_key
        self.__incident_key = incident_key

    def get_service_key(self):
        return self.__service_key

    def get_incident_key(self):
        return self.__incident_key

    def acknowledge(self):
        self.__send_request_with_event_type('acknowledge')

    def resolve(self):
        self.__send_request_with_event_type('resolve')

    def __send_request_with_event_type(self, event_type):
        payload = {'service_key': self.__service_key,
                   'event_type': event_type,
                   'incident_key': self.__incident_key}

        PagerdutyRestClient().post(payload)

Remove code duplication from PD Incident class.
Remove code duplication from PD Incident class.

  from pagerduty_events_api.pagerduty_rest_client import PagerdutyRestClient
  
  
  class PagerdutyIncident:
      def __init__(self, service_key, incident_key):
          self.__service_key = service_key
          self.__incident_key = incident_key
  
      def get_service_key(self):
          return self.__service_key
  
      def get_incident_key(self):
          return self.__incident_key
  
      def acknowledge(self):
+         self.__send_request_with_event_type('acknowledge')
+ 
+     def resolve(self):
+         self.__send_request_with_event_type('resolve')
+ 
+     def __send_request_with_event_type(self, event_type):
          payload = {'service_key': self.__service_key,
-                    'event_type': 'acknowledge',
+                    'event_type': event_type,
                     'incident_key': self.__incident_key}
  
          PagerdutyRestClient().post(payload)
  
-     def resolve(self):
-         payload = {'service_key': self.__service_key,
-                    'event_type': 'resolve',
-                    'incident_key': self.__incident_key}
- 
-         PagerdutyRestClient().post(payload)
- 
Remove code duplication from PD Incident class.
## Code Before:
from pagerduty_events_api.pagerduty_rest_client import PagerdutyRestClient


class PagerdutyIncident:
    def __init__(self, service_key, incident_key):
        self.__service_key = service_key
        self.__incident_key = incident_key

    def get_service_key(self):
        return self.__service_key

    def get_incident_key(self):
        return self.__incident_key

    def acknowledge(self):
        payload = {'service_key': self.__service_key,
                   'event_type': 'acknowledge',
                   'incident_key': self.__incident_key}

        PagerdutyRestClient().post(payload)

    def resolve(self):
        payload = {'service_key': self.__service_key,
                   'event_type': 'resolve',
                   'incident_key': self.__incident_key}

        PagerdutyRestClient().post(payload)

## Instruction:
Remove code duplication from PD Incident class.
## Code After:
from pagerduty_events_api.pagerduty_rest_client import PagerdutyRestClient


class PagerdutyIncident:
    def __init__(self, service_key, incident_key):
        self.__service_key = service_key
        self.__incident_key = incident_key

    def get_service_key(self):
        return self.__service_key

    def get_incident_key(self):
        return self.__incident_key

    def acknowledge(self):
        self.__send_request_with_event_type('acknowledge')

    def resolve(self):
        self.__send_request_with_event_type('resolve')

    def __send_request_with_event_type(self, event_type):
        payload = {'service_key': self.__service_key,
                   'event_type': event_type,
                   'incident_key': self.__incident_key}

        PagerdutyRestClient().post(payload)
