Module: Harvest::Behavior::Activatable

Included in:
API::Clients, API::Users
Defined in:
lib/harvest/behavior/activatable.rb

Overview

Activate/Deactivate behaviors that can be brought into API collections

Instance Method Summary (collapse)

Instance Method Details

- (Harvest::BaseModel) activate(model)

Activates the item. Does nothing if the item is already activated

Parameters:

  • model (Harvest::BaseModel)

    the model you want to activate

Returns:

  • (Harvest::BaseModel)

    the activated model



22
23
24
25
26
27
28
# File 'lib/harvest/behavior/activatable.rb', line 22

def activate(model)
  if !model.active?
    request(:post, credentials, "#{api_model.api_path}/#{model.to_i}/toggle")
    model.is_active = true
  end
  model
end

- (Harvest::BaseModel) deactivate(model)

Deactivates the item. Does nothing if the item is already deactivated

Parameters:

  • model (Harvest::BaseModel)

    the model you want to deactivate

Returns:

  • (Harvest::BaseModel)

    the deactivated model



10
11
12
13
14
15
16
# File 'lib/harvest/behavior/activatable.rb', line 10

def deactivate(model)
  if model.active?
    request(:post, credentials, "#{api_model.api_path}/#{model.to_i}/toggle")
    model.is_active = false
  end
  model
end