Class: CongressForms::CwcForm
- Defined in:
- lib/congress_forms/cwc_form.rb
Instance Attribute Summary collapse
-
#office_code ⇒ Object
Returns the value of attribute office_code.
Instance Method Summary collapse
- #fill(values, campaign_tag: nil, organization: nil, browser: nil, validate_only: false) ⇒ Object
-
#initialize(office_code) ⇒ CwcForm
constructor
A new instance of CwcForm.
- #required_params ⇒ Object
- #updated_at ⇒ Object
Methods inherited from Form
find, #missing_required_params, repo
Constructor Details
#initialize(office_code) ⇒ CwcForm
Returns a new instance of CwcForm.
5 6 7 |
# File 'lib/congress_forms/cwc_form.rb', line 5 def initialize(office_code) self.office_code = office_code end |
Instance Attribute Details
#office_code ⇒ Object
Returns the value of attribute office_code.
3 4 5 |
# File 'lib/congress_forms/cwc_form.rb', line 3 def office_code @office_code end |
Instance Method Details
#fill(values, campaign_tag: nil, organization: nil, browser: nil, validate_only: false) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 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 |
# File 'lib/congress_forms/cwc_form.rb', line 17 def fill(values, campaign_tag: nil, organization: nil, browser: nil, validate_only: false) params = { campaign_id: campaign_tag || SecureRandom.hex(16), recipient: { member_office: office_code }, constituent: { prefix: values["$NAME_PREFIX"], first_name: values["$NAME_FIRST"], last_name: values["$NAME_LAST"], address: Array(values["$ADDRESS_STREET"]), city: values["$ADDRESS_CITY"], state_abbreviation: values["$ADDRESS_STATE_POSTAL_ABBREV"], zip: values["$ADDRESS_ZIP5"], email: values["$EMAIL"] }, message: { subject: values["$SUBJECT"], library_of_congress_topics: Array(values["$TOPIC"]) } } if organization params[:organization] = organization end if values["$STATEMENT"] params[:message][:organization_statement] = values["$STATEMENT"] end if values["$MESSAGE"] && values["$MESSAGE"] != values["$STATEMENT"] params[:message][:constituent_message] = values["$MESSAGE"] end cwc_client = Cwc::Client.new = cwc_client.(params) if validate_only cwc_client.validate() else cwc_client.deliver() end end |
#required_params ⇒ Object
13 14 15 |
# File 'lib/congress_forms/cwc_form.rb', line 13 def required_params Cwc::RequiredJson.fetch("required_actions").map(&:dup) end |
#updated_at ⇒ Object
9 10 11 |
# File 'lib/congress_forms/cwc_form.rb', line 9 def updated_at Time.at(0) end |