class Mention::AlertCreator
Attributes
account_resource[R]
alert[R]
Public Class Methods
new(account_resource, alert)
click to toggle source
# File lib/mention/alert_creator.rb, line 3 def initialize(account_resource, alert) @account_resource, @alert = account_resource, alert end
Public Instance Methods
created_alert()
click to toggle source
# File lib/mention/alert_creator.rb, line 7 def created_alert @created_alert ||= Alert.new(response['alert']) end
valid?()
click to toggle source
# File lib/mention/alert_creator.rb, line 11 def valid? validate_response! true end
Private Instance Methods
aggregate_errors(hash_node, list = [])
click to toggle source
# File lib/mention/alert_creator.rb, line 43 def aggregate_errors(hash_node, list = []) if !hash_node.is_a?(Hash) [] elsif hash_node['errors'] hash_node['errors'] else error_lists = hash_node.map do |key, node| aggregate_errors(node) end error_lists.inject([]) do |list, node_list| list + node_list end end end
request_params()
click to toggle source
# File lib/mention/alert_creator.rb, line 29 def request_params alert.attributes .reject{|k,v| k == :id} .reject{|k,v| k == :shares} end
response()
click to toggle source
# File lib/mention/alert_creator.rb, line 19 def response @response ||= JSON.parse(response_str) end
response_str()
click to toggle source
# File lib/mention/alert_creator.rb, line 23 def response_str @response_str ||= account_resource['alerts'].post( JSON.generate(request_params), :content_type => 'application/json') end
validate_response!()
click to toggle source
# File lib/mention/alert_creator.rb, line 35 def validate_response! raise ValidationError.new(validation_errors.join(", ")) unless response['alert'] end
validation_errors()
click to toggle source
# File lib/mention/alert_creator.rb, line 39 def validation_errors aggregate_errors(response) end