Class: ShopsavvyDataApi::UsageInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/shopsavvy_data_api/models.rb

Overview

API usage information

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ UsageInfo

Returns a new instance of UsageInfo.



318
319
320
321
# File 'lib/shopsavvy_data_api/models.rb', line 318

def initialize(data)
  @current_period = UsagePeriod.new(data["current_period"] || {})
  @usage_percentage = data["usage_percentage"]&.to_f || 0
end

Instance Attribute Details

#current_periodObject (readonly)

Returns the value of attribute current_period.



316
317
318
# File 'lib/shopsavvy_data_api/models.rb', line 316

def current_period
  @current_period
end

#usage_percentageObject (readonly)

Returns the value of attribute usage_percentage.



316
317
318
# File 'lib/shopsavvy_data_api/models.rb', line 316

def usage_percentage
  @usage_percentage
end

Instance Method Details

#billing_period_endObject

Deprecated.

Use ‘current_period.end_date` instead



344
345
346
# File 'lib/shopsavvy_data_api/models.rb', line 344

def billing_period_end
  current_period.end_date
end

#billing_period_startObject

Deprecated.

Use ‘current_period.start_date` instead



339
340
341
# File 'lib/shopsavvy_data_api/models.rb', line 339

def billing_period_start
  current_period.start_date
end

#credits_percentage_remainingObject



361
362
363
# File 'lib/shopsavvy_data_api/models.rb', line 361

def credits_percentage_remaining
  100 - credits_percentage_used
end

#credits_percentage_usedObject



355
356
357
358
359
# File 'lib/shopsavvy_data_api/models.rb', line 355

def credits_percentage_used
  return 0 if current_period.credits_limit.zero?

  (current_period.credits_used.to_f / current_period.credits_limit * 100).round(2)
end

#credits_remainingObject

Deprecated.

Use ‘current_period.credits_remaining` instead



329
330
331
# File 'lib/shopsavvy_data_api/models.rb', line 329

def credits_remaining
  current_period.credits_remaining
end

#credits_totalObject

Deprecated.

Use ‘current_period.credits_limit` instead



334
335
336
# File 'lib/shopsavvy_data_api/models.rb', line 334

def credits_total
  current_period.credits_limit
end

#credits_usedObject

Deprecated.

Use ‘current_period.credits_used` instead



324
325
326
# File 'lib/shopsavvy_data_api/models.rb', line 324

def credits_used
  current_period.credits_used
end

#to_hObject



348
349
350
351
352
353
# File 'lib/shopsavvy_data_api/models.rb', line 348

def to_h
  {
    current_period: current_period.to_h,
    usage_percentage: usage_percentage
  }
end