govdelivery-tms 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -5
  3. data/README.md +0 -32
  4. data/Rakefile +4 -6
  5. data/govdelivery-tms.gemspec +15 -15
  6. data/lib/govdelivery-tms.rb +0 -9
  7. data/lib/govdelivery/tms/base.rb +4 -6
  8. data/lib/govdelivery/tms/client.rb +15 -16
  9. data/lib/govdelivery/tms/collection_resource.rb +7 -8
  10. data/lib/govdelivery/tms/connection.rb +4 -4
  11. data/lib/govdelivery/tms/errors.rb +7 -8
  12. data/lib/govdelivery/tms/instance_resource.rb +34 -39
  13. data/lib/govdelivery/tms/link_header.rb +27 -28
  14. data/lib/govdelivery/tms/mail/delivery_method.rb +11 -14
  15. data/lib/govdelivery/tms/resource/collections.rb +0 -20
  16. data/lib/govdelivery/tms/resource/command.rb +1 -2
  17. data/lib/govdelivery/tms/resource/command_action.rb +1 -1
  18. data/lib/govdelivery/tms/resource/command_type.rb +8 -9
  19. data/lib/govdelivery/tms/resource/email_message.rb +0 -1
  20. data/lib/govdelivery/tms/resource/email_recipient.rb +1 -1
  21. data/lib/govdelivery/tms/resource/from_address.rb +1 -1
  22. data/lib/govdelivery/tms/resource/inbound_sms_message.rb +1 -1
  23. data/lib/govdelivery/tms/resource/keyword.rb +6 -7
  24. data/lib/govdelivery/tms/resource/recipient.rb +1 -1
  25. data/lib/govdelivery/tms/resource/sms_message.rb +0 -1
  26. data/lib/govdelivery/tms/util/core_ext.rb +3 -3
  27. data/lib/govdelivery/tms/util/hal_link_parser.rb +11 -12
  28. data/lib/govdelivery/tms/version.rb +1 -1
  29. data/spec/client_spec.rb +6 -6
  30. data/spec/command_types_spec.rb +14 -14
  31. data/spec/email_message_spec.rb +42 -45
  32. data/spec/email_template_spec.rb +49 -51
  33. data/spec/errors_spec.rb +3 -3
  34. data/spec/from_address_spec.rb +37 -36
  35. data/spec/inbound_sms_messages_spec.rb +2 -2
  36. data/spec/instance_resource_spec.rb +4 -6
  37. data/spec/keyword_spec.rb +8 -10
  38. data/spec/keywords_spec.rb +4 -4
  39. data/spec/mail/delivery_method_spec.rb +8 -9
  40. data/spec/sms_message_spec.rb +9 -11
  41. data/spec/sms_messages_spec.rb +3 -3
  42. data/spec/spec_helper.rb +4 -5
  43. data/spec/tms_spec.rb +3 -3
  44. metadata +34 -64
  45. data/lib/govdelivery/tms/resource/ipaws_acknowledgement.rb +0 -9
  46. data/lib/govdelivery/tms/resource/ipaws_alert.rb +0 -38
  47. data/lib/govdelivery/tms/resource/ipaws_category.rb +0 -7
  48. data/lib/govdelivery/tms/resource/ipaws_cog_profile.rb +0 -29
  49. data/lib/govdelivery/tms/resource/ipaws_event_code.rb +0 -7
  50. data/lib/govdelivery/tms/resource/ipaws_nwem_area.rb +0 -18
  51. data/lib/govdelivery/tms/resource/ipaws_nwem_authorization.rb +0 -9
  52. data/lib/govdelivery/tms/resource/ipaws_nwem_auxilary_data.rb +0 -8
  53. data/lib/govdelivery/tms/resource/ipaws_response_type.rb +0 -7
  54. data/lib/govdelivery/tms/resource/ipaws_static_resource.rb +0 -8
  55. data/spec/ipaws_acknowledgement_spec.rb +0 -16
  56. data/spec/ipaws_alerts_spec.rb +0 -192
  57. data/spec/ipaws_cog_profile_spec.rb +0 -75
  58. data/spec/ipaws_event_codes_spec.rb +0 -35
  59. data/spec/ipaws_nwem_areas_spec.rb +0 -58
  60. data/spec/ipaws_nwem_authorization_spec.rb +0 -16
@@ -1,5 +1,5 @@
1
1
  # link_header, Copyright (c) 2009 Mike Burrows
2
-
2
+
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
-
10
+
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
-
13
+
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -19,17 +19,16 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- require "strscan"
22
+ require 'strscan'
23
23
 
24
24
  #
25
25
  # Represents an HTTP link header of the form described in the draft spec http://tools.ietf.org/id/draft-nottingham-http-link-header-06.txt.
26
26
  # It is simply a list of LinkHeader::Link objects and some conversion functions.
27
27
  #
28
28
  class LinkHeader
29
-
30
29
  # An array of Link objects
31
30
  attr_reader :links
32
-
31
+
33
32
  #
34
33
  # Initialize from a collection of either LinkHeader::Link objects or data from which Link objects can be created.
35
34
  #
@@ -47,14 +46,14 @@ class LinkHeader
47
46
  #
48
47
  # See also LinkHeader.parse
49
48
  #
50
- def initialize(links=[])
49
+ def initialize(links = [])
51
50
  if links
52
- @links = links.map{|l| l.kind_of?(Link) ? l : Link.new(*l)}
51
+ @links = links.map { |l| l.is_a?(Link) ? l : Link.new(*l) }
53
52
  else
54
53
  @links = []
55
54
  end
56
55
  end
57
-
56
+
58
57
  #
59
58
  # Convert to a JSON-friendly array
60
59
  #
@@ -63,9 +62,9 @@ class LinkHeader
63
62
  # ["http://example.com/", [["rel", "up"]]]]
64
63
  #
65
64
  def to_a
66
- links.map{|l| l.to_a}
65
+ links.map(&:to_a)
67
66
  end
68
-
67
+
69
68
  #
70
69
  # Convert to string representation as per the link header spec
71
70
  #
@@ -77,7 +76,7 @@ class LinkHeader
77
76
  def to_s
78
77
  links.join(', ')
79
78
  end
80
-
79
+
81
80
  #
82
81
  # Regexes for link header parsing. TOKEN and QUOTED in particular should conform to RFC2616.
83
82
  #
@@ -100,7 +99,7 @@ class LinkHeader
100
99
  #
101
100
  def self.parse(link_header)
102
101
  return new unless link_header
103
-
102
+
104
103
  scanner = StringScanner.new(link_header)
105
104
  links = []
106
105
  while scanner.scan(HREF)
@@ -117,7 +116,7 @@ class LinkHeader
117
116
 
118
117
  new(links)
119
118
  end
120
-
119
+
121
120
  #
122
121
  # Find a member link that has the given attributes
123
122
  #
@@ -126,14 +125,14 @@ class LinkHeader
126
125
  !attr_pairs.detect do |pair|
127
126
  !link.attr_pairs.include?(pair)
128
127
  end
129
- end
128
+ end
130
129
  end
131
-
130
+
132
131
  #
133
132
  # Render as a list of HTML link elements
134
133
  #
135
- def to_html(separator="\n")
136
- links.map{|link| link.to_html}.join(separator)
134
+ def to_html(separator = "\n")
135
+ links.map(&:to_html).join(separator)
137
136
  end
138
137
 
139
138
  #
@@ -150,7 +149,7 @@ class LinkHeader
150
149
  # => 'http://example.com/foo>'
151
150
  #
152
151
  attr_reader :href
153
-
152
+
154
153
  #
155
154
  # The link's attributes, an array of key-value pairs
156
155
  #
@@ -158,7 +157,7 @@ class LinkHeader
158
157
  # => [["rel", "self"], ["rel", "canonical"]]
159
158
  #
160
159
  attr_reader :attr_pairs
161
-
160
+
162
161
  #
163
162
  # Initialize a Link from an href and attribute list
164
163
  #
@@ -168,7 +167,7 @@ class LinkHeader
168
167
  def initialize(href, attr_pairs)
169
168
  @href, @attr_pairs = href, attr_pairs
170
169
  end
171
-
170
+
172
171
  #
173
172
  # Lazily convert the attribute list to a Hash
174
173
  #
@@ -180,14 +179,14 @@ class LinkHeader
180
179
  def attrs
181
180
  @attrs ||= Hash[*attr_pairs.flatten]
182
181
  end
183
-
182
+
184
183
  #
185
184
  # Access #attrs by key
186
185
  #
187
186
  def [](key)
188
187
  attrs[key]
189
188
  end
190
-
189
+
191
190
  #
192
191
  # Convert to a JSON-friendly Array
193
192
  #
@@ -197,7 +196,7 @@ class LinkHeader
197
196
  def to_a
198
197
  [href, attr_pairs]
199
198
  end
200
-
199
+
201
200
  #
202
201
  # Convert to string representation as per the link header spec. This includes backspace-escaping doublequote characters in
203
202
  # quoted attribute values.
@@ -208,16 +207,16 @@ class LinkHeader
208
207
  # #=> '<http://example.com/foo>; rel="self"'
209
208
  #
210
209
  def to_s
211
- (["<#{href}>"] + attr_pairs.map{|k, v| "#{k}=\"#{v.gsub(/"/, '\"')}\""}).join('; ')
210
+ (["<#{href}>"] + attr_pairs.map { |k, v| "#{k}=\"#{v.gsub(/"/, '\"')}\"" }).join('; ')
212
211
  end
213
-
212
+
214
213
  #
215
214
  # Bonus! Render as an HTML link element
216
215
  #
217
216
  # LinkHeader::Link.new(["http://example.com/foo", [["rel", "self"]]]).to_html
218
217
  # #=> '<link href="http://example.com/foo" rel="self">'
219
218
  def to_html
220
- ([%Q(<link href="#{href}")] + attr_pairs.map{|k, v| "#{k}=\"#{v.gsub(/"/, '\"')}\""}).join(' ')
219
+ ([%(<link href="#{href}")] + attr_pairs.map { |k, v| "#{k}=\"#{v.gsub(/"/, '\"')}\"" }).join(' ')
221
220
  end
222
221
  end
223
- end
222
+ end
@@ -24,17 +24,15 @@ module GovDelivery::TMS
24
24
  attr_accessor :settings
25
25
 
26
26
  def deliver!(mail)
27
- raise GovDelivery::TMS::Errors::NoRelation.new('email_messages', client) unless client.respond_to?(:email_messages)
28
-
29
- envelope_from = mail.return_path || mail.sender || mail.from_addrs.first
27
+ fail GovDelivery::TMS::Errors::NoRelation.new('email_messages', client) unless client.respond_to?(:email_messages)
30
28
 
31
29
  body = case
32
- when mail.html_part
33
- mail.html_part.body
34
- when mail.text_part
35
- mail.text_part.body
36
- else
37
- mail.body
30
+ when mail.html_part
31
+ mail.html_part.body
32
+ when mail.text_part
33
+ mail.text_part.body
34
+ else
35
+ mail.body
38
36
  end.decoded
39
37
 
40
38
  tms_message = client.email_messages.build(
@@ -56,8 +54,7 @@ module GovDelivery::TMS
56
54
  end
57
55
 
58
56
  if defined?(ActionMailer)
59
- ActionMailer::Base.add_delivery_method :govdelivery_tms, GovDelivery::TMS::Mail::DeliveryMethod, {
60
- auth_token: nil,
61
- logger: ActionMailer::Base.logger,
62
- api_root: GovDelivery::TMS::Client::DEFAULTS[:api_root]}
63
- end
57
+ ActionMailer::Base.add_delivery_method :govdelivery_tms, GovDelivery::TMS::Mail::DeliveryMethod, auth_token: nil,
58
+ logger: ActionMailer::Base.logger,
59
+ api_root: GovDelivery::TMS::Client::DEFAULTS[:api_root]
60
+ end
@@ -60,26 +60,6 @@ class GovDelivery::TMS::CommandActions
60
60
  include GovDelivery::TMS::CollectionResource
61
61
  end
62
62
 
63
- class GovDelivery::TMS::IpawsEventCodes
64
- include GovDelivery::TMS::CollectionResource
65
- end
66
-
67
- class GovDelivery::TMS::IpawsCategories
68
- include GovDelivery::TMS::CollectionResource
69
- end
70
-
71
- class GovDelivery::TMS::IpawsResponseTypes
72
- include GovDelivery::TMS::CollectionResource
73
- end
74
-
75
- class GovDelivery::TMS::IpawsAlerts
76
- include GovDelivery::TMS::CollectionResource
77
- end
78
-
79
- class GovDelivery::TMS::IpawsNwemAreas
80
- include GovDelivery::TMS::CollectionResource
81
- end
82
-
83
63
  class GovDelivery::TMS::Webhooks
84
64
  include GovDelivery::TMS::CollectionResource
85
65
  end
@@ -20,6 +20,5 @@ module GovDelivery::TMS #:nodoc:
20
20
 
21
21
  # @!parse attr_reader :created_at, :updated_at
22
22
  readonly_attributes :created_at, :updated_at
23
-
24
23
  end
25
- end
24
+ end
@@ -14,4 +14,4 @@ module GovDelivery::TMS #:nodoc:
14
14
 
15
15
  readonly_attributes :status, :content_type, :response_body, :created_at
16
16
  end
17
- end
17
+ end
@@ -2,19 +2,18 @@ module GovDelivery::TMS #:nodoc:
2
2
  # CommandType is a pair of values (name, string_fields, array_fields) that can be attached
3
3
  # to a Keyword (in a Command object).
4
4
  #
5
- # This resource is read-only.
5
+ # This resource is read-only.
6
6
  #
7
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
- #
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
13
  class CommandType
14
-
15
14
  include InstanceResource
16
-
15
+
17
16
  # @!parse attr_reader :string_fields, :array_fields, :name
18
17
  readonly_attributes :name, :string_fields, :array_fields
19
18
  end
20
- end
19
+ end
@@ -54,7 +54,6 @@ module GovDelivery::TMS #:nodoc:
54
54
  :reply_to,
55
55
  :subject
56
56
 
57
-
58
57
  # @!parse attr_reader :created_at, :status
59
58
  readonly_attributes :created_at, :status
60
59
 
@@ -3,7 +3,7 @@ module GovDelivery::TMS #:nodoc:
3
3
  #
4
4
  # @attr email [String] The recipient email address
5
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
- #
6
+ #
7
7
  # @example Sending a message
8
8
  # email_message = client.email_messages.build(:subject => "Great news!", :body => "You win! <a href='http://example.com/'>click here</a>.")
9
9
  # email_message.recipients.build(:email => "john@example.com")
@@ -5,6 +5,6 @@ module GovDelivery::TMS #:nodoc:
5
5
  # @!parse attr_accessor :from_email, :reply_to_email, :bounce_email, :is_default
6
6
  writeable_attributes :from_email, :reply_to_email, :bounce_email, :is_default
7
7
 
8
- readonly_attributes :created_at
8
+ readonly_attributes :created_at
9
9
  end
10
10
  end
@@ -1,7 +1,7 @@
1
1
  module GovDelivery::TMS #:nodoc:
2
2
  class InboundSmsMessage
3
3
  include InstanceResource
4
-
4
+
5
5
  # @!parse attr_reader :created_at, :completed_at, :from, :body, :to, :command_status
6
6
  readonly_attributes :created_at, :completed_at, :from, :body, :to, :command_status, :keyword_response
7
7
  end
@@ -1,14 +1,14 @@
1
1
  module GovDelivery::TMS #:nodoc:
2
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
3
+ # when an incoming text message has a keyword, TMS will execute the keyword's Commands. Keywords may
4
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.
5
+ # immediately with the given text.
6
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).
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
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.
9
+ # This value can be blank, in which case the handset user will not receive a response.
10
10
  # Note that all keyword commands will be executed, regardless of the value of response_text.
11
- #
11
+ #
12
12
  # @example
13
13
  # keyword = client.keywords.build(:name => "HOWDY")
14
14
  # keyword.post
@@ -25,6 +25,5 @@ module GovDelivery::TMS #:nodoc:
25
25
  ##
26
26
  # A CollectionResource of Command objects
27
27
  collection_attributes :commands
28
-
29
28
  end
30
- end
29
+ end
@@ -7,4 +7,4 @@ module GovDelivery::TMS #:nodoc:
7
7
  # @!parse attr_reader :formatted_phone, :error_message, :status, :completed_at
8
8
  readonly_attributes :formatted_phone, :error_message, :status, :completed_at
9
9
  end
10
- end
10
+ end
@@ -30,6 +30,5 @@ module GovDelivery::TMS #:nodoc:
30
30
  ##
31
31
  # A CollectionResource of Recipients that failed
32
32
  collection_attribute :failed, 'Recipients'
33
-
34
33
  end
35
34
  end
@@ -10,8 +10,8 @@ module GovDelivery::TMS::CoreExt
10
10
  end
11
11
 
12
12
  def singularize(str)
13
- ActiveSupport::Inflector.singularize(str)
14
- end
13
+ ActiveSupport::Inflector.singularize(str)
14
+ end
15
15
 
16
16
  def pluralize(str)
17
17
  ActiveSupport::Inflector.pluralize(str)
@@ -24,4 +24,4 @@ module GovDelivery::TMS::CoreExt
24
24
  def instance_class(klass)
25
25
  ActiveSupport::Inflector.constantize(singularize(klass.to_s))
26
26
  end
27
- end
27
+ end
@@ -1,11 +1,10 @@
1
1
  module GovDelivery::TMS::Util
2
2
  module HalLinkParser
3
-
4
- def parse_links(_links)
3
+ def parse_links(links)
5
4
  @resources = {}
6
- return if _links.nil?
7
- parse_link(_links) and return if _links.is_a?(Hash)
8
- _links.each { |link| parse_link(link) }
5
+ return if links.nil?
6
+ parse_link(links) && return if links.is_a?(Hash)
7
+ links.each { |link| parse_link(link) }
9
8
  end
10
9
 
11
10
  def subresources
@@ -15,8 +14,8 @@ module GovDelivery::TMS::Util
15
14
  protected
16
15
 
17
16
  def metaclass
18
- @metaclass ||= class << self;
19
- self;
17
+ @metaclass ||= class << self
18
+ self
20
19
  end
21
20
  end
22
21
 
@@ -26,12 +25,12 @@ module GovDelivery::TMS::Util
26
25
  self.href = href
27
26
  else
28
27
  klass = relation_class(rel)
29
- klass = self.class if ['first', 'prev', 'next', 'last'].include?(rel)
28
+ klass = self.class if %w(first prev next last).include?(rel)
30
29
  if klass
31
- subresources[rel] = klass.new(self.client, href)
30
+ subresources[rel] = klass.new(client, href)
32
31
  setup_subresource(link)
33
32
  else
34
- logger.info("Don't know what to do with link rel '#{rel}' for class #{self.class.to_s}!") if self.respond_to?(:logger)
33
+ logger.info("Don't know what to do with link rel '#{rel}' for class #{self.class}!") if self.respond_to?(:logger)
35
34
  end
36
35
 
37
36
  end
@@ -44,7 +43,7 @@ module GovDelivery::TMS::Util
44
43
 
45
44
  def setup_subresource(link)
46
45
  return unless link
47
- link.each { |rel, href| self.metaclass.send(:define_method, rel.to_sym, &lambda { subresources[rel] }) unless rel == 'self' }
46
+ link.each { |rel, _href| metaclass.send(:define_method, rel.to_sym, &lambda { subresources[rel] }) unless rel == 'self' }
48
47
  end
49
48
  end
50
- end
49
+ end