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.



214
215
216
217
218
219
220
221
# File 'lib/shopsavvy_data_api/models.rb', line 214

def initialize(data)
  @credits_used = data["credits_used"].to_i
  @credits_remaining = data["credits_remaining"].to_i
  @credits_total = data["credits_total"].to_i
  @billing_period_start = data["billing_period_start"]
  @billing_period_end = data["billing_period_end"]
  @plan_name = data["plan_name"]
end

Instance Attribute Details

#billing_period_endObject (readonly)

Returns the value of attribute billing_period_end.



211
212
213
# File 'lib/shopsavvy_data_api/models.rb', line 211

def billing_period_end
  @billing_period_end
end

#billing_period_startObject (readonly)

Returns the value of attribute billing_period_start.



211
212
213
# File 'lib/shopsavvy_data_api/models.rb', line 211

def billing_period_start
  @billing_period_start
end

#credits_remainingObject (readonly)

Returns the value of attribute credits_remaining.



211
212
213
# File 'lib/shopsavvy_data_api/models.rb', line 211

def credits_remaining
  @credits_remaining
end

#credits_totalObject (readonly)

Returns the value of attribute credits_total.



211
212
213
# File 'lib/shopsavvy_data_api/models.rb', line 211

def credits_total
  @credits_total
end

#credits_usedObject (readonly)

Returns the value of attribute credits_used.



211
212
213
# File 'lib/shopsavvy_data_api/models.rb', line 211

def credits_used
  @credits_used
end

#plan_nameObject (readonly)

Returns the value of attribute plan_name.



211
212
213
# File 'lib/shopsavvy_data_api/models.rb', line 211

def plan_name
  @plan_name
end

Instance Method Details

#credits_percentage_remainingObject



240
241
242
# File 'lib/shopsavvy_data_api/models.rb', line 240

def credits_percentage_remaining
  100 - credits_percentage_used
end

#credits_percentage_usedObject



234
235
236
237
238
# File 'lib/shopsavvy_data_api/models.rb', line 234

def credits_percentage_used
  return 0 if credits_total.zero?

  (credits_used.to_f / credits_total * 100).round(2)
end

#to_hObject



223
224
225
226
227
228
229
230
231
232
# File 'lib/shopsavvy_data_api/models.rb', line 223

def to_h
  {
    credits_used: credits_used,
    credits_remaining: credits_remaining,
    credits_total: credits_total,
    billing_period_start: billing_period_start,
    billing_period_end: billing_period_end,
    plan_name: plan_name
  }
end