govdelivery-tms 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +14 -0
  3. data/README.md +324 -0
  4. data/Rakefile +20 -0
  5. data/govdelivery-tms.gemspec +30 -0
  6. data/lib/govdelivery-tms.rb +43 -0
  7. data/lib/govdelivery-tms/base.rb +37 -0
  8. data/lib/govdelivery-tms/client.rb +97 -0
  9. data/lib/govdelivery-tms/collection_resource.rb +54 -0
  10. data/lib/govdelivery-tms/connection.rb +34 -0
  11. data/lib/govdelivery-tms/errors.rb +58 -0
  12. data/lib/govdelivery-tms/instance_resource.rb +219 -0
  13. data/lib/govdelivery-tms/link_header.rb +223 -0
  14. data/lib/govdelivery-tms/logger.rb +36 -0
  15. data/lib/govdelivery-tms/mail/delivery_method.rb +63 -0
  16. data/lib/govdelivery-tms/resource/collections.rb +98 -0
  17. data/lib/govdelivery-tms/resource/command.rb +25 -0
  18. data/lib/govdelivery-tms/resource/command_action.rb +17 -0
  19. data/lib/govdelivery-tms/resource/command_type.rb +20 -0
  20. data/lib/govdelivery-tms/resource/email_message.rb +81 -0
  21. data/lib/govdelivery-tms/resource/email_recipient.rb +31 -0
  22. data/lib/govdelivery-tms/resource/email_recipient_click.rb +8 -0
  23. data/lib/govdelivery-tms/resource/email_recipient_open.rb +8 -0
  24. data/lib/govdelivery-tms/resource/email_template.rb +15 -0
  25. data/lib/govdelivery-tms/resource/from_address.rb +10 -0
  26. data/lib/govdelivery-tms/resource/inbound_sms_message.rb +8 -0
  27. data/lib/govdelivery-tms/resource/ipaws_acknowledgement.rb +9 -0
  28. data/lib/govdelivery-tms/resource/ipaws_alert.rb +38 -0
  29. data/lib/govdelivery-tms/resource/ipaws_category.rb +7 -0
  30. data/lib/govdelivery-tms/resource/ipaws_cog_profile.rb +29 -0
  31. data/lib/govdelivery-tms/resource/ipaws_event_code.rb +7 -0
  32. data/lib/govdelivery-tms/resource/ipaws_nwem_area.rb +18 -0
  33. data/lib/govdelivery-tms/resource/ipaws_nwem_authorization.rb +9 -0
  34. data/lib/govdelivery-tms/resource/ipaws_nwem_auxilary_data.rb +8 -0
  35. data/lib/govdelivery-tms/resource/ipaws_response_type.rb +7 -0
  36. data/lib/govdelivery-tms/resource/ipaws_static_resource.rb +8 -0
  37. data/lib/govdelivery-tms/resource/keyword.rb +30 -0
  38. data/lib/govdelivery-tms/resource/recipient.rb +10 -0
  39. data/lib/govdelivery-tms/resource/sms_message.rb +35 -0
  40. data/lib/govdelivery-tms/resource/webhook.rb +20 -0
  41. data/lib/govdelivery-tms/util/core_ext.rb +27 -0
  42. data/lib/govdelivery-tms/util/hal_link_parser.rb +50 -0
  43. data/lib/govdelivery-tms/version.rb +3 -0
  44. data/spec/client_spec.rb +41 -0
  45. data/spec/command_types_spec.rb +29 -0
  46. data/spec/email_message_spec.rb +102 -0
  47. data/spec/email_template_spec.rb +149 -0
  48. data/spec/errors_spec.rb +13 -0
  49. data/spec/from_address_spec.rb +86 -0
  50. data/spec/inbound_sms_messages_spec.rb +19 -0
  51. data/spec/instance_resource_spec.rb +61 -0
  52. data/spec/ipaws_acknowledgement_spec.rb +16 -0
  53. data/spec/ipaws_alerts_spec.rb +192 -0
  54. data/spec/ipaws_cog_profile_spec.rb +75 -0
  55. data/spec/ipaws_event_codes_spec.rb +35 -0
  56. data/spec/ipaws_nwem_areas_spec.rb +58 -0
  57. data/spec/ipaws_nwem_authorization_spec.rb +16 -0
  58. data/spec/keyword_spec.rb +62 -0
  59. data/spec/keywords_spec.rb +21 -0
  60. data/spec/mail/delivery_method_spec.rb +52 -0
  61. data/spec/sms_message_spec.rb +63 -0
  62. data/spec/sms_messages_spec.rb +21 -0
  63. data/spec/spec_helper.rb +31 -0
  64. data/spec/tms_spec.rb +7 -0
  65. metadata +172 -0
@@ -0,0 +1,17 @@
1
+ module TMS #:nodoc:
2
+ # CommandAction object represent the results of Commands for a particular input (e.g. an incoming SMS message)
3
+ #
4
+ # This resource is read-only.
5
+ #
6
+ # ==== Attributes
7
+ #
8
+ # * +http_response_code+ - e.g. 200, 404, etc.
9
+ # * +http_content_type+ - text/html, etc.
10
+ # * +http_body+ - Request body (if it's <500 characters, otherwise it'll be nil)
11
+ #
12
+ class CommandAction
13
+ include InstanceResource
14
+
15
+ readonly_attributes :status, :content_type, :response_body, :created_at
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ module TMS #:nodoc:
2
+ # CommandType is a pair of values (name, string_fields, array_fields) that can be attached
3
+ # to a Keyword (in a Command object).
4
+ #
5
+ # This resource is read-only.
6
+ #
7
+ # @attr name [String] The name of the CommandType.
8
+ # @attr string_fields [Array] An Array of strings representing the different string_fields on this
9
+ # CommandType. Field values will always be strings.
10
+ # @attr array_fields [Array] An array of strings representing the different array fields on this
11
+ # CommandType. Field values will always be arrays of strings.
12
+ #
13
+ class CommandType
14
+
15
+ include InstanceResource
16
+
17
+ # @!parse attr_reader :string_fields, :array_fields, :name
18
+ readonly_attributes :name, :string_fields, :array_fields
19
+ end
20
+ end
@@ -0,0 +1,81 @@
1
+ module TMS #:nodoc:
2
+ # An EmailMessage is used to create and send a email to a collection of EmailRecipient
3
+ # objects. Certain metrics are available after the email is sent, including
4
+ # the collection of recipients who clicked or opened the email.
5
+ #
6
+ # @attr from_name [String] The name of the person or entity sending the email.
7
+ # @attr from_email [String] Optional - the email address of the person or entity sending the email. Must be configured in TMS beforehand. Defaults to the account default from address.
8
+ # @attr reply_to [String] Optional - the email address used for the Reply-To header of this email. Defaults to the account default reply_to_email address (which itself defaults to the default from address if not specified).
9
+ # @attr errors_to [String] Optional - the email address used for the Errors-To header of this email. Defaults to the account default bounce_email address (which itself defaults to the default from address if not specified).
10
+ # @attr subject [String] The subject of the email.
11
+ # @attr body [String] The body of the email.
12
+ # @attr open_tracking_enabled [Boolean] Optional - Whether to track opens on this message. Defaults to true.
13
+ # @attr click_tracking_enabled [Boolean] Optional - Whether to track clicks on links in this message. Defaults to true.
14
+ # @attr macros [Hash] Optional - A dictionary of key/value pairs to use in the subject and body as default macros.
15
+ # The message-level macros are used when a recipient has no value for a given macro key.
16
+ #
17
+ # @example Sending a message
18
+ # email_message = client.email_messages.build(:subject => "Great news!",
19
+ # :body => "You win! <a href='http://example.com/'>click here</a>.",
20
+ # :from_email => 'foo@example.com')
21
+ # email_message.recipients.build(:email => "john@example.com")
22
+ # email_message.recipients.build(:email => "jeff@example.com")
23
+ # email_message.post
24
+ # email_message.get
25
+ #
26
+ # @example Viewing recipients that clicked on a link in the email
27
+ # email_message.get
28
+ # email_message.clicked.get
29
+ # email_message.clicked.collection # => [<#EmailRecipient>,...]
30
+ #
31
+ # @example Viewing recipients that opened the email
32
+ # email_message.get
33
+ # email_message.opened.get
34
+ # email_message.opened.collection # => [<#EmailRecipient>,...]
35
+ #
36
+ # @example Using macros
37
+ # email_message = client.email_messages.build(:subject => "Hello [[user]]",
38
+ # :body => "Your name is [[name]]",
39
+ # :macros => {:user => "Sir or Madam", :name => "unknown"})
40
+ # email_message.recipients.build(:email => "jeff@example.com", :macros => {:user => "jexample", :name => "Jeff Example"})
41
+ # email_message.post
42
+ #
43
+ class EmailMessage
44
+ include InstanceResource
45
+
46
+ # @!parse attr_accessor :body, :from_name, :from_email, :reply_to, :errors_to, :subject, :open_tracking_enabled, :click_tracking_enabled, :macros
47
+ writeable_attributes :body,
48
+ :click_tracking_enabled,
49
+ :errors_to,
50
+ :from_email,
51
+ :from_name,
52
+ :macros,
53
+ :open_tracking_enabled,
54
+ :reply_to,
55
+ :subject
56
+
57
+
58
+ # @!parse attr_reader :created_at, :status
59
+ readonly_attributes :created_at, :status
60
+
61
+ ##
62
+ # A CollectionResource of EmailRecipients on this email
63
+ collection_attribute :recipients, 'EmailRecipients'
64
+
65
+ ##
66
+ # A CollectionResource of EmailRecipients that opened this email
67
+ collection_attribute :opened, 'EmailRecipients'
68
+
69
+ ##
70
+ # A CollectionResource of EmailRecipients that clicked on at least one link in this email
71
+ collection_attribute :clicked, 'EmailRecipients'
72
+
73
+ ##
74
+ # A CollectionResource of EmailRecipients that sent successfully
75
+ collection_attribute :sent, 'EmailRecipients'
76
+
77
+ ##
78
+ # A CollectionResource of EmailRecipients that failed, not neccessarily bounced
79
+ collection_attribute :failed, 'EmailRecipients'
80
+ end
81
+ end
@@ -0,0 +1,31 @@
1
+ module TMS #:nodoc:
2
+ # An EmailRecipient is used in conjunction with an EmailMessage to send email.
3
+ #
4
+ # @attr email [String] The recipient email address
5
+ # @attr macros [Hash] A dictionary of key/value pairs to resolve in the subject and body as macros. This value can be nil.
6
+ #
7
+ # @example Sending a message
8
+ # email_message = client.email_messages.build(:subject => "Great news!", :body => "You win! <a href='http://example.com/'>click here</a>.")
9
+ # email_message.recipients.build(:email => "john@example.com")
10
+ # email_message.recipients.build(:email => "jeff@example.com")
11
+ # email_message.post
12
+ # email_message.get
13
+ #
14
+ class EmailRecipient
15
+ include InstanceResource
16
+
17
+ # @!parse attr_accessor :email, :macros
18
+ writeable_attributes :email, :macros
19
+
20
+ # @!parse attr_reader :completed_at, :status, :error_message
21
+ readonly_attributes :completed_at, :status, :error_message
22
+
23
+ ##
24
+ # A CollectionResource of EmailRecipientOpens for this EmailRecipient
25
+ readonly_collection_attribute :opens, 'EmailRecipientOpens'
26
+
27
+ ##
28
+ # A CollectionResource of EmailRecipientClicks for this EmailRecipient
29
+ readonly_collection_attribute :clicks, 'EmailRecipientClicks'
30
+ end
31
+ end
@@ -0,0 +1,8 @@
1
+ module TMS #:nodoc:
2
+ class EmailRecipientClick
3
+ include InstanceResource
4
+
5
+ # @!parse attr_reader :event_at, :url
6
+ readonly_attributes :event_at, :url
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module TMS #:nodoc:
2
+ class EmailRecipientOpen
3
+ include InstanceResource
4
+
5
+ # @!parse attr_reader :event_at
6
+ readonly_attributes :event_at
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ module TMS #:nodoc:
2
+ class EmailTemplate
3
+ include InstanceResource
4
+
5
+ # @!parse attr_accessor :body, :subject, :link_tracking_parameters, :macros, :open_tracking_enabled, :click_tracking_enabled
6
+ writeable_attributes :body, :subject, :link_tracking_parameters, :macros, :open_tracking_enabled, :click_tracking_enabled
7
+
8
+ linkable_attributes :from_address
9
+
10
+ # @!parse attr_reader :created_at
11
+ readonly_attributes :id, :created_at
12
+
13
+ collection_attribute :from_address, 'FromAddress'
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ module TMS #:nodoc:
2
+ class FromAddress
3
+ include InstanceResource
4
+
5
+ # @!parse attr_accessor :from_email, :reply_to_email, :bounce_email, :is_default
6
+ writeable_attributes :from_email, :reply_to_email, :bounce_email, :is_default
7
+
8
+ readonly_attributes :created_at
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module TMS #:nodoc:
2
+ class InboundSmsMessage
3
+ include InstanceResource
4
+
5
+ # @!parse attr_reader :created_at, :completed_at, :from, :body, :to, :command_status
6
+ readonly_attributes :created_at, :completed_at, :from, :body, :to, :command_status, :keyword_response
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ module TMS
2
+ class IpawsAcknowledgement
3
+
4
+ include InstanceResource
5
+
6
+ readonly_attributes :ACK
7
+
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+ module TMS
2
+ class IpawsAlert
3
+
4
+ include InstanceResource
5
+
6
+ writeable_attributes(
7
+ :identifier,
8
+ :sender,
9
+ :sent,
10
+ :status,
11
+ :msgType,
12
+ :source,
13
+ :scope,
14
+ :restriction,
15
+ :addresses,
16
+ :code,
17
+ :note,
18
+ :references,
19
+ :incidents,
20
+ :info
21
+ )
22
+
23
+ attr_accessor :ipaws_response
24
+
25
+ def process_response(response, method)
26
+ # All IPAWS responses are 200, even if there are errors.
27
+ # Capture the IPAWS response on a 200 response to POST (create alert)
28
+ if method == :post && response.status == 200
29
+ self.ipaws_response = response.body
30
+ true
31
+ else
32
+ self.ipaws_response = nil
33
+ super
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ module TMS
2
+ class IpawsCategory
3
+
4
+ include IpawsStaticResource
5
+
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ module TMS
2
+ class IpawsCogProfile
3
+
4
+ include InstanceResource
5
+
6
+ readonly_attributes(
7
+ :cogid,
8
+ :name,
9
+ :description,
10
+ :categoryName,
11
+ :organizationName,
12
+ :cogEnabled,
13
+ :caeAuthorized,
14
+ :caeCmasAuthorized,
15
+ :eanAuthorized,
16
+ :allEventCode,
17
+ :allGeoCode,
18
+ :easAuthorized,
19
+ :cmasAlertAuthorized,
20
+ :cmamTextAuthorized,
21
+ :publicAlertAuthorized,
22
+ :broadcastAuthorized,
23
+ :email,
24
+ :eventCodes,
25
+ :geoCodes
26
+ )
27
+
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ module TMS
2
+ class IpawsEventCode
3
+
4
+ include IpawsStaticResource
5
+
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ module TMS
2
+ class IpawsNwemArea
3
+
4
+ include InstanceResource
5
+
6
+ readonly_attributes(
7
+ :countyFipsCd,
8
+ :countyName,
9
+ :geoType,
10
+ :stateCd,
11
+ :stateFips,
12
+ :stateName,
13
+ :zoneCd,
14
+ :zoneName
15
+ )
16
+
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module TMS
2
+ class IpawsNwemAuthorization
3
+
4
+ include InstanceResource
5
+
6
+ readonly_attributes :cogid
7
+
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module TMS
2
+ class IpawsNwemAuxilaryData
3
+
4
+ include InstanceResource
5
+ include IpawsResponse
6
+
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module TMS
2
+ class IpawsResponseType
3
+
4
+ include IpawsStaticResource
5
+
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module TMS
2
+ module IpawsStaticResource
3
+ def self.included(base)
4
+ base.send(:include, TMS::InstanceResource)
5
+ base.readonly_attributes :value, :description, :cap_exchange, :core_ipaws_profile, :nwem, :eas_and_public, :cmas
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,30 @@
1
+ module TMS #:nodoc:
2
+ # A Keyword is a word that TMS will detect in an incoming SMS message. Keywords can have Commands, and
3
+ # when an incoming text message has a keyword, TMS will execute the keyword's Commands. Keywords may
4
+ # also have a response text field. If the response text is not blank, the system will send an SMS reply to the user
5
+ # immediately with the given text.
6
+ #
7
+ # @attr name [String] The name of the keyword. The system will scan an incoming SMS for this string (in a case-insensitive manner).
8
+ # @attr response_text [String] (Optional) The static text with which to reply to an SMS to this keyword.
9
+ # This value can be blank, in which case the handset user will not receive a response.
10
+ # Note that all keyword commands will be executed, regardless of the value of response_text.
11
+ #
12
+ # @example
13
+ # keyword = client.keywords.build(:name => "HOWDY")
14
+ # keyword.post
15
+ # keyword.name = "INFO"
16
+ # keyword.response_text = "Please call our support staff at 1-555-555-5555"
17
+ # keyword.put
18
+ # keyword.delete
19
+ class Keyword
20
+ include InstanceResource
21
+
22
+ # @!parse attr_accessor :name, :response_text
23
+ writeable_attributes :name, :response_text
24
+
25
+ ##
26
+ # A CollectionResource of Command objects
27
+ collection_attributes :commands
28
+
29
+ end
30
+ end
@@ -0,0 +1,10 @@
1
+ module TMS #:nodoc:
2
+ class Recipient
3
+ include InstanceResource
4
+ # @!parse attr_accessor :phone
5
+ writeable_attributes :phone
6
+
7
+ # @!parse attr_reader :formatted_phone, :error_message, :status, :completed_at
8
+ readonly_attributes :formatted_phone, :error_message, :status, :completed_at
9
+ end
10
+ end
@@ -0,0 +1,35 @@
1
+ module TMS #:nodoc:
2
+ # An SMSMessage is used to create and send a text message to a collection of Recipient
3
+ # objects.
4
+ #
5
+ #
6
+ # @attr body [String] The content of the SMS. This field will be truncated to 160 characters.
7
+ #
8
+ # @example
9
+ # sms = client.sms_messages.build(:body => "Hello")
10
+ # sms.recipients.build(:phone => "+18001002000")
11
+ # sms.post
12
+ # sms.get
13
+ class SmsMessage
14
+ include InstanceResource
15
+
16
+ # @!parse attr_accessor :body
17
+ writeable_attributes :body
18
+
19
+ # @!parse attr_reader :created_at, :completed_at, :status
20
+ readonly_attributes :created_at, :completed_at, :status
21
+
22
+ ##
23
+ # A CollectionResource of Recipient objects
24
+ collection_attributes :recipients
25
+
26
+ ##
27
+ # A CollectionResource of Recipients that sent successfully
28
+ collection_attribute :sent, 'Recipients'
29
+
30
+ ##
31
+ # A CollectionResource of Recipients that failed
32
+ collection_attribute :failed, 'Recipients'
33
+
34
+ end
35
+ end