Class: DocusignDtr::QueryParamHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/docusign_dtr/query_param_helper.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

QUERY_PARAMS =

rubocop:disable Naming/PredicateName

{
  search: :search,
  count: :count,
  end_date: :endDate,
  start_position: :startPosition,
  room_status: :roomStatus,
  owned_only: :ownedOnly,
  transaction_side: :transactionSide,
  is_under_contract: :isUnderContract,
  region_id: :regionId,
  office_id: :officeId,
  has_submitted_task_list: :hasSubmittedTaskList,
  has_contract_amount: :hasContractAmount,
  sort: :sort,
  date_range_type: :dateRangeType,
  start_date: :startDate
}.freeze

Class Method Summary collapse

Class Method Details

.acceptable_value?(key, value) ⇒ Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/docusign_dtr/query_param_helper.rb', line 124

def acceptable_value?(key, value)
  query_acceptable_values[key].include?(value)
end

.call(options) ⇒ Object



24
25
26
27
28
29
# File 'lib/docusign_dtr/query_param_helper.rb', line 24

def call(options)
  @options = options
  QUERY_PARAMS.each_with_object({}) do |(key, value), memo|
    memo[value] = send(key) if @options.key? key
  end
end

.countObject



35
36
37
# File 'lib/docusign_dtr/query_param_helper.rb', line 35

def count
  @options[:count].to_i
end

.date_range_typeObject



91
92
93
94
95
96
97
98
99
# File 'lib/docusign_dtr/query_param_helper.rb', line 91

def date_range_type
  unless acceptable_value?(:date_range_type, @options[:date_range_type])
    raise DocusignDtr::InvalidParameter.new(
      "value #{@options[:date_range_type]} is not valid for #{__method__}"
    )
  end

  @options[:date_range_type].to_s
end

.end_dateObject



105
106
107
# File 'lib/docusign_dtr/query_param_helper.rb', line 105

def end_date
  to_date(@options[:end_date].to_s, __method__)
end

.has_contract_amountObject



79
80
81
# File 'lib/docusign_dtr/query_param_helper.rb', line 79

def has_contract_amount
  to_boolean(@options[:has_contract_amount], __method__)
end

.has_submitted_task_listObject



75
76
77
# File 'lib/docusign_dtr/query_param_helper.rb', line 75

def 
  to_boolean(@options[:has_submitted_task_list], __method__)
end

.is_under_contractObject



63
64
65
# File 'lib/docusign_dtr/query_param_helper.rb', line 63

def is_under_contract
  to_boolean(@options[:is_under_contract], __method__)
end

.office_idObject



71
72
73
# File 'lib/docusign_dtr/query_param_helper.rb', line 71

def office_id
  @options[:office_id].to_i
end

.owned_onlyObject



51
52
53
# File 'lib/docusign_dtr/query_param_helper.rb', line 51

def owned_only
  to_boolean(@options[:owned_only], __method__)
end

.query_acceptable_valuesObject



128
129
130
# File 'lib/docusign_dtr/query_param_helper.rb', line 128

def query_acceptable_values
  DocusignDtr::Models::Room::ACCEPTABLE_VALUES
end

.region_idObject



67
68
69
# File 'lib/docusign_dtr/query_param_helper.rb', line 67

def region_id
  @options[:region_id].to_i
end

.room_statusObject



43
44
45
46
47
48
49
# File 'lib/docusign_dtr/query_param_helper.rb', line 43

def room_status
  unless acceptable_value?(:room_status, @options[:room_status])
    raise DocusignDtr::InvalidParameter.new("value #{@options[:room_status]} is not valid for #{__method__}")
  end

  @options[:room_status].to_s
end

.searchObject



31
32
33
# File 'lib/docusign_dtr/query_param_helper.rb', line 31

def search
  @options[:search].to_s
end

.sortObject



83
84
85
86
87
88
89
# File 'lib/docusign_dtr/query_param_helper.rb', line 83

def sort
  unless acceptable_value?(:sort, @options[:sort].to_s)
    raise DocusignDtr::InvalidParameter.new("value #{@options[:sort]} is not valid for #{__method__}")
  end

  @options[:sort].to_s
end

.start_dateObject



101
102
103
# File 'lib/docusign_dtr/query_param_helper.rb', line 101

def start_date
  to_date(@options[:start_date].to_s, __method__)
end

.start_positionObject



39
40
41
# File 'lib/docusign_dtr/query_param_helper.rb', line 39

def start_position
  @options[:start_position].to_i
end

.to_boolean(value, key) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/docusign_dtr/query_param_helper.rb', line 109

def to_boolean(value, key)
  unless value.is_a?(FalseClass) || value.is_a?(TrueClass)
    raise DocusignDtr::InvalidParameter.new("value #{value} is not valid for #{key}")
  end

  value
end

.to_date(value, key) ⇒ Object



117
118
119
120
121
122
# File 'lib/docusign_dtr/query_param_helper.rb', line 117

def to_date(value, key)
  date = Time.parse(value)
  date.iso8601
rescue ArgumentError
  raise DocusignDtr::InvalidParameter.new("#{value} is not a valid #{key}")
end

.transaction_sideObject



55
56
57
58
59
60
61
# File 'lib/docusign_dtr/query_param_helper.rb', line 55

def transaction_side
  unless acceptable_value?(:transaction_side, @options[:transaction_side])
    raise DocusignDtr::InvalidParameter.new("value #{@options[:transaction_side]} is not valid for #{__method__}")
  end

  @options[:transaction_side].to_s
end