Class: Verizon::Configuration

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/verizon/configuration.rb,
lib/verizon/models/configuration.rb

Overview

List of the field names and values to set.

Constant Summary collapse

ENVIRONMENTS =

All the environments the SDK can run in.

{
  Environment::PRODUCTION => {
    Server::EDGE_DISCOVERY => 'https://5gedge.verizon.com/api/mec/eds',
    Server::THINGSPACE => 'https://thingspace.verizon.com/api',
    Server::OAUTH_SERVER => 'https://thingspace.verizon.com/api/ts/v1',
    Server::M2M => 'https://thingspace.verizon.com/api/m2m',
    Server::DEVICE_LOCATION => 'https://thingspace.verizon.com/api/loc/v1',
    Server::SUBSCRIPTION_SERVER => 'https://thingspace.verizon.com/api/subsc/v1',
    Server::SOFTWARE_MANAGEMENT_V1 => 'https://thingspace.verizon.com/api/fota/v1',
    Server::SOFTWARE_MANAGEMENT_V2 => 'https://thingspace.verizon.com/api/fota/v2',
    Server::SOFTWARE_MANAGEMENT_V3 => 'https://thingspace.verizon.com/api/fota/v3',
    Server::PERFORMANCE => 'https://5gedge.verizon.com/api/mec',
    Server::DEVICE_DIAGNOSTICS => 'https://thingspace.verizon.com/api/diagnostics/v1',
    Server::CLOUD_CONNECTOR => 'https://thingspace.verizon.com/api/cc/v1',
    Server::HYPER_PRECISE_LOCATION => 'https://thingspace.verizon.com/api/hyper-precise/v1',
    Server::SERVICES => 'https://5gedge.verizon.com/api/mec/services',
    Server::QUALITY_OF_SERVICE => 'https://thingspace.verizon.com/api/m2m/v1/devices'
  }
}.freeze

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(frequency = SKIP) ⇒ Configuration

Returns a new instance of Configuration.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/verizon/configuration.rb', line 61

def initialize(
  connection: nil, adapter: :net_http_persistent, timeout: 60,
  max_retries: 0, retry_interval: 1, backoff_factor: 2,
  retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
  retry_methods: %i[get put], http_callback: nil,
  environment: Environment::PRODUCTION, oauth_client_id: nil,
  oauth_client_secret: nil, oauth_token: nil, oauth_scopes: nil,
  client_credentials_auth_credentials: nil, vz_m2m_token: 'TODO: Replace'
)

  super connection: connection, adapter: adapter, timeout: timeout,
        max_retries: max_retries, retry_interval: retry_interval,
        backoff_factor: backoff_factor, retry_statuses: retry_statuses,
        retry_methods: retry_methods, http_callback: http_callback

  # Current API environment
  @environment = String(environment)

  # OAuth 2 Client ID
  @oauth_client_id = oauth_client_id

  # OAuth 2 Client Secret
  @oauth_client_secret = oauth_client_secret

  # Object for storing information about the OAuth token
  @oauth_token = if oauth_token.is_a? OauthToken
                   OauthToken.from_hash oauth_token.to_hash
                 else
                   oauth_token
                 end

  # List of scopes that apply to the OAuth token
  @oauth_scopes = oauth_scopes

  # M2M Session Token ([How to generate an M2M session token?](page:getting-started/5g-edge-developer-creds-token#obtaining-a-vz-m2m-session-token-programmatically))
  @vz_m2m_token = vz_m2m_token

  # Initializing OAuth 2 Client Credentials Grant credentials with the provided auth parameters
  @client_credentials_auth_credentials = create_auth_credentials_object(
    oauth_client_id, oauth_client_secret, oauth_token, oauth_scopes,
    client_credentials_auth_credentials
  )

  # The Http Client to use for making requests.
  set_http_client CoreLibrary::FaradayClient.new(self)
end

Class Attribute Details

.environmentsObject (readonly)

Returns the value of attribute environments.



58
59
60
# File 'lib/verizon/configuration.rb', line 58

def environments
  @environments
end

Instance Attribute Details

#client_credentials_auth_credentialsObject (readonly)

The attribute readers for properties.



55
56
57
# File 'lib/verizon/configuration.rb', line 55

def client_credentials_auth_credentials
  @client_credentials_auth_credentials
end

#environmentObject (readonly)

The attribute readers for properties.



55
56
57
# File 'lib/verizon/configuration.rb', line 55

def environment
  @environment
end

#frequencyString

TODO: Write general description for this method

Returns:

  • (String)


14
15
16
# File 'lib/verizon/models/configuration.rb', line 14

def frequency
  @frequency
end

#vz_m2m_tokenObject (readonly)

The attribute readers for properties.



55
56
57
# File 'lib/verizon/configuration.rb', line 55

def vz_m2m_token
  @vz_m2m_token
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



40
41
42
43
44
45
46
47
48
# File 'lib/verizon/models/configuration.rb', line 40

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  frequency = hash.key?('frequency') ? hash['frequency'] : SKIP

  # Create object from extracted values.
  Configuration.new(frequency)
end

.namesObject

A mapping from model property names to API property names.



17
18
19
20
21
# File 'lib/verizon/models/configuration.rb', line 17

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['frequency'] = 'frequency'
  @_hash
end

.nullablesObject

An array for nullable fields



31
32
33
# File 'lib/verizon/models/configuration.rb', line 31

def self.nullables
  []
end

.optionalsObject

An array for optional fields



24
25
26
27
28
# File 'lib/verizon/models/configuration.rb', line 24

def self.optionals
  %w[
    frequency
  ]
end

Instance Method Details

#clone_with(connection: nil, adapter: nil, timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, retry_statuses: nil, retry_methods: nil, http_callback: nil, environment: nil, oauth_client_id: nil, oauth_client_secret: nil, oauth_token: nil, oauth_scopes: nil, client_credentials_auth_credentials: nil, vz_m2m_token: nil) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/verizon/configuration.rb', line 108

def clone_with(connection: nil, adapter: nil, timeout: nil,
               max_retries: nil, retry_interval: nil, backoff_factor: nil,
               retry_statuses: nil, retry_methods: nil, http_callback: nil,
               environment: nil, oauth_client_id: nil,
               oauth_client_secret: nil, oauth_token: nil,
               oauth_scopes: nil, client_credentials_auth_credentials: nil,
               vz_m2m_token: nil)
  connection ||= self.connection
  adapter ||= self.adapter
  timeout ||= self.timeout
  max_retries ||= self.max_retries
  retry_interval ||= self.retry_interval
  backoff_factor ||= self.backoff_factor
  retry_statuses ||= self.retry_statuses
  retry_methods ||= self.retry_methods
  http_callback ||= self.http_callback
  environment ||= self.environment
  vz_m2m_token ||= self.vz_m2m_token
  client_credentials_auth_credentials = create_auth_credentials_object(
    oauth_client_id, oauth_client_secret, oauth_token, oauth_scopes,
    client_credentials_auth_credentials || self.client_credentials_auth_credentials
  )

  Configuration.new(
    connection: connection, adapter: adapter, timeout: timeout,
    max_retries: max_retries, retry_interval: retry_interval,
    backoff_factor: backoff_factor, retry_statuses: retry_statuses,
    retry_methods: retry_methods, http_callback: http_callback,
    environment: environment, vz_m2m_token: vz_m2m_token,
    client_credentials_auth_credentials: client_credentials_auth_credentials
  )
end

#create_auth_credentials_object(oauth_client_id, oauth_client_secret, oauth_token, oauth_scopes, client_credentials_auth_credentials) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/verizon/configuration.rb', line 141

def create_auth_credentials_object(oauth_client_id, oauth_client_secret,
                                   oauth_token, oauth_scopes,
                                   client_credentials_auth_credentials)
  return client_credentials_auth_credentials if oauth_client_id.nil? &&
                                                oauth_client_secret.nil? &&
                                                oauth_token.nil? &&
                                                oauth_scopes.nil?

  warn('The \'oauth_client_id\', \'oauth_client_secret\', \'oauth_token\','\
       ' \'oauth_scopes\' params are deprecated. Use \'client_credentials_'\
       'auth_credentials\' param instead.')

  unless client_credentials_auth_credentials.nil?
    return client_credentials_auth_credentials.clone_with(
      oauth_client_id: oauth_client_id,
      oauth_client_secret: oauth_client_secret,
      oauth_token: oauth_token,
      oauth_scopes: oauth_scopes
    )
  end

  ClientCredentialsAuthCredentials.new(
    oauth_client_id: oauth_client_id,
    oauth_client_secret: oauth_client_secret, oauth_token: oauth_token,
    oauth_scopes: oauth_scopes
  )
end

#get_base_uri(server = Server::EDGE_DISCOVERY) ⇒ String

Generates the appropriate base URI for the environment and the server. required.

Parameters:

  • server (Configuration::Server) (defaults to: Server::EDGE_DISCOVERY)

    The server enum for which the base URI is

Returns:

  • (String)

    The base URI.



194
195
196
# File 'lib/verizon/configuration.rb', line 194

def get_base_uri(server = Server::EDGE_DISCOVERY)
  ENVIRONMENTS[environment][server].clone
end

#oauth_client_idObject



38
39
40
# File 'lib/verizon/configuration.rb', line 38

def oauth_client_id
  @client_credentials_auth_credentials.oauth_client_id
end

#oauth_client_secretObject



42
43
44
# File 'lib/verizon/configuration.rb', line 42

def oauth_client_secret
  @client_credentials_auth_credentials.oauth_client_secret
end

#oauth_scopesObject



50
51
52
# File 'lib/verizon/configuration.rb', line 50

def oauth_scopes
  @client_credentials_auth_credentials.oauth_scopes
end

#oauth_tokenObject



46
47
48
# File 'lib/verizon/configuration.rb', line 46

def oauth_token
  @client_credentials_auth_credentials.oauth_token
end