Module: Wistia

Defined in:
lib/wistia/base.rb,
lib/wistia/media.rb,
lib/wistia/stats.rb,
lib/wistia/config.rb,
lib/wistia/project.rb,
lib/wistia/initialization.rb,
lib/wistia/projects/sharing.rb

Defined Under Namespace

Modules: Projects, Stats Classes: Base, Media, Project

Constant Summary collapse

API_BASE_URL =
'https://api.wistia.com/v1/'
@@password =
nil
@@format =
:json

Class Method Summary collapse

Class Method Details

.formatObject



50
# File 'lib/wistia/config.rb', line 50

def self.format; @@format; end

.format=(new_format) ⇒ Object

Set the format that the API uses to either ‘json’ or ‘xml’. Accepts either a String or a Symbol.

Raises:

  • (ArgumentError)


43
44
45
46
47
48
49
# File 'lib/wistia/config.rb', line 43

def self.format=(new_format)
  valid_formats = [:json, :xml]
  raise ArgumentError, "Invalid format.  Supported formats: #{valid_formats.join(', ')}." unless valid_formats.include?(new_format.to_sym)
  @@format = new_format
  Wistia.refresh_config_for_wistia_api_objects!
  @@format
end

.passwordObject



39
# File 'lib/wistia/config.rb', line 39

def self.password; @@password; end

.password=(new_password) ⇒ Object

Set your API password using this method. For instructions to find your API password, go here: wistia.com/doc/api-enable



34
35
36
37
38
# File 'lib/wistia/config.rb', line 34

def self.password= (new_password)
  @@password = new_password
  Wistia.refresh_config_for_wistia_api_objects!
  @@password
end

.refresh_config_for_wistia_api_objects!Object



55
56
57
# File 'lib/wistia/config.rb', line 55

def self.refresh_config_for_wistia_api_objects!
  self.wistia_api_objects.each {|d| d.refresh_config!}
end

.use_config!(config) ⇒ Object

Specifies a new configuration to use for the API. Accepts either a Hash or a String pointing to a YAML configuration file.

Example using a Hash:

Wistia.use_config!(:wistia => { :api => { :key => 'your-api-key', :format => 'json-or-xml' } })


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/wistia/config.rb', line 9

def self.use_config!(config)
  if config.is_a?(String) && File.exists?(config) && File.extname(config) == '.yml'
    self.use_config!(YAML.load_file(config))
  elsif config.is_a?(Hash)
    config = config.with_indifferent_access

    if data_hash = config && config[:wistia] && config[:wistia][:api]
      if data_hash[:key]
        data_hash[:password] = data_hash[:key]
        warn '[DEPRECATION] You have configured wistia-api authentication using the configuration key: "key".'
        warn '              Please use the configuration key "password" instead (using the same value).'
      end

      new_password = data_hash[:password]
      self.password = new_password unless new_password.nil?
      new_format = data_hash[:format]
      self.format = new_format.to_sym unless new_format.nil?
    end
  else
    raise ArgumentError, 'Invalid config'
  end
end

.wistia_api_objectsObject



52
53
54
# File 'lib/wistia/config.rb', line 52

def self.wistia_api_objects
  ObjectSpace.each_object(Class).select{|klass| klass < Wistia::Base} << Wistia::Base
end