Class: Tinypass::Meter

Inherits:
Object
  • Object
show all
Defined in:
lib/tinypass/token/meter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ Meter

Returns a new instance of Meter.



3
4
5
# File 'lib/tinypass/token/meter.rb', line 3

def initialize(access_token)
  @access_token = access_token
end

Class Method Details

.create_time_based(rid, trial_period, lockout_period) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tinypass/token/meter.rb', line 20

def self.create_time_based(rid, trial_period, lockout_period)
  access_token = AccessToken.new(rid)
  trial_end_time = Utils::parse_loose_period_in_secs(trial_period) + Time.now.to_i
  lockout_end_time = trial_end_time + Utils::parse_loose_period_in_secs(lockout_period)

  access_token.token_data[TokenData::METER_TYPE] = TokenData::METER_REMINDER
  access_token.token_data[TokenData::METER_TRIAL_ENDTIME] = trial_end_time
  access_token.token_data[TokenData::METER_LOCKOUT_ENDTIME] = lockout_end_time

  new(access_token)
end

.create_view_based(rid, max_views, trial_period) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/tinypass/token/meter.rb', line 7

def self.create_view_based(rid, max_views, trial_period)
  access_token = AccessToken.new(rid)
  end_time = Utils.parse_loose_period_in_secs(trial_period) + Time.now.to_i

  access_token.token_data[TokenData::METER_TYPE] = TokenData::METER_REMINDER
  access_token.token_data[TokenData::METER_TRIAL_MAX_ACCESS_ATTEMPTS] = max_views
  access_token.token_data[TokenData::METER_TRIAL_ACCESS_ATTEMPTS] = 0
  access_token.token_data[TokenData::METER_TRIAL_ENDTIME] = end_time
  access_token.token_data[TokenData::METER_LOCKOUT_ENDTIME] = end_time

  new(access_token)
end

Instance Method Details

#dataObject



44
45
46
# File 'lib/tinypass/token/meter.rb', line 44

def data
  @access_token.token_data
end

#incrementObject



32
33
34
# File 'lib/tinypass/token/meter.rb', line 32

def increment
  data[TokenData::METER_TRIAL_ACCESS_ATTEMPTS] = trial_view_count + 1
end

#lockout_end_time_secsObject



72
73
74
# File 'lib/tinypass/token/meter.rb', line 72

def lockout_end_time_secs
  @access_token.lockout_end_time_secs
end

#lockout_period_active?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/tinypass/token/meter.rb', line 40

def lockout_period_active?
  @access_token.lockout_period_active?
end

#meter_typeObject



64
65
66
# File 'lib/tinypass/token/meter.rb', line 64

def meter_type
  @access_token.meter_type
end

#trial_dead?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/tinypass/token/meter.rb', line 60

def trial_dead?
  @access_token.trial_dead?
end

#trial_end_time_secsObject



68
69
70
# File 'lib/tinypass/token/meter.rb', line 68

def trial_end_time_secs
  @access_token.trial_end_time_secs
end

#trial_period_active?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/tinypass/token/meter.rb', line 36

def trial_period_active?
  @access_token.trial_period_active?
end

#trial_view_countObject



52
53
54
# File 'lib/tinypass/token/meter.rb', line 52

def trial_view_count
  @access_token.trial_view_count
end

#trial_view_limitObject



56
57
58
# File 'lib/tinypass/token/meter.rb', line 56

def trial_view_limit
  @access_token.trial_view_limit
end

#view_based?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/tinypass/token/meter.rb', line 48

def view_based?
  @access_token.meter_view_based?
end