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_delivery_args!(metrics_req) ⇒ Object
TODO - delete?.
- #validate_insertion!(ins) ⇒ Object
- #validate_request!(req) ⇒ Object
- #validate_response!(res) ⇒ Object
- #validate_user_info!(ui) ⇒ Object
Instance Method Details
#check_that_content_ids_are_set!(req) ⇒ Object
175 176 177 178 179 |
# File 'lib/promoted/ruby/client/validator.rb', line 175 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
165 166 167 168 169 170 171 172 173 |
# File 'lib/promoted/ruby/client/validator.rb', line 165 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_delivery_args!(metrics_req) ⇒ Object
TODO - delete?
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/promoted/ruby/client/validator.rb', line 146 def validate_delivery_args!(metrics_req) validate_fields!( metrics_req, "metrics request", [ { :name => :request, :required => true }, { :name => :retrieval_insertion_offset, :type => Integer } ] ) validate_request!(metrics_req[:request]) end |
#validate_insertion!(ins) ⇒ Object
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 78 79 80 81 |
# File 'lib/promoted/ruby/client/validator.rb', line 30 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_request!(req) ⇒ Object
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 118 119 120 121 122 123 124 125 |
# File 'lib/promoted/ruby/client/validator.rb', line 83 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 => :disable_personalization, :type => [TrueClass, FalseClass] }, { :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
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/promoted/ruby/client/validator.rb', line 127 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 25 26 27 28 |
# 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] }, { :name => :ignore_usage, :type => [TrueClass, FalseClass] } ] ) end |