Class: ContextIO::Folder

Inherits:
Resource show all
Defined in:
lib/context-io/folder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from Request

#delete, #get, #post, #put, #request

Instance Attribute Details

#account_idString (readonly)

Returns The (Context.IO) ID of the account this folder belongs to, as a hexadecimal string.

Returns:

  • (String)

    The (Context.IO) ID of the account this folder belongs to, as a hexadecimal string.



8
9
10
# File 'lib/context-io/folder.rb', line 8

def 
  @account_id
end

#delimString (readonly)

Returns The folder hierarchy delimiter.

Examples:

Get the folder name and not the entire path.

folder.name.split(folder.delim).last

Returns:

  • (String)

    The folder hierarchy delimiter.



24
25
26
# File 'lib/context-io/folder.rb', line 24

def delim
  @delim
end

#included_in_synctrue, false (readonly)

Returns Whether this folder is included when Context.IO syncs with the source.

Returns:

  • (true, false)

    Whether this folder is included when Context.IO syncs with the source.



33
34
35
# File 'lib/context-io/folder.rb', line 33

def included_in_sync
  @included_in_sync
end

#nameString (readonly)

Returns The full name of the folder. This includes the name of parent folders.

Returns:

  • (String)

    The full name of the folder. This includes the name of parent folders.



17
18
19
# File 'lib/context-io/folder.rb', line 17

def name
  @name
end

#nb_messagesInteger (readonly)

Returns The number of messages in the folder.

Returns:

  • (Integer)

    The number of messages in the folder.



28
29
30
# File 'lib/context-io/folder.rb', line 28

def nb_messages
  @nb_messages
end

#source_labelString (readonly)

Returns The label of the source this folder belongs to.

Returns:

  • (String)

    The label of the source this folder belongs to.



12
13
14
# File 'lib/context-io/folder.rb', line 12

def source_label
  @source_label
end

Class Method Details

.all(account_id, source_label) ⇒ Array<ContextIO::Folder> .all(source) ⇒ Array<ContextIO::Folder>

Get all folders for a given source and account

Examples:

Find a the folders on a given source.

ContextIO::Folder.all(source)

Overloads:

  • .all(account_id, source_label) ⇒ Array<ContextIO::Folder>

    Parameters:

    • account_id (#to_s)

      The account ID

    • source_label (#to_s)

      The source label

  • .all(source) ⇒ Array<ContextIO::Folder>

    Parameters:

Returns:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/context-io/folder.rb', line 49

def self.all(*args)
  if args.length == 1
     = args.first.
    source_label = args.first.label
  elsif args.length == 2
     = args.first.to_s
    source_label = args.last.to_s
  else
    raise ArgumentError, "Expecting one or two arguments, got #{args.length}"
  end

  get("/2.0/accounts/#{}/sources/#{source_label}/folders").map do |msg|
    Folder.from_json(, source_label, msg)
  end
end

.from_json(account_id, source_label, json) ⇒ ContextIO::Folder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a Folder with the JSON data from Context.IO

Parameters:

  • account_id (String)

    The account ID the source belongs to.

  • source_label (String)

    The label of the source this folder belongs to.

  • json (Hash)

    The parsed JSON object returned by a Context.IO API request. See their documentation for possible keys.

Returns:



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/context-io/folder.rb', line 76

def self.from_json(, source_label, json)
  folder = new
  folder.instance_eval do
    @account_id = 
    @source_label = source_label
    @name = json['name']
    @delim = json['delim']
    @nb_messages = json['nb_messages']
    @included_in_sync = json['included_in_sync']
  end

  folder
end