Esempio n. 1
0
    def add_organisation_link(self, organisation_id, role=None, details=None):
        """Add a organisation link to this opportunity

        :organisation_id: Organisation ID to link to this Opportunity
        :role: role in this Opportunity
        :details: additional details to add context
        :return: the link
        :rtype: Link
        """

        post_args = dict(OPPORTUNITY_ID=self.OPPORTUNITY_ID,
                         ORGANISATION_ID=organisation_id)

        if role:
            post_args['ROLE'] = role

        if details:
            post_args['DETAILS'] = details

        json_obj = self.client.get_json(
            Config["Opportunities"]["Endpoints"]["AddLink"]["Url"].format(
                id=self.OPPORTUNITY_ID),
            http_method=Config["Opportunities"]["Endpoints"]["AddLink"]
            ["Method"],
            post_args=post_args)
        # self.fetch()  # update current model
        return Link.from_json(json_obj)
Esempio n. 2
0
    def add_opportunity_link(self, opportunity_id, role=None, details=None):
        """Add an opportunity link to this organisation

        :opportunity: Opportunity ID to link to this Contact
        :role: role in this Opportunity
        :details: additional details to add context
        :return: the link
        :rtype: Link
        """

        post_args = dict(CONTACT_ID=self.CONTACT_ID,
                         OPPORTUNITY_ID=opportunity_id)

        if role:
            post_args['ROLE'] = role

        if details:
            post_args['DETAILS'] = details

        json_obj = self.client.get_json(
            Config["Contacts"]["Endpoints"]["AddLink"]["Url"].format(
                id=force_str(self.CONTACT_ID)),
            http_method=Config["Contacts"]["Endpoints"]["AddLink"]["Method"],
            post_args=post_args)
        # self.fetch()  # update current model
        return Link.from_json(json_obj)
Esempio n. 3
0
    def add_contact_link(self, contact_id, role=None, details=None):
        """Add a contact link to this organisation

        :contact_id: Contact ID to link to this Organisation
        :role: role in this Organisation
        :details: additional details to add context
        :return: the link
        :rtype: Link
        """

        post_args = dict(ORGANISATION_ID=self.ORGANISATION_ID,
                         CONTACT_ID=contact_id)

        if role:
            post_args['ROLE'] = role

        if details:
            post_args['DETAILS'] = details

        json_obj = self.client.get_json(
            Config["Organisations"]["Endpoints"]["AddLink"]["Url"].format(
                id=self.ORGANISATION_ID),
            http_method=Config["Organisations"]["Endpoints"]["AddLink"]
            ["Method"],
            post_args=post_args)
        # self.fetch()  # update current model
        return Link.from_json(json_obj)
Esempio n. 4
0
    def from_json(cls, insightly_client=None, json_obj=None):
        """
        Deserialize the organisation json object to a Organisation object

        :insightly_client: the insightly client
        :json_obj: the organisation json object
        """

        organisation = Organisation(
            client=insightly_client,
            organisation_id=json_obj['ORGANISATION_ID'],
            name=json_obj['ORGANISATION_NAME'],
            background=json_obj['BACKGROUND'],
            billing_address=Address(json_obj['ADDRESS_BILLING_STREET'],
                                    json_obj['ADDRESS_BILLING_CITY'],
                                    json_obj['ADDRESS_BILLING_STATE'],
                                    json_obj['ADDRESS_BILLING_POSTCODE'],
                                    json_obj['ADDRESS_BILLING_COUNTRY']),
            shipping_address=Address(json_obj['ADDRESS_BILLING_STREET'],
                                     json_obj['ADDRESS_BILLING_CITY'],
                                     json_obj['ADDRESS_BILLING_STATE'],
                                     json_obj['ADDRESS_BILLING_POSTCODE'],
                                     json_obj['ADDRESS_BILLING_COUNTRY']),
            deletable=json_obj['CAN_DELETE'],
            editable=json_obj['CAN_EDIT'],
            custom_fields=[
                CustomField.from_json(obj) for obj in json_obj['CUSTOMFIELDS']
            ],
            dates=json_obj['DATES'],
            created=json_obj['DATE_CREATED_UTC'],
            last_updated=json_obj['DATE_UPDATED_UTC'],
            email_domains=json_obj['EMAILDOMAINS'],
            image_url=json_obj['IMAGE_URL'],
            links=[Link.from_json(json_obj=obj) for obj in json_obj['LINKS']],
            organisation_links=[
                OrganisationLink.from_json(json_obj=obj)
                for obj in json_obj['ORGANISATIONLINKS']
            ],
            owner_user_id=json_obj['OWNER_USER_ID'],
            phone=json_obj['PHONE'],
            fax=json_obj['PHONE_FAX'],
            facebook=json_obj['SOCIAL_FACEBOOK'],
            linkedin=json_obj['SOCIAL_LINKEDIN'],
            twitter=json_obj['SOCIAL_TWITTER'],
            tags=json_obj['TAGS'],
            visible_team_id=json_obj['VISIBLE_TEAM_ID'],
            visible_to=json_obj['VISIBLE_TO'],
            visible_user_ids=json_obj['VISIBLE_USER_IDS'],
            website=json_obj['WEBSITE'])

        return organisation
Esempio n. 5
0
    def from_json(cls, insightly_client=None, json_obj=None):
        """
        Deserialize the organisation json object to an Opportunity object

        :insightly_client: the insightly client
        :json_obj: the opportunity json object
        """

        opportunity = Opportunity(
            client=insightly_client,
            opportunity_id=json_obj['OPPORTUNITY_ID'],
            opportunity_name=json_obj['OPPORTUNITY_NAME'],
            opportunity_details=json_obj['OPPORTUNITY_DETAILS'],
            organisation_id=json_obj['ORGANISATION_ID'],
            owner_user_id=json_obj['OWNER_USER_ID'],
            bid_amount=json_obj['BID_AMOUNT'],
            bid_currency=json_obj['BID_CURRENCY'],
            bid_duration=json_obj['BID_DURATION'],
            bid_type=json_obj['BID_TYPE'],
            deletable=json_obj['CAN_DELETE'],
            editable=json_obj['CAN_EDIT'],
            category_id=json_obj['CATEGORY_ID'],
            customfields=[
                CustomField.from_json(obj) for obj in json_obj['CUSTOMFIELDS']
            ],
            forecast_close_date=json_obj['FORECAST_CLOSE_DATE'],
            actual_close_date=json_obj['ACTUAL_CLOSE_DATE'],
            image_url=json_obj['IMAGE_URL'],
            links=[Link.from_json(obj) for obj in json_obj['LINKS']],
            opportunity_state=json_obj['OPPORTUNITY_STATE'],
            opportunity_state_reason_id=json_obj[
                'OPPORTUNITY_STATE_REASON_ID'],
            opportunity_value=json_obj['OPPORTUNITY_VALUE'],
            pipeline_id=json_obj['PIPELINE_ID'],
            probability=json_obj['PROBABILITY'],
            responsible_user_id=json_obj['RESPONSIBLE_USER_ID'],
            stage_id=json_obj['STAGE_ID'],
            tags=json_obj['TAGS'],
            visible_team_id=json_obj['VISIBLE_TEAM_ID'],
            visible_to=json_obj['VISIBLE_TO'],
            visible_user_ids=json_obj['VISIBLE_USER_IDS'],
            created=json_obj['DATE_CREATED_UTC'],
            last_updated=json_obj['DATE_UPDATED_UTC'])

        return opportunity
Esempio n. 6
0
    def update_opportunity_link(self,
                                link_id=None,
                                opportunity_id=None,
                                role=None,
                                details=None):
        """Update a opportunity link to this Contact
        :link_id: the identifier for the opportunity link - note: must exist already in order to update
        :opportunity_id: Opportunity ID to link to this Contact
        :role: role in this Opportunity
        :details: additional details to add context
        :return: the link
        :rtype: Link
        """

        link = self.get_link(link_id)

        if not link:
            raise DoesNotExist("Opportunity Link does not exist", link)

        post_args = dict(LINK_ID=link_id,
                         OPPORTUNITY_ID=opportunity_id
                         if opportunity_id else link.OPPORTUNITY_ID)

        if role:
            post_args['ROLE'] = role
        if not role and link.ROLE:
            post_args['ROLE'] = link.ROLE

        if details:
            post_args['DETAILS'] = details
        if not details and link.DETAILS:
            post_args['DETAILS'] = link.DETAILS

        json_obj = self.client.get_json(
            Config["Contacts"]["Endpoints"]["UpdateLink"]["Url"].format(
                id=force_str(self.CONTACT_ID)),
            http_method=Config["Contacts"]["Endpoints"]["UpdateLink"]
            ["Method"],
            post_args=post_args)
        # self.fetch()  # update current model
        return Link.from_json(json_obj)
Esempio n. 7
0
    def update_contact_link(self,
                            link_id=None,
                            contact_id=None,
                            role=None,
                            details=None):
        """Update a contact link to this Organisation
        :link_id: the identifier for the organisation link - note: must exist already in order to update
        :contact_id: Contact ID to link to this Organisation
        :role: role in this Organisation
        :details: additional details to add context
        :return: the link
        :rtype: Link
        """

        link = self.get_link(link_id)

        if not link:
            raise DoesNotExist("Contact Link does not exist", link)

        post_args = dict(
            LINK_ID=link_id,
            CONTACT_ID=contact_id if contact_id else link.CONTACT_ID)

        if role:
            post_args['ROLE'] = role
        if not role and link.ROLE:
            post_args['ROLE'] = link.ROLE

        if details:
            post_args['DETAILS'] = details
        if not details and link.DETAILS:
            post_args['DETAILS'] = link.DETAILS

        json_obj = self.client.get_json(
            Config["Organisations"]["Endpoints"]["UpdateLink"]["Url"].format(
                id=self.ORGANISATION_ID),
            http_method=Config["Organisations"]["Endpoints"]["UpdateLink"]
            ["Method"],
            post_args=post_args)
        # self.fetch()  # update current model
        return Link.from_json(json_obj)
Esempio n. 8
0
    def from_json(cls, insightly_client=None, json_obj=None):
        """
        Deserialize the contact json object to a Contact object

        :insightly_client: the insightly client
        :json_obj: the contact json object
        """

        contact = Contact(
            client=insightly_client,
            contact_id=json_obj['CONTACT_ID'],
            organisation_id=json_obj['ORGANISATION_ID'],
            default_linked_organisation_id=json_obj[
                'DEFAULT_LINKED_ORGANISATION'],
            salutation=json_obj['SALUTATION'],
            first_name=json_obj['FIRST_NAME'],
            last_name=json_obj['LAST_NAME'],
            dob=json_obj['DATE_OF_BIRTH'],
            email_address=json_obj['EMAIL_ADDRESS'],
            title=json_obj['TITLE'],
            background=json_obj['BACKGROUND'],
            postal_address=Address(json_obj['ADDRESS_MAIL_STREET'],
                                   json_obj['ADDRESS_MAIL_CITY'],
                                   json_obj['ADDRESS_MAIL_STATE'],
                                   json_obj['ADDRESS_MAIL_POSTCODE'],
                                   json_obj['ADDRESS_MAIL_COUNTRY']),
            other_address=Address(json_obj['ADDRESS_OTHER_STREET'],
                                  json_obj['ADDRESS_OTHER_CITY'],
                                  json_obj['ADDRESS_OTHER_STATE'],
                                  json_obj['ADDRESS_OTHER_POSTCODE'],
                                  json_obj['ADDRESS_OTHER_COUNTRY']),
            assistant_name=json_obj['ASSISTANT_NAME'],
            assistant_phone=json_obj['PHONE_ASSISTANT'],
            deletable=json_obj['CAN_DELETE'],
            editable=json_obj['CAN_EDIT'],
            contact_links=[
                ContactLink.from_json(obj) for obj in json_obj['CONTACTLINKS']
            ],
            custom_fields=[
                CustomField.from_json(obj) for obj in json_obj['CUSTOMFIELDS']
            ],
            dates=json_obj['DATES'],
            created=json_obj['DATE_CREATED_UTC'],
            last_updated=json_obj['DATE_UPDATED_UTC'],
            image_url=json_obj['IMAGE_URL'],
            links=[Link.from_json(obj) for obj in json_obj['LINKS']],
            owner_user_id=json_obj['OWNER_USER_ID'],
            phone=json_obj['PHONE'],
            fax=json_obj['PHONE_FAX'],
            phone_home=json_obj['PHONE_HOME'],
            phone_mobile=json_obj['PHONE_MOBILE'],
            phone_other=json_obj['PHONE_OTHER'],
            facebook=json_obj['SOCIAL_FACEBOOK'],
            linkedin=json_obj['SOCIAL_LINKEDIN'],
            twitter=json_obj['SOCIAL_TWITTER'],
            tags=json_obj['TAGS'],
            visible_team_id=json_obj['VISIBLE_TEAM_ID'],
            visible_to=json_obj['VISIBLE_TO'],
            visible_user_ids=json_obj['VISIBLE_USER_IDS'])

        return contact