Class: Cwc::Client
- Inherits:
-
Object
- Object
- Cwc::Client
- Defined in:
- lib/cwc/client.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
- .configure(options) ⇒ Object
- .default_client_configuration ⇒ Object
- .default_client_configuration=(x) ⇒ Object
Instance Method Summary collapse
-
#create_message(params) ⇒ Object
Params format { campaign_id: String recipient: { member_office: String is_response_requested: Boolean ? newsletter_opt_in: Boolean ? }, organization: { name: String ? contact: { name: String ? email: String ? phone: String ? about: String ? } }, constituent: { prefix: String first_name: String middle_name: String ? last_name: String suffix: String ? title: String ? organization: String ? address: Array city: String state_abbreviation: String zip: String phone: String ? address_validation: Boolean ? email: String email_validation: Boolean ? }, message: { subject: String library_of_congress_topics: Array, drawn from Cwc::TopicCodes. Must give at least 1. bills: { Array congress: Integer ? type_abbreviation: String number: Integer }, pro_or_con: “pro” or “con” ? organization_statement: String ? constituent_message: String ? more_info: String (URL) ? }.
- #deliver(message) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
Required options keys api_key String delivery_agent String, must match the api key owner delivery_agent_ack_email String delivery_agent_contact_name String delivery_agent_contact_email String delivery_agent_contact_phone String, format xxx-xxx-xxxx.
- #office_supported?(office_code) ⇒ Boolean
- #required_json(o = {}) ⇒ Object
- #validate(message) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Required options keys
api_key String
delivery_agent String, must match the api key owner
delivery_agent_ack_email String
delivery_agent_contact_name String
delivery_agent_contact_email String
delivery_agent_contact_phone String, format xxx-xxx-xxxx
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cwc/client.rb', line 37 def initialize(={}) = self.class.default_client_configuration.merge() self. = { api_key: .fetch(:api_key), host: .fetch(:host), delivery_agent: { name: .fetch(:delivery_agent), ack_email: .fetch(:delivery_agent_ack_email), contact_name: .fetch(:delivery_agent_contact_name), contact_email: .fetch(:delivery_agent_contact_email), contact_phone: .fetch(:delivery_agent_contact_phone) } } end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
14 15 16 |
# File 'lib/cwc/client.rb', line 14 def @options end |
Class Method Details
.configure(options) ⇒ Object
25 26 27 |
# File 'lib/cwc/client.rb', line 25 def configure() self.default_client_configuration = end |
.default_client_configuration ⇒ Object
21 22 23 |
# File 'lib/cwc/client.rb', line 21 def default_client_configuration @default_client_configuration ||= {} end |
.default_client_configuration=(x) ⇒ Object
17 18 19 |
# File 'lib/cwc/client.rb', line 17 def default_client_configuration=(x) @default_client_configuration = x end |
Instance Method Details
#create_message(params) ⇒ Object
Params format {
campaign_id: String
recipient: {
member_office: String
is_response_requested: Boolean ?
newsletter_opt_in: Boolean ?
},
organization: {
name: String ?
contact: {
name: String ?
email: String ?
phone: String ?
about: String ?
}
},
constituent: {
prefix: String
first_name: String
middle_name: String ?
last_name: String
suffix: String ?
title: String ?
organization: String ?
address: Array[String]
city: String
state_abbreviation: String
zip: String
phone: String ?
address_validation: Boolean ?
email: String
email_validation: Boolean ?
},
message: {
subject: String
library_of_congress_topics: Array[String], drawn from Cwc::TopicCodes. Must give at least 1.
bills: { Array[Hash]
congress: Integer ?
type_abbreviation: String
number: Integer
},
pro_or_con: "pro" or "con" ?
organization_statement: String ?
constituent_message: String ?
more_info: String (URL) ?
}
Use message for personal message, or message for campaign message At least one of these must be given
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/cwc/client.rb', line 104 def (params) Cwc::Message.new.tap do || .delivery[:agent] = .fetch(:delivery_agent) .delivery[:organization] = params.fetch(:organization, {}) .delivery[:campaign_id] = params.fetch(:campaign_id) .recipient.merge!(params.fetch(:recipient)) .constituent.merge!(params.fetch(:constituent)) ..merge!(params.fetch(:message)) end end |
#deliver(message) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/cwc/client.rb', line 116 def deliver() post action("/v2/message"), .to_xml true rescue RestClient::BadRequest => e raise BadRequest.new(e) end |
#office_supported?(office_code) ⇒ Boolean
130 131 132 |
# File 'lib/cwc/client.rb', line 130 def office_supported?(office_code) !offices.find{ |office| office.code == office_code }.nil? end |
#required_json(o = {}) ⇒ Object
134 135 136 |
# File 'lib/cwc/client.rb', line 134 def required_json(o={}) Cwc::RequiredJson.merge(o) end |
#validate(message) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/cwc/client.rb', line 123 def validate() post action("/v2/validate"), .to_xml true rescue RestClient::BadRequest => e raise BadRequest.new(e) end |