Class: Fastly::Dictionary

Inherits:
BelongsToServiceAndVersion show all
Defined in:
lib/fastly/dictionary.rb

Instance Attribute Summary collapse

Attributes inherited from BelongsToServiceAndVersion

#version

Attributes inherited from Base

#fetcher

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BelongsToServiceAndVersion

#as_hash, delete_path, get_path, path_escape, post_path, put_path, #service, #version_number

Methods inherited from Base

#as_hash, #delete!, delete_path, get_path, #initialize, list_path, path, post_path, put_path, #require_api_key!, #save!

Constructor Details

This class inherits a constructor from Fastly::Base

Instance Attribute Details

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/fastly/dictionary.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/fastly/dictionary.rb', line 3

def name
  @name
end

#service_idObject

Returns the value of attribute service_id.



3
4
5
# File 'lib/fastly/dictionary.rb', line 3

def service_id
  @service_id
end

Class Method Details

.pluralizeObject



37
38
39
# File 'lib/fastly/dictionary.rb', line 37

def self.pluralize
  'dictionaries'
end

Instance Method Details

#add_item(key, value) ⇒ Object



18
19
20
# File 'lib/fastly/dictionary.rb', line 18

def add_item(key, value)
  fetcher.create_dictionary_item(service_id: service_id, dictionary_id: id, item_key: key, item_value: value)
end

#delete_item(key) ⇒ Object



32
33
34
35
# File 'lib/fastly/dictionary.rb', line 32

def delete_item(key)
  di = items.select {|item| item.item_key.eql? key }.first
  fetcher.delete_dictionary_item(di) if di
end

#item(key) ⇒ Object

Returns a Fastly::DictionaryItem corresponding to this dictionary and the key

  • key - Key of the dictionary item



12
13
14
15
16
# File 'lib/fastly/dictionary.rb', line 12

def item(key)
  fetcher.get_dictionary_item(service_id, id, key)
rescue Fastly::Error => e
  raise unless e.message =~ /Record not found/
end

#itemsObject



5
6
7
# File 'lib/fastly/dictionary.rb', line 5

def items
  fetcher.list_dictionary_items(:service_id => service_id, :dictionary_id => id)
end

#update_item(key, value) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/fastly/dictionary.rb', line 22

def update_item(key, value)
  di = items.select {|item| item.item_key.eql? key }.first
  if di
    di.item_value = value
    fetcher.update_dictionary_item(di)
  else
    add_item(key, value)
  end
end