Module: SevenApi::Subaccounts::Validator

Defined in:
lib/seven_api/subaccounts.rb

Class Method Summary collapse

Class Method Details

.create(params) ⇒ Object



35
36
37
38
# File 'lib/seven_api/subaccounts.rb', line 35

def self.create(params)
  SevenApi::Util::lengthy_string?(params[:email]) &&
    SevenApi::Util::lengthy_string?(params[:name])
end

.delete(params) ⇒ Object



40
41
42
# File 'lib/seven_api/subaccounts.rb', line 40

def self.delete(params)
  SevenApi::Util::is_positive_integer?(params[:id])
end

.is_action?(str) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/seven_api/subaccounts.rb', line 14

def self.is_action?(str)
  SevenApi::Util::in_module_constants?(str, SevenApi::Subaccounts::Action)
end

.transfer_credits(params) ⇒ Object



44
45
46
47
# File 'lib/seven_api/subaccounts.rb', line 44

def self.transfer_credits(params)
  SevenApi::Util::is_positive_integer?(params[:amount]) &&
    SevenApi::Util::is_positive_integer?(params[:id])
end

.update(params) ⇒ Object



49
50
51
52
53
# File 'lib/seven_api/subaccounts.rb', line 49

def self.update(params)
  SevenApi::Util::is_positive_integer?(params[:amount]) &&
    SevenApi::Util::is_positive_integer?(params[:id]) &&
    SevenApi::Util::is_positive_integer?(params[:threshold])
end

.validate(params) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/seven_api/subaccounts.rb', line 18

def self.validate(params)
  action = params[:action]

  case action
  when SevenApi::Subaccounts::Action::CREATE
    raise 'Parameter validation failed' unless SevenApi::Subaccounts::Validator::create(params)
  when SevenApi::Subaccounts::Action::DELETE
    raise 'Parameter validation failed' unless SevenApi::Subaccounts::Validator::delete(params)
  when SevenApi::Subaccounts::Action::TRANSFER_CREDITS
    raise 'Parameter validation failed' unless SevenApi::Subaccounts::Validator::transfer_credits(params)
  when SevenApi::Subaccounts::Action::UPDATE
    raise 'Parameter validation failed' unless SevenApi::Subaccounts::Validator::update(params)
  else
    raise "Unknown action #{action}" unless SevenApi::Subaccounts::Validator::is_action?(action)
  end
end