Class: MoxiworksPlatform::Credentials

Inherits:
Object
  • Object
show all
Defined in:
lib/moxiworks_platform/credentials.rb

Overview

Moxi Works Platform Credentials

A Singleton class used for authorization on the Moxi Works Platform

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(platform_identifier, platform_secret) ⇒ Credentials

Returns a new instance of Credentials.

Parameters:

  • platform_id (String)

    Your provided Moxi Works Platform Identifier

  • platform_secret (String)

    Your provided Moxi Works Platform Secret



69
70
71
72
73
74
# File 'lib/moxiworks_platform/credentials.rb', line 69

def initialize(platform_identifier, platform_secret)
  return if MoxiworksPlatform::Credentials.instance
  MoxiworksPlatform::Credentials.platform_identifier = platform_identifier
  MoxiworksPlatform::Credentials.platform_secret = platform_secret
  MoxiworksPlatform::Credentials.instance = self
end

Class Attribute Details

.instanceObject

Singleton instance of MoxiworksPlatform::Credentials



14
15
16
# File 'lib/moxiworks_platform/credentials.rb', line 14

def instance
  @instance
end

.platform_identifierString

The Moxi Works Platform Identifier associated with the MoxiworksPlatform::Credentials instance

This should be set when MoxiworksPlafform::Credentials is instantiated

Returns:

  • (String)


23
24
25
# File 'lib/moxiworks_platform/credentials.rb', line 23

def platform_identifier
  @platform_identifier
end

.platform_secretString

The Moxi Works Platform Secret associated with the MoxiworksPlatform::Credentials instance

This should be set when MoxiworksPlafform::Credentials is instantiated

Returns:

  • (String)


32
33
34
# File 'lib/moxiworks_platform/credentials.rb', line 32

def platform_secret
  @platform_secret
end

Class Method Details

.new(*args, &block) ⇒ MoxiWorksPlatform::Credentials

Examples:

platform_identifier = 'abc1234'
platform_secret = 'secret'
MoxiworksPlatform::Credentials.new(platform_identifier, platform_secret)

Parameters:

  • platform_id (String)

    Your provided Moxi Works Platform Identifier

  • platform_secret (String)

    Your provided Moxi Works Platform Secret

Returns:

  • (MoxiWorksPlatform::Credentials)


45
46
47
48
49
50
51
52
53
54
# File 'lib/moxiworks_platform/credentials.rb', line 45

def self.new(*args, &block)
  pid = args[0]
  ps = args[1]
  return MoxiworksPlatform::Credentials.instance if
      MoxiworksPlatform::Credentials.instance and
          (pid == MoxiworksPlatform::Credentials.platform_identifier and
          ps == MoxiworksPlatform::Credentials.platform_secret)

  super(*args, &block)
end

.set?Boolean

whether the required values for authorization have been set in the Singleton instance of MoxiworksPlatform::Credentials

Returns:

  • (Boolean)

    Returns `true` if the access key id and secret access key are both set.



59
60
61
62
63
64
# File 'lib/moxiworks_platform/credentials.rb', line 59

def self.set?
  not ((platform_identifier.nil? or
      platform_identifier.empty?) or
      (platform_secret.nil? or
          platform_secret.empty?))
end

Instance Method Details

#inspectObject

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.

Removing the secret access key from the default inspect string.



103
104
105
# File 'lib/moxiworks_platform/credentials.rb', line 103

def inspect
  "#<#{self.class.name} platform_identifier=#{platform_identifier.inspect}>"
end

#platform_identifierString

The Moxi Works Platform Identifier associated with the MoxiworksPlatform::Credentials instance

This should be set when MoxiworksPlafform::Credentials is instantiated

Returns:

  • (String)


81
82
83
# File 'lib/moxiworks_platform/credentials.rb', line 81

def platform_identifier
  MoxiworksPlatform::Credentials.platform_identifier
end

#platform_secretString

The Moxi Works Platform Secret associated with the MoxiworksPlatform::Credentials instance

This should be set when MoxiworksPlafform::Credentials is instantiated

Returns:

  • (String)


90
91
92
# File 'lib/moxiworks_platform/credentials.rb', line 90

def platform_secret
  MoxiworksPlatform::Credentials.platform_secret
end

#set?Boolean

whether the required values for authorization have been set in the Singleton instance of MoxiworksPlatform::Credentials

Returns:

  • (Boolean)

    Returns `true` if the access key id and secret access key are both set.



97
98
99
# File 'lib/moxiworks_platform/credentials.rb', line 97

def set?
  MoxiworksPlatform::Credentials.set?
end