Maghraby / detect_discrepancy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Detect Discrepancy

This Service Object is intended for internal use by HeyJobs to detect discrepancies between Local campaigns and remote ads.

Prerequisite

Make sure that you install Ruby v2.5

Development

Clone the source

git clone https://github.com/Maghraby/detect_discrepancy.git

Installing

Running this command will install all required gems.

cd detect_discrepancy
./bin/setup

Console

./bin/console

Running

./bin/console
detect = Detect.run

Check changes:

detect.changes

Check errors:

detect.errors

Service output format

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>]

Configurable

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.

Testing

rspec

About


Languages

Language:Ruby 99.8%Language:Shell 0.2%