Class: Worochi::Agent::Example
- Inherits:
-
Worochi::Agent
- Object
- Worochi::Agent
- Worochi::Agent::Example
- Defined in:
- lib/worochi/agent/#example.rb
Overview
The Worochi::Agent for an example API. This is a sample of methods that should be implemented by a service agent.
Instance Attribute Summary
Attributes inherited from Worochi::Agent
Instance Method Summary collapse
-
#delete(path) ⇒ Object
Deletes the file at path.
-
#init_client ⇒ ApiClient
This is where the service-specific API client should be initialized.
-
#list(path = nil) ⇒ Array<Hash>
Returns a list of files and subdirectories at the remote path specified by ‘options`.
-
#push_all(items) ⇒ nil
Defined for services that need to push all the items together as a batch.
-
#push_item(item) ⇒ nil
Pushes an individual item to the service.
Methods inherited from Worochi::Agent
#files, #files_and_folders, #folders, #initialize, #name, new, #push, #push_items, #remove, #set_dir, #set_options, #type
Constructor Details
This class inherits a constructor from Worochi::Agent
Instance Method Details
#delete(path) ⇒ Object
Deletes the file at path. Raises Error if file deletion is not supported by the service.
57 58 59 |
# File 'lib/worochi/agent/#example.rb', line 57 def delete(path) raise Error, 'Deletion is not supported' end |
#init_client ⇒ ApiClient
This is where the service-specific API client should be initialized.
9 10 11 |
# File 'lib/worochi/agent/#example.rb', line 9 def init_client @client = nil end |
#list(path = nil) ⇒ Array<Hash>
Returns a list of files and subdirectories at the remote path specified by ‘options`. Each file entry is a hash that should contain at least the keys `:name`, `:path`, and `:type`, but can also contain other service-specific meta information.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/worochi/agent/#example.rb', line 43 def list(path=nil) remote_path = list_path(path) result = @client.get_file_list(remote_path) result.map do |elem| { name: elem.name, path: elem.path, type: elem.type } end end |
#push_all(items) ⇒ nil
Defined for services that need to push all the items together as a batch. For example, GitHub needs to make one commit for all the files. Usually a service-specific implementation should only need one of either #push_item or #push_all.
20 21 22 |
# File 'lib/worochi/agent/#example.rb', line 20 def push_all(items) items.each { |item| @client.push(item.content, item.path) } end |
#push_item(item) ⇒ nil
Pushes an individual item to the service. Usually a service-specific implementation should only need one of either #push_item or #push_all.
30 31 32 |
# File 'lib/worochi/agent/#example.rb', line 30 def push_item(item) @client.push(item.content, item.path) end |