Class: IABConsentString::Consent::Implementation::V1::VendorConsentBuilder
- Inherits:
-
Object
- Object
- IABConsentString::Consent::Implementation::V1::VendorConsentBuilder
- Defined in:
- lib/iab_consent_string/consent/implementation/v1/vendor_consent_builder.rb
Overview
Builder for version 1 of vendor consent
Constant Summary collapse
- VERSION =
1
Instance Method Summary collapse
-
#build ⇒ IABConsentString::Consent::VendorConsent
Validate supplied values and build VendorConsent object.
-
#withAllowedPurposeIds(allowedPurposeIds) ⇒ VendorConsentBuilder
With allowed purpose IDs.
-
#withAllowedPurposes(allowedPurposes) ⇒ VendorConsentBuilder
With allowed purposes.
-
#withBitField(bitFieldEntries) ⇒ VendorConsentBuilder
With bit field entries.
-
#withCmpId(cmpId) ⇒ VendorConsentBuilder
With CMP Id.
-
#withCmpVersion(cmpVersion) ⇒ VendorConsentBuilder
With CMP version.
-
#withConsentLanguage(consentLanguage) ⇒ VendorConsentBuilder
With consent language.
-
#withConsentRecordCreatedOn(consentRecordCreated) ⇒ VendorConsentBuilder
With creation date.
-
#withConsentRecordLastUpdatedOn(consentRecordLastUpdated) ⇒ VendorConsentBuilder
With update date.
-
#withConsentScreenId(consentScreenId) ⇒ VendorConsentBuilder
With Consent Screen Id.
-
#withDefaultConsent(defaultConsent) ⇒ VendorConsentBuilder
With default consent.
-
#withMaxVendorId(maxVendorId) ⇒ VendorConsentBuilder
With max vendor ID.
-
#withRangeEntries(rangeEntries) ⇒ VendorConsentBuilder
With range entries.
-
#withVendorEncodingType(vendorEncodingType) ⇒ VendorConsentBuilder
With vendor encoding type.
-
#withVendorListVersion(vendorListVersion) ⇒ VendorConsentBuilder
With vendor list version.
Instance Method Details
#build ⇒ IABConsentString::Consent::VendorConsent
Validate supplied values and build VendorConsent object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/iab_consent_string/consent/implementation/v1/vendor_consent_builder.rb', line 141 def build if @consentRecordCreated.nil? raise IABConsentString::Error::VendorConsentCreateError, "consentRecordCreated must be set", caller end if @consentRecordLastUpdated.nil? raise IABConsentString::Error::VendorConsentCreateError, "consentRecordLastUpdated must be set", caller end if @consentLanguage.nil? raise IABConsentString::Error::VendorConsentCreateError, "consentLanguage must be set", caller end if @vendorListVersion.nil? || @vendorListVersion <=0 raise IABConsentString::Error::VendorConsentCreateError, "Invalid value for vendorListVersion:" + @vendorListVersion.to_s, caller end if @maxVendorId.nil? || @maxVendorId<=0 raise IABConsentString::Error::VendorConsentCreateError, "Invalid value for maxVendorId:" + @maxVendorId.to_s, caller end # For range encoding, check if each range entry is valid if @vendorEncodingType == IABConsentString::GDPRConstants::VENDOR_ENCODING_RANGE if @rangeEntries.nil? raise IABConsentString::Error::VendorConsentCreateError, "Range entries must be set", caller end @rangeEntries.each do |rangeEntry| if !rangeEntry.valid(@maxVendorId) raise IABConsentString::Error::VendorConsentCreateError, "Invalid range entries found", caller end end end # Calculate size of bit buffer in bits bitBufferSizeInBits = 0 if (@vendorEncodingType == IABConsentString::GDPRConstants::VENDOR_ENCODING_RANGE) rangeEntrySectionSize = 0 @rangeEntries.each do |rangeEntry| rangeEntrySectionSize += rangeEntry.size end bitBufferSizeInBits = IABConsentString::GDPRConstants::RANGE_ENTRY_OFFSET + rangeEntrySectionSize else bitBufferSizeInBits = IABConsentString::GDPRConstants::VENDOR_BITFIELD_OFFSET + @maxVendorId end # Create new bit buffer bitsFit = (bitBufferSizeInBits % 8) == 0 str = "" for i in (0...(bitBufferSizeInBits / 8 + (bitsFit ? 0 : 1))) do str << 0b00000000 end bits = IABConsentString::Bits.new(str.bytes.to_a) # Set fields in bit buffer bits.setInt(IABConsentString::GDPRConstants::VERSION_BIT_OFFSET, IABConsentString::GDPRConstants::VERSION_BIT_SIZE, VERSION) bits.setDateTimeToEpochDeciseconds(IABConsentString::GDPRConstants::CREATED_BIT_OFFSET, IABConsentString::GDPRConstants::CREATED_BIT_SIZE, @consentRecordCreated) bits.setDateTimeToEpochDeciseconds(IABConsentString::GDPRConstants::UPDATED_BIT_OFFSET, IABConsentString::GDPRConstants::UPDATED_BIT_SIZE, @consentRecordLastUpdated) bits.setInt(IABConsentString::GDPRConstants::CMP_ID_OFFSET, IABConsentString::GDPRConstants::CMP_ID_SIZE, @cmpId) bits.setInt(IABConsentString::GDPRConstants::CMP_VERSION_OFFSET, IABConsentString::GDPRConstants::CMP_VERSION_SIZE, @cmpVersion) bits.setInt(IABConsentString::GDPRConstants::CONSENT_SCREEN_SIZE_OFFSET, IABConsentString::GDPRConstants::CONSENT_SCREEN_SIZE, @consentScreenId) bits.setSixBitString(IABConsentString::GDPRConstants::CONSENT_LANGUAGE_OFFSET, IABConsentString::GDPRConstants::CONSENT_LANGUAGE_SIZE, @consentLanguage) bits.setInt(IABConsentString::GDPRConstants::VENDOR_LIST_VERSION_OFFSET, IABConsentString::GDPRConstants::VENDOR_LIST_VERSION_SIZE, @vendorListVersion) # Set purposes bits for i in (0...IABConsentString::GDPRConstants::PURPOSES_SIZE) do if (@allowedPurposes.include?(i+1)) bits.setBit(IABConsentString::GDPRConstants::PURPOSES_OFFSET + i) else bits.unsetBit(IABConsentString::GDPRConstants::PURPOSES_OFFSET + i) end end bits.setInt(IABConsentString::GDPRConstants::MAX_VENDOR_ID_OFFSET, IABConsentString::GDPRConstants::MAX_VENDOR_ID_SIZE, @maxVendorId) bits.setInt(IABConsentString::GDPRConstants::ENCODING_TYPE_OFFSET, IABConsentString::GDPRConstants::ENCODING_TYPE_SIZE, @vendorEncodingType) # Set the bit field or range sections if (@vendorEncodingType == IABConsentString::GDPRConstants::VENDOR_ENCODING_RANGE) # Range encoding if (@defaultConsent) bits.setBit(IABConsentString::GDPRConstants::DEFAULT_CONSENT_OFFSET) else bits.unsetBit(IABConsentString::GDPRConstants::DEFAULT_CONSENT_OFFSET) end bits.setInt(IABConsentString::GDPRConstants::NUM_ENTRIES_OFFSET, IABConsentString::GDPRConstants::NUM_ENTRIES_SIZE, @rangeEntries.size) currentOffset = IABConsentString::GDPRConstants::RANGE_ENTRY_OFFSET @rangeEntries.each do |rangeEntry| currentOffset = rangeEntry.appendTo(bits, currentOffset) end else # Bit field encoding for i in (0...@maxVendorId) do if @vendorsBitField.include?(i+1) bits.setBit(IABConsentString::GDPRConstants::VENDOR_BITFIELD_OFFSET+i) else bits.unsetBit(IABConsentString::GDPRConstants::VENDOR_BITFIELD_OFFSET+i) end end end IABConsentString::Consent::Implementation::V1::ByteBufferBackedVendorConsent.new(bits) end |
#withAllowedPurposeIds(allowedPurposeIds) ⇒ VendorConsentBuilder
With allowed purpose IDs
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/iab_consent_string/consent/implementation/v1/vendor_consent_builder.rb', line 72 def withAllowedPurposeIds(allowedPurposeIds) if allowedPurposeIds.nil? raise "Argument allowedPurposeIds is null" end allowedPurposeIds.each do |purposeId| if purposeId < 0 || purposeId > IABConsentString::GDPRConstants::PURPOSES_SIZE raise "Invalid purpose ID found" end end @allowedPurposes = allowedPurposeIds; self end |
#withAllowedPurposes(allowedPurposes) ⇒ VendorConsentBuilder
With allowed purposes
88 89 90 91 92 93 94 |
# File 'lib/iab_consent_string/consent/implementation/v1/vendor_consent_builder.rb', line 88 def withAllowedPurposes(allowedPurposes) if allowedPurposes.nil? raise "Argument allowedPurposes is null" end @allowedPurposes = allowedPurposes.map! {|purpose| purpose.getId } self end |
#withBitField(bitFieldEntries) ⇒ VendorConsentBuilder
With bit field entries
118 119 120 121 |
# File 'lib/iab_consent_string/consent/implementation/v1/vendor_consent_builder.rb', line 118 def withBitField(bitFieldEntries) @vendorsBitField = bitFieldEntries self end |
#withCmpId(cmpId) ⇒ VendorConsentBuilder
With CMP Id
40 41 42 43 |
# File 'lib/iab_consent_string/consent/implementation/v1/vendor_consent_builder.rb', line 40 def withCmpId(cmpId) @cmpId = cmpId self end |
#withCmpVersion(cmpVersion) ⇒ VendorConsentBuilder
With CMP version
32 33 34 35 |
# File 'lib/iab_consent_string/consent/implementation/v1/vendor_consent_builder.rb', line 32 def withCmpVersion(cmpVersion) @cmpVersion = cmpVersion self end |
#withConsentLanguage(consentLanguage) ⇒ VendorConsentBuilder
With consent language
56 57 58 59 |
# File 'lib/iab_consent_string/consent/implementation/v1/vendor_consent_builder.rb', line 56 def withConsentLanguage() @consentLanguage = self end |
#withConsentRecordCreatedOn(consentRecordCreated) ⇒ VendorConsentBuilder
With creation date
16 17 18 19 |
# File 'lib/iab_consent_string/consent/implementation/v1/vendor_consent_builder.rb', line 16 def withConsentRecordCreatedOn() @consentRecordCreated = self end |
#withConsentRecordLastUpdatedOn(consentRecordLastUpdated) ⇒ VendorConsentBuilder
With update date
24 25 26 27 |
# File 'lib/iab_consent_string/consent/implementation/v1/vendor_consent_builder.rb', line 24 def withConsentRecordLastUpdatedOn() @consentRecordLastUpdated = ; self end |
#withConsentScreenId(consentScreenId) ⇒ VendorConsentBuilder
With Consent Screen Id
48 49 50 51 |
# File 'lib/iab_consent_string/consent/implementation/v1/vendor_consent_builder.rb', line 48 def withConsentScreenId() @consentScreenId = self end |
#withDefaultConsent(defaultConsent) ⇒ VendorConsentBuilder
With default consent
134 135 136 137 |
# File 'lib/iab_consent_string/consent/implementation/v1/vendor_consent_builder.rb', line 134 def withDefaultConsent(defaultConsent) @defaultConsent = defaultConsent self end |
#withMaxVendorId(maxVendorId) ⇒ VendorConsentBuilder
With max vendor ID
99 100 101 102 |
# File 'lib/iab_consent_string/consent/implementation/v1/vendor_consent_builder.rb', line 99 def withMaxVendorId(maxVendorId) @maxVendorId = maxVendorId self end |
#withRangeEntries(rangeEntries) ⇒ VendorConsentBuilder
With range entries
126 127 128 129 |
# File 'lib/iab_consent_string/consent/implementation/v1/vendor_consent_builder.rb', line 126 def withRangeEntries(rangeEntries) @rangeEntries = rangeEntries self end |
#withVendorEncodingType(vendorEncodingType) ⇒ VendorConsentBuilder
With vendor encoding type
107 108 109 110 111 112 113 |
# File 'lib/iab_consent_string/consent/implementation/v1/vendor_consent_builder.rb', line 107 def withVendorEncodingType(vendorEncodingType) if (vendorEncodingType < 0 || vendorEncodingType > 1) raise "Illegal value for argument vendorEncodingType:" + vendorEncodingType.to_s end @vendorEncodingType = vendorEncodingType self end |
#withVendorListVersion(vendorListVersion) ⇒ VendorConsentBuilder
With vendor list version
64 65 66 67 |
# File 'lib/iab_consent_string/consent/implementation/v1/vendor_consent_builder.rb', line 64 def withVendorListVersion(vendorListVersion) @vendorListVersion = vendorListVersion self end |