95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/huginn_reddit_agent/reddit_agent.rb', line 95
def validate_options
errors.add(:base, "type has invalid value: should be 'read_unreadmessage' 'hottest_post_subreddit'") if interpolated['type'].present? && !%w(read_unreadmessage hottest_post_subreddit).include?(interpolated['type'])
unless options['subreddit'].present? || !['hottest_post_subreddit'].include?(options['type'])
errors.add(:base, "subreddit is a required field")
end
unless options['password'].present? || !['read_unreadmessage', 'hottest_post_subreddit'].include?(options['type'])
errors.add(:base, "password is a required field")
end
unless options['username'].present? || !['read_unreadmessage', 'hottest_post_subreddit'].include?(options['type'])
errors.add(:base, "username is a required field")
end
unless options['client_id'].present? || !['read_unreadmessage', 'hottest_post_subreddit'].include?(options['type'])
errors.add(:base, "client_id is a required field")
end
unless options['secret_key'].present? || !['read_unreadmessage', 'hottest_post_subreddit'].include?(options['type'])
errors.add(:base, "secret_key is a required field")
end
unless options['bearer_token'].present?
errors.add(:base, "bearer_token is a required field")
end
unless options['limit'].present? || !['hottest_post_subreddit'].include?(options['type'])
errors.add(:base, "limit is a required field")
end
if options.has_key?('emit_events') && boolify(options['emit_events']).nil?
errors.add(:base, "if provided, emit_events must be true or false")
end
if options.has_key?('details') && boolify(options['details']).nil?
errors.add(:base, "if provided, details must be true or false")
end
if options.has_key?('debug') && boolify(options['debug']).nil?
errors.add(:base, "if provided, debug must be true or false")
end
unless options['expected_receive_period_in_days'].present? && options['expected_receive_period_in_days'].to_i > 0
errors.add(:base, "Please provide 'expected_receive_period_in_days' to indicate how many days can pass before this Agent is considered to be not working")
end
end
|