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::HYPER_PRECISE_CREDENTIALS => 'https://thingspace.verizon.com/api/auth/v1',
    Server::IMP_SERVER => 'https://imp.thingspace.verizon.com',
    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::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'
  },
  Environment::STAGING => {
    Server::HYPER_PRECISE_CREDENTIALS => 'https://staging.thingspace.verizon.com/api/auth/v1',
    Server::IMP_SERVER => 'https://imp-staging.thingspace.verizon.com',
    Server::THINGSPACE => 'https://staging.thingspace.verizon.com/api',
    Server::OAUTH_SERVER => 'https://staging.thingspace.verizon.com/api/ts/v1',
    Server::M2M => 'https://staging.thingspace.verizon.com/api/m2m',
    Server::DEVICE_LOCATION => 'https://staging.thingspace.verizon.com/api/loc/v1',
    Server::SUBSCRIPTION_SERVER => 'https://staging.thingspace.verizon.com/api/subsc/v1',
    Server::SOFTWARE_MANAGEMENT_V1 => 'https://staging.thingspace.verizon.com/api/fota/v1',
    Server::SOFTWARE_MANAGEMENT_V2 => 'https://staging.thingspace.verizon.com/api/fota/v2',
    Server::SOFTWARE_MANAGEMENT_V3 => 'https://staging.thingspace.verizon.com/api/fota/v3',
    Server::DEVICE_DIAGNOSTICS => 'https://staging.thingspace.verizon.com/api/diagnostics/v1',
    Server::CLOUD_CONNECTOR => 'https://staging.thingspace.verizon.com/api/cc/v1',
    Server::HYPER_PRECISE_LOCATION => 'https://staging.thingspace.verizon.com/api/hyper-precise/v1',
    Server::SERVICES => 'https://staging.5gedge.verizon.com/api/mec/services',
    Server::QUALITY_OF_SERVICE => 'https://staging.thingspace.verizon.com/api/m2m/v1/devices'
  },
  Environment::DEV => {
    Server::HYPER_PRECISE_CREDENTIALS => 'https://staging.thingspace.verizon.com/api/auth/v1',
    Server::IMP_SERVER => 'https://devmanagement-staging.imp.thingspace.verizon.com',
    Server::THINGSPACE => 'https://devmanagement-staging.thingspace.verizon.com/api',
    Server::OAUTH_SERVER => 'https://devmanagement-staging.thingspace.verizon.com:80/ts/v1',
    Server::M2M => 'https://devmanagement-staging.thingspace.verizon.com:80/m2m',
    Server::DEVICE_LOCATION => 'https://devmanagement-staging.thingspace.verizon.com:80/loc/v1',
    Server::SUBSCRIPTION_SERVER => 'https://devmanagement-staging.thingspace.verizon.com:80/subsc/v1',
    Server::SOFTWARE_MANAGEMENT_V1 => 'https://devmanagement-staging.thingspace.verizon.com:80/fota/v1',
    Server::SOFTWARE_MANAGEMENT_V2 => 'https://devmanagement-staging.thingspace.verizon.com:80/fota/v2',
    Server::SOFTWARE_MANAGEMENT_V3 => 'https://devmanagement-staging.thingspace.verizon.com:80/fota/v3',
    Server::DEVICE_DIAGNOSTICS => 'https://devmanagement-staging.thingspace.verizon.com:80/diagnostics/v1',
    Server::CLOUD_CONNECTOR => 'https://devmanagement-staging.thingspace.verizon.com:80/cc/v1',
    Server::HYPER_PRECISE_LOCATION => 'https://devmanagement-staging.thingspace.verizon.com:80/hyper-precise/v1',
    Server::SERVICES => 'https://devmanagement-staging.5gedge.verizon.com:80/mec/services',
    Server::QUALITY_OF_SERVICE => 'https://devmanagement-staging.thingspace.verizon.com/api/m2m/v1/devices'
  },
  Environment::QA => {
    Server::HYPER_PRECISE_CREDENTIALS => 'https://thingspace.verizon.com/api/auth/v1',
    Server::IMP_SERVER => 'https://tsd-nginx-qa-us-east-1.imp.thingspace.verizon.com',
    Server::THINGSPACE => 'https://tsd-nginx-qa-us-east-1.thingspace.verizon.com/api',
    Server::OAUTH_SERVER => 'https://tsd-nginx-qa-us-east-1.thingspace.verizon.com/api/ts/v1',
    Server::M2M => 'https://tsd-nginx-qa-us-east-1.thingspace.verizon.com/api/m2m',
    Server::DEVICE_LOCATION => 'https://tsd-nginx-qa-us-east-1.thingspace.verizon.com/api/loc/v1',
    Server::SUBSCRIPTION_SERVER => 'https://tsd-nginx-qa-us-east-1.thingspace.verizon.com/api/subsc/v1',
    Server::SOFTWARE_MANAGEMENT_V1 => 'https://tsd-nginx-qa-us-east-1.thingspace.verizon.com/api/fota/v1',
    Server::SOFTWARE_MANAGEMENT_V2 => 'https://tsd-nginx-qa-us-east-1.thingspace.verizon.com/api/fota/v2',
    Server::SOFTWARE_MANAGEMENT_V3 => 'https://tsd-nginx-qa-us-east-1.thingspace.verizon.com/api/fota/v3',
    Server::DEVICE_DIAGNOSTICS => 'https://tsd-nginx-qa-us-east-1.thingspace.verizon.com/api/diagnostics/v1',
    Server::CLOUD_CONNECTOR => 'https://tsd-nginx-qa-us-east-1.thingspace.verizon.com/api/cc/v1',
    Server::HYPER_PRECISE_LOCATION => 'https://tsd-nginx-qa-us-east-1.thingspace.verizon.com/api/hyper-precise/v1',
    Server::SERVICES => 'https://tsd-nginx-qa-us-east-1.5gedge.verizon.com/api/mec/services',
    Server::QUALITY_OF_SERVICE => 'https://tsd-nginx-qa-us-east-1.thingspace.verizon.com/api/m2m/v1/devices'
  },
  Environment::MOCK_SERVER_FOR_LIMITED_AVAILABILITY_SEE_QUICK_START => {
    Server::HYPER_PRECISE_CREDENTIALS => 'https://staging.thingspace.verizon.com/api/auth/v1',
    Server::IMP_SERVER => 'https://mock-staging.thingspace.verizon.com',
    Server::THINGSPACE => 'https://mock-staging.thingspace.verizon.com/api',
    Server::OAUTH_SERVER => 'https://mock-staging.thingspace.verizon.com/api/ts/v1',
    Server::M2M => 'https://mock-staging.thingspace.verizon.com/api/m2m',
    Server::DEVICE_LOCATION => 'https://mock-staging.thingspace.verizon.com/api/loc/v1',
    Server::SUBSCRIPTION_SERVER => 'https://mock-staging.thingspace.verizon.com/api/subsc/v1',
    Server::SOFTWARE_MANAGEMENT_V1 => 'https://mock-staging.thingspace.verizon.com/api/fota/v1',
    Server::SOFTWARE_MANAGEMENT_V2 => 'https://mock-staging.thingspace.verizon.com/api/fota/v2',
    Server::SOFTWARE_MANAGEMENT_V3 => 'https://mock-staging.thingspace.verizon.com/api/fota/v3',
    Server::DEVICE_DIAGNOSTICS => 'https://mock-staging.thingspace.verizon.com/api/diagnostics/v1',
    Server::CLOUD_CONNECTOR => 'https://mock-staging.thingspace.verizon.com/api/cc/v1',
    Server::HYPER_PRECISE_LOCATION => 'https://mock-staging.thingspace.verizon.com/api/hyper-precise/v1',
    Server::SERVICES => 'https://mock-staging.thingspace.verizon.com/api/mec/services',
    Server::QUALITY_OF_SERVICE => 'https://mock-staging.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

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(frequency = SKIP) ⇒ Configuration

Returns a new instance of Configuration.



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/verizon/configuration.rb', line 97

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, proxy_settings: nil,
  environment: Environment::PRODUCTION, thingspace_oauth_credentials: nil,
  vz_m2m_token_credentials: nil, session_token_credentials: nil,
  thingspace_oauth_1credentials: nil
)
  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,
        proxy_settings: proxy_settings

  # Current API environment
  @environment = String(environment)

  # The object holding OAuth 2 Client Credentials Grant credentials
  @thingspace_oauth_credentials = thingspace_oauth_credentials

  # The object holding Custom Header Signature credentials
  @vz_m2m_token_credentials = vz_m2m_token_credentials

  # The object holding Custom Header Signature credentials
  @session_token_credentials = session_token_credentials

  # The object holding OAuth 2 Client Credentials Grant credentials
  @thingspace_oauth_1credentials = thingspace_oauth_1credentials

  # 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.



94
95
96
# File 'lib/verizon/configuration.rb', line 94

def environments
  @environments
end

Instance Attribute Details

#environmentObject (readonly)

The attribute readers for properties.



89
90
91
# File 'lib/verizon/configuration.rb', line 89

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

#session_token_credentialsObject (readonly)

The attribute readers for properties.



89
90
91
# File 'lib/verizon/configuration.rb', line 89

def session_token_credentials
  @session_token_credentials
end

#thingspace_oauth_1credentialsObject (readonly)

The attribute readers for properties.



89
90
91
# File 'lib/verizon/configuration.rb', line 89

def thingspace_oauth_1credentials
  @thingspace_oauth_1credentials
end

#thingspace_oauth_credentialsObject (readonly)

The attribute readers for properties.



89
90
91
# File 'lib/verizon/configuration.rb', line 89

def thingspace_oauth_credentials
  @thingspace_oauth_credentials
end

#vz_m2m_token_credentialsObject (readonly)

The attribute readers for properties.



89
90
91
# File 'lib/verizon/configuration.rb', line 89

def vz_m2m_token_credentials
  @vz_m2m_token_credentials
end

Class Method Details

.build_default_config_from_envObject

Builds a Configuration instance using environment variables.



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/verizon/configuration.rb', line 267

def self.build_default_config_from_env
  # === Core environment ===
  environment = Environment.from_value(ENV.fetch('ENVIRONMENT', 'production'))
  timeout = (ENV['TIMEOUT'] || 60).to_f
  max_retries = (ENV['MAX_RETRIES'] || 0).to_i
  retry_interval = (ENV['RETRY_INTERVAL'] || 1).to_f
  backoff_factor = (ENV['BACKOFF_FACTOR'] || 2).to_f
  retry_statuses = ENV.fetch('RETRY_STATUSES',
                             '[408, 413, 429, 500, 502, 503, 504, 521, 522, 524]').gsub(/[\[\]]/, '')
                                      .split(',')
                                      .map(&:strip)
                                      .map do |item|
                                        item.match?(/\A\d+\z/) ? item.to_i : item.downcase
                                      end
  retry_methods = ENV.fetch('RETRY_METHODS', '%i[get put]').gsub(/[\[\]]/, '')
                                      .split(',')
                                      .map(&:strip)
                                      .map do |item|
                                        item.match?(/\A\d+\z/) ? item.to_i : item.downcase
                                      end

  # === Authentication credentials ===
  thingspace_oauth_credentials = ThingspaceOauthCredentials.from_env
  vz_m2m_token_credentials = VZM2mTokenCredentials.from_env
  session_token_credentials = SessionTokenCredentials.from_env
  thingspace_oauth_1credentials = ThingspaceOauth1Credentials.from_env

  # === Proxy settings ===
  proxy_settings = ProxySettings.from_env

  Configuration.new(
    environment: environment,
    timeout: timeout,
    max_retries: max_retries,
    retry_interval: retry_interval,
    backoff_factor: backoff_factor,
    retry_statuses: retry_statuses,
    retry_methods: retry_methods,
    thingspace_oauth_credentials: thingspace_oauth_credentials,
    vz_m2m_token_credentials: vz_m2m_token_credentials,
    session_token_credentials: session_token_credentials,
    thingspace_oauth_1credentials: thingspace_oauth_1credentials,
    proxy_settings: proxy_settings
  )
end

.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, proxy_settings: nil, environment: nil, thingspace_oauth_credentials: nil, vz_m2m_token_credentials: nil, session_token_credentials: nil, thingspace_oauth_1credentials: nil) ⇒ Object



131
132
133
134
135
136
137
138
139
140
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
# File 'lib/verizon/configuration.rb', line 131

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,
               proxy_settings: nil, environment: nil,
               thingspace_oauth_credentials: nil,
               vz_m2m_token_credentials: nil,
               session_token_credentials: nil,
               thingspace_oauth_1credentials: 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
  proxy_settings ||= self.proxy_settings
  environment ||= self.environment
  thingspace_oauth_credentials ||= self.thingspace_oauth_credentials
  vz_m2m_token_credentials ||= self.vz_m2m_token_credentials
  session_token_credentials ||= self.session_token_credentials
  thingspace_oauth_1credentials ||= self.thingspace_oauth_1credentials

  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,
    proxy_settings: proxy_settings, environment: environment,
    thingspace_oauth_credentials: thingspace_oauth_credentials,
    vz_m2m_token_credentials: vz_m2m_token_credentials,
    session_token_credentials: session_token_credentials,
    thingspace_oauth_1credentials: thingspace_oauth_1credentials
  )
end

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

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

Parameters:

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

    The server enum for which the base URI is

Returns:

  • (String)

    The base URI.



262
263
264
# File 'lib/verizon/configuration.rb', line 262

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

#inspectObject

Provides a debugging-friendly string with detailed object information.



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

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} frequency: #{@frequency.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



51
52
53
54
# File 'lib/verizon/models/configuration.rb', line 51

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} frequency: #{@frequency}>"
end