Class: Promoted::Ruby::Client::Validator
- Inherits:
-
Object
- Object
- Promoted::Ruby::Client::Validator
- Defined in:
- lib/promoted/ruby/client/validator.rb
Instance Method Summary collapse
- #check_that_content_ids_are_set!(req) ⇒ Object
- #check_that_log_ids_not_set!(req) ⇒ Object
- #validate_insertion!(ins) ⇒ Object
-
#validate_metrics_request!(metrics_req) ⇒ Object
TODO - delete?.
- #validate_request!(req) ⇒ Object
- #validate_response!(res) ⇒ Object
- #validate_user_info!(ui) ⇒ Object
Instance Method Details
#check_that_content_ids_are_set!(req) ⇒ Object
163 164 165 166 167 |
# File 'lib/promoted/ruby/client/validator.rb', line 163 def check_that_content_ids_are_set! req req[:request][:insertion].each do |insertion_hash| raise ValidationError.new("Insertion.contentId should be set") if !insertion_hash[:content_id] || insertion_hash[:content_id].empty? end end |
#check_that_log_ids_not_set!(req) ⇒ Object
153 154 155 156 157 158 159 160 161 |
# File 'lib/promoted/ruby/client/validator.rb', line 153 def check_that_log_ids_not_set! req raise ValidationError.new("Request should be set") if !req[:request] raise ValidationError.new("Request.requestId should not be set") if req.dig(:request, :request_id) req[:request][:insertion].each do |insertion_hash| raise ValidationError.new("Insertion.requestId should not be set") if insertion_hash[:request_id] raise ValidationError.new("'Insertion.insertionId should not be set") if insertion_hash[:insertion_id] end end |
#validate_insertion!(ins) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/promoted/ruby/client/validator.rb', line 26 def validate_insertion!(ins) validate_fields!( ins, "insertion", [ { :name => :platform_id, :type => Integer }, { :name => :insertion_id, :type => String }, { :name => :request_id, :type => String }, { :name => :view_id, :type => String }, { :name => :session_id, :type => String }, { :name => :content_id, :type => String }, { :name => :position, :type => Integer }, { :name => :delivery_score, :type => Integer }, { :name => :retrieval_rank, :type => Integer }, { :name => :retrieval_score, :type => Float } ] ) if ins[:user_info] then self.validate_user_info! ins[:user_info] end end |
#validate_metrics_request!(metrics_req) ⇒ Object
TODO - delete?
138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/promoted/ruby/client/validator.rb', line 138 def validate_metrics_request!(metrics_req) validate_fields!( metrics_req, "metrics request", [ { :name => :request, :required => true } ] ) validate_request!(metrics_req[:request]) end |
#validate_request!(req) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/promoted/ruby/client/validator.rb', line 79 def validate_request!(req) validate_fields!( req, "request", [ { :name => :platform_id, :type => Integer }, { :name => :request_id, :type => String }, { :name => :view_id, :type => String }, { :name => :session_id, :type => String }, { :name => :insertion, :required => true, :type => Array } ] ) if req[:insertion] then req[:insertion].each {|ins| validate_insertion! ins } end if req[:user_info] then validate_user_info! req[:user_info] end end |
#validate_response!(res) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/promoted/ruby/client/validator.rb', line 119 def validate_response!(res) validate_fields!( res, "response", [ { :name => :request_id, :required => true, :type => String } ] ) if !res.key?(:insertion) then res[:insertion] = [] end end |
#validate_user_info!(ui) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/promoted/ruby/client/validator.rb', line 5 def validate_user_info!(ui) validate_fields!( ui, "user info", [ { :name => :user_id, :type => String }, { :name => :anon_user_id, :type => String }, { :name => :is_internal_user, :type => [TrueClass, FalseClass] } ] ) end |