예제 #1
0
def intercom_companies():
    """ Get all companies from Intercom and return the data as a pandas
        DataFrame.

    """
    Intercom.app_id = get_config('INTERCOM_APP_ID')
    Intercom.app_api_key = get_config('INTERCOM_API_KEY')
    company_list = [FlatDict(c.to_dict) for c in Company.all()
                    if 'Verified' in c.custom_attributes and
                    c.custom_attributes['Verified']]
    companies = []
    for c in company_list:
        dic = {}
        for k, v in c.iteritems():
            kn = k.lower().split(':')[-1].replace(' ', '_')
            dic[kn] = v
        companies.append(dic)
    companies = pd.DataFrame(companies)
    companies = companies.T.drop(
        ['0', '1', 'id', 'widget_integrated', 'app_id',
         'automatic_confirm_bookings', 'minimum_book_in_advance_hours',
         'phone_number', 'monthly_spend']).T
    companies.last_request_at = companies.last_request_at.apply(
        lambda x: date.fromtimestamp(x))
    companies.created_at = companies.created_at.apply(
        lambda x: date.fromtimestamp(x))
    companies.remote_created_at = companies.remote_created_at.apply(
        lambda x: date.fromtimestamp(x))
    companies.updated_at = companies.updated_at.apply(
        lambda x: date.fromtimestamp(x))
    return companies
예제 #2
0
 def test_iterate(self):
     # Iterate over all companies
     for company in Company.all():
         self.assertTrue(company.id is not None)
예제 #3
0
 def it_raises_error_if_no_response_on_find_all(self):
     with patch.object(Intercom, 'get', return_value=None) as mock_method:
         with assert_raises(intercom.HttpError):
             [x for x in Company.all()]
         mock_method.assert_called_once_with('/companies')
예제 #4
0
 def it_raises_error_if_no_response_on_find_all(self):
     with patch.object(Intercom, 'get', return_value=None) as mock_method:
         with assert_raises(intercom.HttpError):
             [x for x in Company.all()]
         mock_method.assert_called_once_with('/companies')