Module: AnkiConnect::Client::Miscellaneous

Included in:
AnkiConnect::Client
Defined in:
lib/anki_connect/miscellaneous.rb

Overview

Methods for API permissions, version checking, profile management, synchronization, and import/export.

Instance Method Summary collapse

Instance Method Details

#active_profileString

Gets the active profile.

Returns:

  • (String)

    Profile name string



51
52
53
# File 'lib/anki_connect/miscellaneous.rb', line 51

def active_profile
  request(:getActiveProfile)
end

#api_reflect(scopes, actions: nil) ⇒ Hash

Gets information about available APIs.

Parameters:

  • scopes (Array<String>)

    Array of scope names (currently only “actions” supported)

  • actions (Array<String>, nil) (defaults to: nil)

    null for all actions, or array of action names to check (optional)

Returns:

  • (Hash)

    Object with scopes used and available actions



28
29
30
31
32
# File 'lib/anki_connect/miscellaneous.rb', line 28

def api_reflect(scopes, actions: nil)
  params = { scopes: scopes }
  params[:actions] = actions if actions
  request(:apiReflect, **params)
end

#export_deck(deck_name, path, include_scheduling: false) ⇒ Boolean

Exports deck to .apkg format.

Parameters:

  • deck_name (String)

    Deck name

  • path (String)

    Output file path

  • include_scheduling (Boolean) (defaults to: false)

    Include scheduling data (default: false)

Returns:

  • (Boolean)

    true on success, false otherwise



77
78
79
# File 'lib/anki_connect/miscellaneous.rb', line 77

def export_deck(deck_name, path, include_scheduling: false)
  request(:exportPackage, deck: deck_name, path: path, includeSched: include_scheduling)
end

#import_deck(path) ⇒ Boolean

Imports .apkg file into collection.

Parameters:

  • path (String)

    File path (relative to collection.media folder)

Returns:

  • (Boolean)

    true on success, false otherwise



85
86
87
# File 'lib/anki_connect/miscellaneous.rb', line 85

def import_deck(path)
  request(:importPackage, path: path)
end

#load_profile(name) ⇒ Boolean

Switches to specified profile.

Parameters:

  • name (String)

    Profile name

Returns:

  • (Boolean)

    true on success



59
60
61
# File 'lib/anki_connect/miscellaneous.rb', line 59

def load_profile(name)
  request(:loadProfile, name: name)
end

#multi(actions) ⇒ Array

Performs multiple actions in one request.

Parameters:

  • actions (Array<Hash>)

    Array of action objects (each with action, version, params)

Returns:

  • (Array)

    Array of responses in same order



67
68
69
# File 'lib/anki_connect/miscellaneous.rb', line 67

def multi(actions)
  request(:multi, actions: actions)
end

#profilesArray<String>

Retrieves list of profiles.

Returns:

  • (Array<String>)

    Array of profile names



44
45
46
# File 'lib/anki_connect/miscellaneous.rb', line 44

def profiles
  request(:getProfiles)
end

#reload_collectionnil

Reloads all data from database.

Returns:

  • (nil)


92
93
94
# File 'lib/anki_connect/miscellaneous.rb', line 92

def reload_collection
  request(:reloadCollection)
end

#request_permissionHash

Requests API permission (first call to establish trust). Only method accepting requests from any origin. Shows popup for untrusted origins.

Returns:

  • (Hash)

    Object with permission (granted/denied), and optionally requireApiKey and version



12
13
14
# File 'lib/anki_connect/miscellaneous.rb', line 12

def request_permission
  request(:requestPermission)
end

#syncnil

Synchronizes local collection with AnkiWeb.

Returns:

  • (nil)


37
38
39
# File 'lib/anki_connect/miscellaneous.rb', line 37

def sync
  request(:sync)
end

#versionInteger

Gets AnkiConnect API version.

Returns:

  • (Integer)

    Version number (currently 6)



19
20
21
# File 'lib/anki_connect/miscellaneous.rb', line 19

def version
  request(:version)
end