Class: Worochi::Agent::Example

Inherits:
Worochi::Agent show all
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

#options

Instance Method Summary collapse

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.

Raises:



57
58
59
# File 'lib/worochi/agent/#example.rb', line 57

def delete(path)
  raise Error, 'Deletion is not supported'
end

#init_clientApiClient

This is where the service-specific API client should be initialized.

Returns:

  • (ApiClient)

See Also:



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.

Parameters:

  • path (String) (defaults to: nil)

    path to list instead of the current directory

Returns:

  • (Array<Hash>)

    list of files and subdirectories

See Also:



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.

Returns:

  • (nil)

See Also:



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.

Returns:

  • (nil)

See Also:



30
31
32
# File 'lib/worochi/agent/#example.rb', line 30

def push_item(item)
  @client.push(item.content, item.path)
end