Skip to content

Instantly share code, notes, and snippets.

@gaygenius
Last active August 29, 2015 14:16
Show Gist options
  • Save gaygenius/ea7af0de550a09854e65 to your computer and use it in GitHub Desktop.
Save gaygenius/ea7af0de550a09854e65 to your computer and use it in GitHub Desktop.
Rails API endpoint for after-sign sponsored ads

GET /soa/petition_ads/:id

(id is the lead-in petition id)

additional params:

  • (required) context=after_sign_sponsored
  • (required) locale
  • (required) country_code
  • (optional) include_phone_upsells (only if phone_petition is not in the user’s request)
  • (optional) source=fe-services-app
  • (optional) is_mobile
  • (optional) alert_id

required cookies:

  • _change_session (there must be a session for an identified user (Rails gets the session via cookies)

200 http status code (SUCCESS)

items will be an array of ads, including either:

  1. an array of sponsored petition ads followed by a redirect ad to redirect the user to finish_petition_upsells_url(petition_id: originating_petition.id)

  2. a single redirect ad to either:

/p (petitions_path) if

  • user not identified
  • no previous signature
  • no lead-in petition found (missing or incorrect petition_id param)

OTHER DESTINATIONS per upsell_list_redirect

Sponsored petition ads

items: [
  ad_type:                    petition.ad_type
  petition_id:                petition.id
  lead_in_petition_id:        originating_petition.id
  sign_url:                   [SEE NOTE BELOW]
  skip_url:                   [SEE NOTE BELOW]
  prompt_record_id:           prompt_record.try(:id)
  title:                      prompted_petition_title(petition, mvtp)
  has_mvtp_description:       (boolean)
  original_description:       petition.description
  description:                prompted_petition_description(petition, mvtp, nil)  # nil = don’t truncate
  html_formatted_letter:      petition.html_formatted_letter
  photo_url:                  petition_photo_image_tag(:column_9) # SIZE: 556x313
  photo_alt_title:            # new helper reusing petition_photo_image_tag(:column_3, petition, :alt => petition.widget_title, :class => 'petition-image', :url_options => {:mvtp => mvtp})
  displayed_signature_count:  petition.displayed_signature_count
  optin_text:                 petition_optin_text(petition, :include_name => true)
  sign_button_text:           sign_button_text(petition)[0]
  signing_button_text:        sign_button_text(petition)[1]
  phone_number_placeholder:   I18n::PhoneNumberValidator.placeholder

  client_commitment:
    id: petition.client_commitment.id,
    name: petition.client_commitment.name
  
  dollar_value: petition.dollar_value || -1.0
  dollar_status: petition.dollar_status || "unavailable"
  targeting_type: UserTargetingCondition.upsell_targeting_type(petition)

  organization:
    id:                       petition.organization_id
    name:                     petition.organization.name
    logo_url:                 place_organization_logo(petition)  # 44x44 (exisiting organization :column_1 size)
]

NOTES:

  • if has_mvtp_description is true, then description is the MVT description. Otherwise, it is the petition’s description.
  • sign_url and skip_url are not used by Rendr, as we chose to add routes to its services-app that form the required URLs. Also note that skip_url used to include a prompt_record_id param but that is no longer used after this commit.

Redirect ads

items: [
  ad_type:                    'redirect'
  redirect_to:                (either `/p` or whatever `upsell_list_redirect` specifies)
]

Cookies

Rendr will set the cookies

When showing sponsored petition ads to a user

cookies["prompted_petitions"] = { value: 'true', expires: 12.hours.from_now, domain: base_domain }

When the user successfully signs a phone sponsored petition ad

cookies["phone_petition"] = { :value => 'true', :expires => 30.days.from_now, :domain => base_domain }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment