Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if item_value is not None:
return DictionaryItem.upsert(self.conn, {
'service_id': self.attrs['service_id'],
'dictionary_id': self.attrs['id'],
'item_key': item_key,
'item_value': item_value,
})
return DictionaryItem.find(self.conn, service_id=self.attrs['service_id'], dictionary_id=self.attrs['id'], item_key=item_key)
def items(self):
return DictionaryItem.list(self.conn, service_id=self.attrs['service_id'], dictionary_id=self.attrs['id'])
class DictionaryItem(Model):
COLLECTION_PATTERN = Service.COLLECTION_PATTERN + '/$service_id/dictionary/$dictionary_id/items'
INSTANCE_PATTERN = Service.COLLECTION_PATTERN + '/$service_id/dictionary/$dictionary_id/item/$item_key'
INSTANCE_CREATE_PATTERN = Service.COLLECTION_PATTERN + '/$service_id/dictionary/$dictionary_id/item'
@classmethod
def upsert(cls, conn, data):
# https://docs.fastly.com/api/config#dictionary_item_34c884a7cdce84dfcfd38dac7a0b5bb0
instance = cls.construct_instance(data)
instance.conn = conn
params_str = urlencode(instance.attrs)
resp, data = instance._query('PUT', body=params_str)
instance._original_attrs = data
instance.attrs = data
return instance
def _collection_query(self, method, suffix='', body=None):
# DictionaryItem's create API URL is inconsistent with the other APIs,
# with the use of singular and plural ("item" and "items").
# Only use case for POST on this Model is to create one item, so swap in that API URL.
def service(self, id):
return Service.find(self.conn, id=id)
def services(self):
return Service.list(self.conn)