Exemple #1
0
def create_mood_device():
    mood_device_serial_number = uuid.uuid1()
    sn = mood_device_serial_number.hex
    master_api = xively.XivelyAPIClient(XIVELY_MASTER_API_KEY)
    master_client = xively.Client(XIVELY_MASTER_API_KEY)

    # create the device
    device_data = {'devices': [{'serial': sn}]}
    response = master_client.post(
        '/v2/products/{}/devices'.format(SENSE_PRODUCT_CODE), data=device_data)

    # find the just-created device
    senseboards = master_client.get(
        '/v2/products/{}/devices?per_page=1000'.format(
            SENSE_PRODUCT_CODE)).json()['devices']
    mood_voter = [s for s in senseboards if s['serial'] == sn][0]

    #activate the device
    response = master_client.get('/v2/devices/{}/activate'.format(
        mood_voter['activation_code'])).json()
    mood_device_api_key = response['apikey']
    mood_device_feed_id = response['feed_id']

    config = configparser.ConfigParser()
    config['mood'] = {
        'device_api_key': mood_device_api_key,
        'feed_id': mood_device_feed_id
    }
    with open(CONFIG_FILE, 'w') as configfile:
        config.write(configfile)
    print(
        time.asctime(), "Created new device {} with feedID {}".format(
            mood_device_serial_number, mood_device_feed_id))
 def test_create(self):
     """Tests that we can create a client object."""
     xively.Client("ABCDE")
 def test_request_absolute_url(self):
     """Tests absolute urls are requested for a different host."""
     client = xively.Client("API_KEY")
     client.request('GET', "http://example.com")
     self.request.assert_called_with('GET', "http://example.com")
 def test_request_relative_url(self):
     """Tests relative urls are requested with absolute url."""
     client = xively.Client("API_KEY")
     client.request('GET', "/v2/feeds")
     self.request.assert_called_with('GET', "http://api.xively.com/v2/feeds")