<commit_before>import requests
from settings import Settings
settings = Settings()

class Component(object):

  def __init__(self):
    self._id = None
    self._name = None
    self._position = None
    self._status = None
    self._group_id = None
    self._updated_at = None
    self._description = None
    
  @property
  def id(self):
    return self._id
  
  @id.setter
  def id(self, value):
    self._id = value
    
  @property
  def position(self):
    return self._position
  
  @position.setter
  def position(self, value):
    self.position = value
  
  @property
  def group_id(self):
    return self._group_id
  
  @group_id.setter
  def group_id(self, value):
    self._group_id = value

  @property
  def name(self):
    return self._name

  @name.setter
  def name(self, value):
    self._name = value
 
  @property
  def status(self):
    return self._status
  
  @status.setter
  def status(self, value):
    self._status = value
  
  @property
  def description(self):
    return self._description
  
  @description.setter
  def description(self, value):
    self._description = value
  
  @staticmethod
  def fromName(component_name):
    component_list = Component.list()
    for component in component_list:
      if component.name == component_name:
        return component
    raise ValueError('Component does not exist')

  @staticmethod
  def fromDict(component_dict):
    component = Component()
    component.id = component_dict['id']
    component.name = component_dict['name']
    component.description = component_dict['description']
    component.status = component_dict['status']
    component.group_id = component_dict['group_id']
    # component.created_at = component_dict['created_at']
    # component.updated-at = component_dict['updated_at']
    return component

  @staticmethod
  def list():
    # url format : GET /pages/[page_id]/components.json
    url = 'https://{}/pages/{}/components.json'.format(settings.SITE_HOST, settings.PAGE_ID)
    try:
      response = requests.get(url, headers={'Authorization': 'OAuth {}'.format(settings.API_TOKEN, verify=True)})
      assert(response.status_code == 200)
    except AssertionError as e:
      raise ValueError("Could not fetch Component list. Returned status code {}. Content: {}".format(response.status_code, response.content))
    except Exception as e:
      raise e
    for component in response.json():
      yield(Component.fromDict(component))

  def create(self):
    # url format : POST /pages/[page_id]/components.json
    url = 'https://{}/pages/{}/components.json'.format(settings.SITE_HOST, settings.PAGE_ID)
    data = {
            'component' : {
                'name': self.name,
                'description': self.description,
                'group_id' : self.group_id
                }
           }
    try:
      response = requests.post(url, json=data, headers={'Authorization': 'OAuth {}'.format(settings.API_TOKEN, verify=True)})
      assert(response.status_code == 201)
    except AssertionError as e:
      raise ValueError("Could not create Component. Returned status code {}. Content: {}".format(response.status_code, response.content))
    except Exception as e:
      raise e
    self.status = response.json()['status']
    self.position = response.json()['position']
    self.id = response.json()['id']

  def update(self, status='major_outage'):
    # url format : PATCH /pages/[page_id]/components/[component_id].json
    url = 'https://{}/pages/{}/components/{}.json'.format(settings.SITE_HOST, settings.PAGE_ID, self.id)
    data = {
            'component' : {
                'status': status,
                }
           }
    try:
      response = requests.patch(url, json=data, headers={'Authorization': 'OAuth {}'.format(settings.API_TOKEN, verify=True)})
      assert(response.status_code == 200)
    except AssertionError as e:
      raise ValueError("Could not update Component. Returned status code {}. Content: {}".format(response.status_code, response.content))
    except Exception as e:
      raise e

  def delete(self):
    # url = DELETE /pages/[page_id]/components/[component_id].json
    url = 'https://{}/pages/{}/components/{}.json'.format(settings.SITE_HOST, settings.PAGE_ID, self.id)
    try:
      response = requests.delete(url, headers={'Authorization': 'OAuth {}'.format(settings.API_TOKEN, verify=True)})
      assert(response.status_code == 204)
    except AssertionError as e:
      raise ValueError("Could not delete Component. Returned status code {}. Content: {}".format(response.status_code, response.content))
    except Exception as e:
      raise e
    self.status = response.json()['status']<commit_msg>[core] Updating component to use util.<commit_after>from util.rest import *
from settings import Settings
settings = Settings()

class Component(object):

  def __init__(self):
    self._id = None
    self._name = None
    self._position = None
    self._status = None
    self._group_id = None
    self._updated_at = None
    self._description = None
    
  @property
  def id(self):
    return self._id
  
  @id.setter
  def id(self, value):
    self._id = value
    
  @property
  def position(self):
    return self._position
  
  @position.setter
  def position(self, value):
    self.position = value
  
  @property
  def group_id(self):
    return self._group_id
  
  @group_id.setter
  def group_id(self, value):
    self._group_id = value

  @property
  def name(self):
    return self._name

  @name.setter
  def name(self, value):
    self._name = value
 
  @property
  def status(self):
    return self._status
  
  @status.setter
  def status(self, value):
    self._status = value
  
  @property
  def description(self):
    return self._description
  
  @description.setter
  def description(self, value):
    self._description = value
  
  @staticmethod
  def fromName(component_name):
    component_list = Component.list()
    for component in component_list:
      if component.name == component_name:
        return component
    raise ValueError('Component does not exist')

  @staticmethod
  def fromDict(component_dict):
    component = Component()
    component.id = component_dict['id']
    component.name = component_dict['name']
    component.description = component_dict['description']
    component.status = component_dict['status']
    component.group_id = component_dict['group_id']
    # component.created_at = component_dict['created_at']
    # component.updated-at = component_dict['updated_at']
    return component

  @staticmethod
  def list():
    # url format : GET /pages/[page_id]/components.json
    url = 'https://{}/pages/{}/components.json'.format(settings.SITE_HOST, settings.PAGE_ID)
    try:
      response = getUrl(url)
      assert(response.status_code == 200)
    except AssertionError as e:
      raise ValueError("Could not fetch Component list. Returned status code {}. Content: {}".format(response.status_code, response.content))
    
    for component in response.json():
      yield(Component.fromDict(component))

  def create(self):
    # url format : POST /pages/[page_id]/components.json
    url = 'https://{}/pages/{}/components.json'.format(settings.SITE_HOST, settings.PAGE_ID)
    data = {
            'component' : {
                'name': self.name,
                'description': self.description,
                'group_id' : self.group_id
                }
           }
    try:
      response = postUrl(url, data)
      assert(response.status_code == 201)
      self.status = response.json()['status']
      self.position = response.json()['position']
      self.id = response.json()['id']
    except AssertionError as e:
      raise ValueError("Could not create Component. Returned status code {}. Content: {}".format(response.status_code, response.content))

  def update(self, status='major_outage'):
    # url format : PATCH /pages/[page_id]/components/[component_id].json
    url = 'https://{}/pages/{}/components/{}.json'.format(settings.SITE_HOST, settings.PAGE_ID, self.id)
    data = {
            'component' : {
                'status': status,
                }
           }
    try:
      response = patchUrl(url, data)
      assert(response.status_code == 200)
    except AssertionError as e:
      raise ValueError("Could not update Component. Returned status code {}. Content: {}".format(response.status_code, response.content))

  def delete(self):
    # url = DELETE /pages/[page_id]/components/[component_id].json
    url = 'https://{}/pages/{}/components/{}.json'.format(settings.SITE_HOST, settings.PAGE_ID, self.id)
    try:
      response = deleteUrl(url)
      assert(response.status_code == 204)
      self.status = response.json()['status']
    except AssertionError as e:
      raise ValueError("Could not delete Component. Returned status code {}. Content: {}".format(response.status_code, response.content))
{'fraction_non_alphanumeric': 0.12348041422782531, 'fraction_numerical': 0.0027014858171994596, 'mean_word_length': 3.055225924235509, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5477308', 'n_tokens_mistral': 2633, 'n_tokens_neox': 2583, 'n_words': 603}