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_profile ⇒ String

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_capabilities(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_capabilities(scopes, actions: nil)
  params = { scopes: scopes }
  params[:actions] = actions if actions
  request(:apiReflect, **params)
end

#api_version ⇒ Integer

Gets AnkiConnect API version.

Returns:

  • (Integer) —

    Version number (currently 6)



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

def api_version
  request(:version)
end

#batch(actions) ⇒ Array

Performs multiple actions in one request. Unlike convenience wrappers, each action uses AnkiConnect's raw wire keys.

Parameters:

  • actions (Array<Hash>) —

    Raw wire action objects with action, version, and params

Returns:

  • (Array) —

    Array of responses in same order

See Also:



69
70
71
# File 'lib/anki_connect/miscellaneous.rb', line 69

def batch(actions)
  request(:multi, actions: actions)
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



79
80
81
# File 'lib/anki_connect/miscellaneous.rb', line 79

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

#import_package(path) ⇒ Boolean

Imports .apkg file into collection.

Parameters:

  • path (String) —

    Package file path on the Anki host

Returns:

  • (Boolean) —

    true on success, false otherwise



87
88
89
# File 'lib/anki_connect/miscellaneous.rb', line 87

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

#load_profile(name) ⇒ Boolean

Switches to specified profile.

Parameters:

  • name (String) —

    Profile name

Returns:

  • (Boolean) —

    true on success, false when the profile does not exist



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

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

#profiles ⇒ Array<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_collection ⇒ nil

Reloads all data from database.

Returns:

  • (nil)


94
95
96
# File 'lib/anki_connect/miscellaneous.rb', line 94

def reload_collection
  request(:reloadCollection)
end

#request_permission ⇒ Hash

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 and optionally requireApikey and version



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

def request_permission
  request(:requestPermission)
end

#sync ⇒ nil

Synchronizes local collection with AnkiWeb.

Returns:

  • (nil)


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

def sync
  request(:sync)
end