hermod 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/README.md +29 -0
- data/lib/hermod/version.rb +1 -1
- data/lib/hermod/xml_section.rb +2 -1
- data/lib/hermod/xml_section_builder.rb +17 -0
- data/spec/hermod/xml_section_builder/datetime_node_spec.rb +32 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f824eee43c5ddbc599aebe96158698b9861b1b38
|
4
|
+
data.tar.gz: 51b60d86ba5750414a51d383757cab4ee9f8af39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a675232e7799a9b03d64f6c4a96043dbaf27cf4f8d31b3e1d01933c920570078d4a22f73c4df5e8e10fe06ba4f1ccc9078d7827469ef0ffbdbdce376ba3c5772
|
7
|
+
data.tar.gz: 8a2cc8a477aab48de66149eb98a54401e56971168e5d656b1d9b9cef52c6f439a3aa1879a706a2f5f491ec8135b7a47287fe87be657a822ac5f9958889ea771a
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -266,6 +266,35 @@ end
|
|
266
266
|
</Example>
|
267
267
|
```
|
268
268
|
|
269
|
+
#### DateTime Nodes
|
270
|
+
|
271
|
+
Datetime nodes let you send through a date and a time to HMRC. It will be
|
272
|
+
converted to the given datetime format which you can specify as a format
|
273
|
+
string in the `formats` option passed to the `Hermod::XmlSection.build`
|
274
|
+
call. Anything that responds to `strftime` can be passed to the node.
|
275
|
+
Anything else will cause an `Hermod::InvalidInputError` exception to be raised.
|
276
|
+
|
277
|
+
*Building an XmlSection*
|
278
|
+
```ruby
|
279
|
+
Example = Hermod::XmlSection.build(formats: {datetime: "%Y-%m-%d %H:%M:%S"}) do |builder|
|
280
|
+
builder.datetime_node :published
|
281
|
+
end
|
282
|
+
```
|
283
|
+
|
284
|
+
*Using that XmlSection*
|
285
|
+
```ruby
|
286
|
+
Example.new do |example|
|
287
|
+
example.published DateTime.new(2014, 9, 3, 10, 42, 50)
|
288
|
+
end
|
289
|
+
```
|
290
|
+
|
291
|
+
*The Resulting XML*
|
292
|
+
```xml
|
293
|
+
<Example>
|
294
|
+
<Published>2014-09-03 10:42:50</Published>
|
295
|
+
</Example>
|
296
|
+
```
|
297
|
+
|
269
298
|
#### Yes Nodes
|
270
299
|
|
271
300
|
Yes nodes allow you to send a boolean value to HMRC provided that value is
|
data/lib/hermod/version.rb
CHANGED
data/lib/hermod/xml_section.rb
CHANGED
@@ -112,6 +112,23 @@ module Hermod
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
+
# Public: defines a node for sending a datetime to HMRC
|
116
|
+
#
|
117
|
+
# name - the name of the node. This will become the name of the method on the XmlSection.
|
118
|
+
# options - a hash of options used to set up validations.
|
119
|
+
#
|
120
|
+
# Returns nothing you should rely on
|
121
|
+
def datetime_node(name, options={})
|
122
|
+
validators = [].tap do |validators|
|
123
|
+
validators << Validators::ValuePresence.new unless options.delete(:optional)
|
124
|
+
validators << Validators::TypeChecker.new(DateTime) { |value| value.respond_to? :strftime }
|
125
|
+
end
|
126
|
+
|
127
|
+
create_method(name, [], validators, options) do |value, attributes|
|
128
|
+
[(value ? value.strftime(format_for(:datetime)) : nil), attributes]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
115
132
|
# Public: defines a node for sending a boolean to HMRC. It will only be
|
116
133
|
# sent if the boolean is true.
|
117
134
|
#
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "minitest_helper"
|
2
|
+
|
3
|
+
module Hermod
|
4
|
+
describe XmlSection do
|
5
|
+
|
6
|
+
DateTimeXml = XmlSection.build do |builder|
|
7
|
+
builder.datetime_node :published
|
8
|
+
builder.datetime_node :redacted, optional: true
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "Date nodes" do
|
12
|
+
subject do
|
13
|
+
DateTimeXml.new do |dummy|
|
14
|
+
dummy.published DateTime.new(2015, 3, 14, 12, 30, 56)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should format the datetime with the given format string" do
|
19
|
+
value_of_node("Published").must_equal "2015-03-14 12:30:56"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should raise an error if given something that isn't a date" do
|
23
|
+
proc { subject.redacted "yesterday" }.must_raise InvalidInputError
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should ignore blank dates if the date is optional" do
|
27
|
+
subject.redacted nil
|
28
|
+
nodes("Redacted").must_be_empty
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hermod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry Mills
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: libxml-ruby
|
@@ -175,6 +175,7 @@ files:
|
|
175
175
|
- spec/hermod/validators/value_presence_spec.rb
|
176
176
|
- spec/hermod/validators/whole_units_spec.rb
|
177
177
|
- spec/hermod/xml_section_builder/date_node_spec.rb
|
178
|
+
- spec/hermod/xml_section_builder/datetime_node_spec.rb
|
178
179
|
- spec/hermod/xml_section_builder/integer_node_spec.rb
|
179
180
|
- spec/hermod/xml_section_builder/monetary_node_spec.rb
|
180
181
|
- spec/hermod/xml_section_builder/parent_node_spec.rb
|
@@ -204,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
205
|
version: '0'
|
205
206
|
requirements: []
|
206
207
|
rubyforge_project:
|
207
|
-
rubygems_version: 2.
|
208
|
+
rubygems_version: 2.2.5
|
208
209
|
signing_key:
|
209
210
|
specification_version: 4
|
210
211
|
summary: A Ruby library for talking to the HMRC Government Gateway.
|
@@ -220,6 +221,7 @@ test_files:
|
|
220
221
|
- spec/hermod/validators/value_presence_spec.rb
|
221
222
|
- spec/hermod/validators/whole_units_spec.rb
|
222
223
|
- spec/hermod/xml_section_builder/date_node_spec.rb
|
224
|
+
- spec/hermod/xml_section_builder/datetime_node_spec.rb
|
223
225
|
- spec/hermod/xml_section_builder/integer_node_spec.rb
|
224
226
|
- spec/hermod/xml_section_builder/monetary_node_spec.rb
|
225
227
|
- spec/hermod/xml_section_builder/parent_node_spec.rb
|