This Service Object is intended for internal use by HeyJobs to detect discrepancies between Local campaigns and remote ads.
Make sure that you install Ruby v2.5
git clone https://github.com/Maghraby/detect_discrepancy.git
Running this command will install all required gems.
cd detect_discrepancy
./bin/setup
./bin/console
./bin/console
detect = Detect.run
Check changes:
detect.changes
Check errors:
detect.errors
detect.changes
- When there is no discrepancy between local and remote.
[]
- When there is a discrepancy:
- Between status or description of local and remote Campaign.
[ { remote_reference: '2', discrepancies: [ { status: { remote: 'disabled', local: 'active' } }, { ad_description: { remote: 'Description for campaign 13', local: 'Description for campaign 50' } } ] }, { remote_reference: '3', discrepancies: [ { ad_description: { remote: 'Description for campaign 3', local: 'Description for campaign 33' } } ] } ]
- When there is a remote Campaign without a matching local one.
[ { remote_reference: '2', discrepancies: [ { status: { remote: 'enabled', local: 'deleted' } }, { ad_description: { remote: 'Description for campaign 13', local: nil } } ] } ]
- When there is a local Campaign without a matching remote one.
[ { remote_reference: '2', discrepancies: [ { status: { remote: nil, local: 'active' } }, { ad_description: { remote: nil, local: 'Description for campaign 13' } } ] } ]
detect.errors
If no error:
[]
When there are errors:
[#<Errors::RemoteAdFetchError: Error while fetching data from url with error_message_here>]
There are three configurable keys:
-
REMOTE_AD_URL
You can change the remote add URL. Example:
REMOTE_AD_URL='https://mockbin.org/bin/fcb30500-7b98-476f-810d-463a0b8fc3df' bin/console
detect = Detect.run ...
-
MAPPING_KEYS
You can pass the mapping keys that you want this service to detect. Example:
MAPPING_KEYS="{\"status\":\"status\",\"ad_description\":\"description\"}" ./bin/console
detect = Detect.run ...
you can add keys as much you want ;).
-
MAPPING_VALUES
For keys that have different values from remote_ad and local campaign. Example:
MAPPING_VALUES="{\"status\":{\"active\":\"enabled\",\"paused\":\"disabled\"}}" ./bin/console
detect = Detect.run ...
This will map status key with values: enabled to active and disabled to paused.
rspec