adf_builder 0.0.2 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a45dd0135682b562fe9fe49cacd5590a0da5c702894ae9f0b888d1d48c6536c
4
- data.tar.gz: 479f5c42eb07d457a0196abe35192f719d77a953bf6045739a3944157ff41434
3
+ metadata.gz: 363203a0be498b2a4c64b3a8468fb9f5107c0a64a53f7931ebfc6b5804763b96
4
+ data.tar.gz: 7b1500ef7e17368b62987600f306f216321e5ffdeecfdc439569db89a85cb0d2
5
5
  SHA512:
6
- metadata.gz: 1d43d0eb120efacce6e7e52e610a51435f7d9dbc2f0cd366dbeae29f57eb1446ff220e70ce600dd8adeb9b33a0609d897a34ba4efa519af631777d9413563c6d
7
- data.tar.gz: 63e65e9fa0fe65d6a285bdf52d246ab4f075fefd297fe9fda70d6784358a502ec2924f5dce41f5e5209cbc09835898e646784b9976aa7b237880559bfa297a96
6
+ metadata.gz: 3966f161aeeff1e4657860bf6f87a6d730ffc689c7ff726353ceb2f84c8a87dd942f64374623bd0e7c0532d22e844e9f7bc275534cd9cda7bd3b04ebbad12986
7
+ data.tar.gz: 5eafe81b9c315faf6f9e4f6302fb2f5328916033e3f9ef3507a0618dabcbdf6f59729f2c1dbe772022c4a8ef42b353a06f38ef5bf530048af8e7a54a75d6a6f0
data/CHANGELOG.md CHANGED
@@ -1,11 +1,36 @@
1
1
  ## [Unreleased]
2
- - Add Vehicle structure
3
- - Add Vendor structure
4
- - Add Customer structure
2
+ - Vehicle Structure
3
+ - Remaining Optional Tags that are not free text
4
+ - odometer
5
+ - condition
6
+ - colorcombination
7
+ - imagetag
8
+ - price
9
+ - option
10
+ - finance
11
+ - Expand Structures for all parameters
12
+ - Customer
13
+ - Vehicle
14
+ - Contact
15
+
16
+ ### In many moons
5
17
  - Add Provider structure
6
- - Add Contact structure
7
18
  - Add Price structure
8
19
 
20
+ ## [0.0.6] - 2021-08-08
21
+ - minimal_lead function will remove all previous adf nodes
22
+ - Created ability to reset doc
23
+
24
+ ## [0.0.5] - 2021-08-08
25
+ - Fixed bug that kept us from using the library
26
+
27
+ ## [0.0.4] - 2021-08-08
28
+ - Added Customer, Contact, Vendor basic structure
29
+
30
+
31
+ ## [0.0.3] - 2021-08-04
32
+ - Added ability to add simple vehicle structures
33
+
9
34
  ## [0.0.2] - 2021-08-04
10
35
 
11
36
  - Can create a prospect and dynamically update params and values for the base and parent level
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- adf_builder (0.0.1)
4
+ adf_builder (0.0.6)
5
5
  ox (~> 2.14)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # AdfBuilder
2
- Hopefully this will help with development in the ADF format. The goal is to intuitively create an update an ADF XML file that can easily be added to an email or saved to a file.
2
+ Hopefully this will help with development in the ADF format. The goal is to intuitively create and update an ADF XML file that can easily be added to an email or saved to a file.
3
3
 
4
4
  ## Installation
5
5
 
@@ -10,70 +10,195 @@ gem 'adf_builder'
10
10
  ```
11
11
 
12
12
  And then execute:
13
-
14
- $ bundle install
13
+ ```shell
14
+ $ bundle install
15
+ ```
15
16
 
16
17
  Or install it yourself as:
17
-
18
- $ gem install adf_builder
18
+ ```shell
19
+ $ gem install adf_builder
20
+ ```
19
21
 
20
22
  ## Usage
21
23
 
22
24
  Quickly create the minimal lead found in the spec document
23
-
24
- builder = AdfBuilder::Builder.new
25
- builder.minimal_lead
26
-
25
+ ```ruby
26
+ builder = AdfBuilder::Builder.new
27
+ builder.minimal_lead
28
+ ```
27
29
  Start Building
30
+ ```ruby
31
+ builder = AdfBuilder::Builder.new
32
+ builder.to_xml
33
+ ```
34
+
28
35
 
29
- builder = AdfBuilder::Builder.new
30
- builder.to_xml
36
+ Outputs
37
+ ```xml
38
+ <?ADF version="1.0"?>
39
+
40
+ <?xml version="1.0"?>
41
+ <adf>
42
+ <prospect status="new">
43
+ <requestdate>2021-08-04T15:18:30+04:00</requestdate>
44
+ </prospect>
45
+ </adf>
46
+ ```
31
47
 
32
- Outputs
33
-
34
- <?ADF version="1.0"?>
35
- <?xml version="1.0"?>
36
- <adf>
37
- <prospect status="new">
38
- <requestdate>2021-08-04T15:18:30+04:00</requestdate>
39
- </prospect>
40
- </adf>
41
48
 
42
49
  Update Requestdate value
50
+ ```ruby
51
+ builder = AdfBuilder::Builder.new
52
+ builder.prospect.request_date.update_val(Date.new(2021,12,12))
53
+ ```
54
+ Outputs
43
55
 
44
- builder = AdfBuilder::Builder.new
45
- builder.base.prospect.request_date.update_val(Date.new(2021,12,12))
56
+ ```xml
57
+ <?ADF version="1.0"?>
46
58
 
47
- Outputs
59
+ <?xml version="1.0"?>
60
+ <adf>
61
+ <prospect status="new">
62
+ <requestdate>2021-12-12T00:00:00+00:00</requestdate>
63
+ </prospect>
64
+ </adf>
65
+ ```
48
66
 
49
- <?ADF version="1.0"?>
50
-
51
- <?xml version="1.0"?>
52
- <adf>
53
- <prospect status="new">
54
- <requestdate>2021-12-12T00:00:00+00:00</requestdate>
55
- </prospect>
56
- </adf>
57
67
 
58
68
  Add ID tag to Prospect
69
+ ```ruby
70
+ builder = AdfBuilder::Builder.new
71
+ builder.prospect.add_id('howdy', 'Ag')
72
+ ```
73
+
74
+ Outputs
75
+ ```xml
76
+ <?ADF version="1.0"?>
77
+
78
+ <?xml version="1.0"?>
79
+ <adf>
80
+ <prospect status="new">
81
+ <id sequence="1" source="Ag">howdy</id>
82
+ <requestdate>2021-08-04T15:24:16+04:00</requestdate>
83
+ </prospect>
84
+ </adf>
85
+ ```
86
+
87
+ Add Vehicle
59
88
 
60
- builder = AdfBuilder::Builder.new
61
- builder.base.prospect.add_id('howdy', 'Ag')
89
+ ```ruby
90
+ builder = AdfBuilder::Builder.new
91
+ builder.prospect.vehicles.add(2021, 'Ford', 'Raptor')
92
+ ```
93
+
94
+ Outputs
95
+
96
+ ```xml
97
+ <?ADF version="1.0"?>
98
+
99
+ <?xml version="1.0"?>
100
+ <adf>
101
+ <prospect status="new">
102
+ <requestdate>2021-08-04T18:08:50+04:00</requestdate>
103
+ <vehicle interest="buy" status="new">
104
+ <year>2021</year>
105
+ <make>Ford</make>
106
+ <model>Raptor</model>
107
+ </vehicle>
108
+ </prospect>
109
+ </adf>
110
+ ```
111
+ Add Vehicle with tags
112
+
113
+ ```ruby
114
+ builder = AdfBuilder::Builder.new
115
+ builder.prospect.vehicles.add(2021, 'Toyota', 'Prius', {
116
+ interest: :sell,
117
+ status: :used,
118
+ vin: 'XXXXXXXXXX',
119
+ })
120
+ ```
121
+
122
+ Outputs
123
+
124
+ ```xml
125
+ <?ADF version="1.0"?>
126
+
127
+ <?xml version="1.0"?>
128
+ <adf>
129
+ <prospect status="new">
130
+ <requestdate>2021-08-04T18:16:31+04:00</requestdate>
131
+ <vehicle interest="sell" status="used">
132
+ <year>2021</year>
133
+ <make>Toyota</make>
134
+ <model>Prius</model>
135
+ <vin>XXXXXXXXXX</vin>
136
+ </vehicle>
137
+ </prospect>
138
+ </adf>
139
+
140
+ ```
141
+
142
+ Add Vendor
143
+
144
+ ```ruby
145
+ builder = AdfBuilder::Builder.new
146
+ builder.prospect.vendor.add('Dealer One', 'Manager Name', {
147
+ part: 'full',
148
+ type: 'individual'
149
+ }) # options for customer object that is required in vendor
150
+ ```
62
151
 
63
152
  Outputs
64
153
 
65
- <?ADF version="1.0"?>
66
-
67
- <?xml version="1.0"?>
68
- <adf>
69
- <prospect status="new">
70
- <id sequence="1" source="Ag">howdy</id>
71
- <requestdate>2021-08-04T15:24:16+04:00</requestdate>
72
- </prospect>
73
- </adf>
154
+ ```xml
155
+ <?ADF version="1.0"?>
156
+
157
+ <?xml version="1.0"?>
158
+ <adf>
159
+ <prospect status="new">
160
+ <requestdate>2021-08-08T18:43:02+04:00</requestdate>
161
+ <customer/>
162
+ <vendor>
163
+ <vendorname>Dealer One</vendorname>
164
+ <contact>
165
+ <name part="full" type="individual">Manager Name</name>
166
+ </contact>
167
+ </vendor>
168
+ </prospect>
169
+ </adf>
170
+ ```
171
+
172
+ Add Contact with phone
74
173
 
174
+ ```ruby
175
+ builder = AdfBuilder::Builder.new
176
+ builder.prospect.customer.add('New Guy', {
177
+ part: 'full',
178
+ type: 'individual'
179
+ })
180
+ builder.prospect.customer.contact.add_phone('(555)-444-3333')
181
+ ```
75
182
 
183
+ Outputs
76
184
 
185
+ ```xml
186
+ <?ADF version="1.0"?>
187
+
188
+ <?xml version="1.0"?>
189
+ <adf>
190
+ <prospect status="new">
191
+ <requestdate>2021-08-08T18:44:45+04:00</requestdate>
192
+ <customer>
193
+ <contact>
194
+ <name part="full" type="individual">New Guy</name>
195
+ <phone>(555)-444-3333</phone>
196
+ </contact>
197
+ </customer>
198
+ <vendor/>
199
+ </prospect>
200
+ </adf>
201
+ ```
77
202
  ## Development
78
203
 
79
204
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/adf_builder.rb CHANGED
@@ -1,13 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'ox'
3
4
  require_relative "adf_builder/version"
4
- require_relative 'adf_builder/base'
5
+
6
+ # CUSTOMER
7
+ require_relative 'adf_builder/customer/customer'
8
+
9
+ # BASE
10
+ require_relative 'adf_builder/base/base'
5
11
  require_relative 'adf_builder/base/prospect'
6
12
  require_relative 'adf_builder/base/request_date'
7
- require_relative 'adf_builder/id'
8
13
 
14
+ # SHARED
15
+ require_relative 'adf_builder/shared/id'
16
+ require_relative 'adf_builder/shared/contact'
9
17
 
10
- require 'ox'
18
+ # VEHICLES
19
+ require_relative 'adf_builder/vehicles/vehicles'
20
+
21
+ # VENDER
22
+ require_relative 'adf_builder/vendor/vendor'
11
23
 
12
24
  module AdfBuilder
13
25
  class Error < StandardError; end
@@ -17,8 +29,8 @@ module AdfBuilder
17
29
  @base = Base.new(@doc)
18
30
  end
19
31
 
20
- def base
21
- @base
32
+ def prospect
33
+ @base.prospect
22
34
  end
23
35
 
24
36
  # output the XML
@@ -28,8 +40,6 @@ module AdfBuilder
28
40
 
29
41
  # def an example of minimal XML taken from ADF spec file http://adfxml.info/adf_spec.pdf
30
42
  def minimal_lead
31
- adf = Ox::Element.new("adf")
32
-
33
43
  prospect = Ox::Element.new("prospect")
34
44
 
35
45
  request_date = Ox::Element.new("requestdate")
@@ -72,16 +82,15 @@ module AdfBuilder
72
82
  vendor << contact
73
83
 
74
84
  prospect << request_date << vehicle << customer << vendor
75
- adf << prospect
76
- @doc << adf
85
+ @doc.remove_children_by_path("adf/prospect")
86
+ @doc.adf << prospect
77
87
  Ox.dump(@doc, {})
78
88
  end
79
89
 
80
-
81
-
82
-
83
- private
84
-
90
+ # go back to the initial structure
91
+ def reset_doc
92
+ @doc.adf.prospect.remove_children_by_path("*")
93
+ end
85
94
 
86
95
  # all the files will start with this same header
87
96
  def init_doc
@@ -9,7 +9,5 @@ module AdfBuilder
9
9
  def prospect
10
10
  @prospect
11
11
  end
12
-
13
-
14
12
  end
15
13
  end
@@ -10,13 +10,30 @@ module AdfBuilder
10
10
  @doc.adf << Ox::Element.new("prospect")
11
11
  @prospect = @doc.adf.prospect
12
12
  @prospect[:status] = STATUSES[:new]
13
+
14
+
13
15
  @request_date = RequestDate.new(@prospect)
16
+ @vehicles = Vehicles.new(@prospect)
17
+ @customer = Customer.new(@prospect)
18
+ @vendor = Vendor.new(@prospect)
14
19
  end
15
20
 
16
21
  def request_date
17
22
  @request_date
18
23
  end
19
24
 
25
+ def vehicles
26
+ @vehicles
27
+ end
28
+
29
+ def customer
30
+ @customer
31
+ end
32
+
33
+ def vendor
34
+ @vendor
35
+ end
36
+
20
37
  # set status to renew
21
38
  def set_renew
22
39
  @prospect[:status] = STATUSES[:resend]
@@ -7,7 +7,6 @@ module AdfBuilder
7
7
  @request_date_node = Ox::Element.new('requestdate')
8
8
  @request_date_node << DateTime.now.strftime('%FT%T%:z')
9
9
  prospect_node << @request_date_node
10
- @request_date_node
11
10
  end
12
11
 
13
12
  def update_val(datetime_value, format=1)
@@ -0,0 +1,27 @@
1
+ module AdfBuilder
2
+ class Customer
3
+ def initialize(prospect)
4
+ @customer = Ox::Element.new('customer')
5
+ @contact = nil
6
+
7
+ prospect << @customer
8
+ end
9
+
10
+ def contact
11
+ @contact
12
+ end
13
+
14
+ def add(name, opts={})
15
+ @contact = Contact.new(@customer, name, opts)
16
+ end
17
+
18
+ def add_id(index, value, source=nil, sequence=1)
19
+ if @prospect.locate("customer").empty?
20
+ false
21
+ else
22
+ Id.new.add(@prospect.customer(index), value, source, sequence)
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,55 @@
1
+ module AdfBuilder
2
+ class Contact
3
+ VALID_PARAMETERS = {
4
+ name: [:part, :type, :primarycontact],
5
+ email: [:preferredcontact],
6
+ phone: [:type, :time, :preferredcontact]
7
+ }
8
+
9
+ PHONE_TYPES = [:phone, :fax, :cellphone, :pager]
10
+
11
+ def initialize(parent_node, name, opts={})
12
+ @contact = Ox::Element.new('contact') << (Ox::Element.new('name') << name)
13
+ parent_node << @contact
14
+
15
+ opts = whitelabel_opts(opts, :name)
16
+
17
+ if opts[:primary_contact]
18
+ @contact[:primarycontact] = opts[:primary_contact].to_s
19
+ end
20
+
21
+ opts.each do |k,v|
22
+ @contact.locate("name")[0][k] = v.to_s
23
+ end
24
+
25
+ end
26
+
27
+ def add_email(email, opts={})
28
+ @contact << (Ox::Element.new('email') << email)
29
+ opts = whitelabel_opts(opts, :phone)
30
+
31
+ opts.each do |k,v|
32
+ @contact.email[k] = v.to_s
33
+ end
34
+ end
35
+
36
+ def add_phone(phone, opts={})
37
+ @contact << (Ox::Element.new('phone') << phone)
38
+ opts = whitelabel_opts(opts, :phone)
39
+
40
+ opts.each do |k,v|
41
+ @contact.phone[k] = v.to_s
42
+ end
43
+ end
44
+
45
+
46
+
47
+
48
+ private
49
+
50
+ # clear out the opts that don't match valid keys
51
+ def whitelabel_opts(opts, key)
52
+ opts.slice(*VALID_PARAMETERS[key])
53
+ end
54
+ end
55
+ end
File without changes
@@ -0,0 +1,69 @@
1
+ module AdfBuilder
2
+ class Vehicles
3
+ INTEREST_VALUES = {
4
+ buy: 'buy',
5
+ lease: 'lease',
6
+ sell: 'sell',
7
+ trade_in: 'trade-in',
8
+ test_drive: 'test-drive'
9
+ }
10
+
11
+ STATUS_VALUES = {
12
+ new: 'new',
13
+ used: 'used'
14
+ }
15
+
16
+ FREE_TEXT_OPTIONAL_TAGS = {
17
+ vin: :vin,
18
+ stock: :stock,
19
+ trim: :trim,
20
+ doors: :doors,
21
+ bodystyle: :bodystyle,
22
+ transmission: :transmission,
23
+ pricecomments: :pricecomments,
24
+ comments: :comments
25
+ }
26
+
27
+ def initialize(prospect)
28
+ @prospect = prospect
29
+ end
30
+
31
+ def add(year, make, model, tags={})
32
+ vehicle = Ox::Element.new('vehicle')
33
+
34
+ if tags[:interest]
35
+ interest = INTEREST_VALUES[tags[:interest].to_sym]
36
+ tags.delete(:interest)
37
+ vehicle[:interest] = interest
38
+ end
39
+
40
+ if tags[:status]
41
+ status = STATUS_VALUES[tags[:status].to_sym]
42
+ tags.delete(:status)
43
+ vehicle[:status] = status
44
+ end
45
+
46
+
47
+ vehicle << (Ox::Element.new('year') << year.to_s)
48
+ vehicle << (Ox::Element.new('make') << make)
49
+ vehicle << (Ox::Element.new('model') << model)
50
+
51
+ tags.each do |key, value|
52
+ if FREE_TEXT_OPTIONAL_TAGS.include? key.to_sym
53
+ vehicle << (Ox::Element.new(key.to_s) << value)
54
+ end
55
+ end
56
+
57
+ @prospect << vehicle
58
+ end
59
+
60
+ def add_id(index, value, source=nil, sequence=1)
61
+ if @prospect.locate("vehicle").empty? or @prospect.vehicle(index).nil?
62
+ false
63
+ else
64
+ Id.new.add(@prospect.vehicle(index), value, source, sequence)
65
+ end
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,34 @@
1
+ module AdfBuilder
2
+ class Vendor
3
+ def initialize(prospect)
4
+ @vendor = Ox::Element.new('vendor')
5
+ @contact = nil
6
+ prospect << @vendor
7
+ end
8
+
9
+ def contact
10
+ @contact
11
+ end
12
+
13
+ def add(name, contact_name, opts={})
14
+ @vendor << (Ox::Element.new('vendorname') << name)
15
+ @contact = Contact.new(@vendor, contact_name, opts)
16
+ end
17
+
18
+ def add_url(url)
19
+ if @vendor.locate("url").size > 0
20
+ @vendor.remove_children(@vendor.url)
21
+ end
22
+ @vendor << (Ox::Element.new('url') << url)
23
+ end
24
+
25
+ def add_id(index, value, source=nil, sequence=1)
26
+ if @prospect.locate("vendor").empty?
27
+ false
28
+ else
29
+ Id.new.add(@prospect.vendor(index), value, source, sequence)
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AdfBuilder
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adf_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - marcus.salinas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-04 00:00:00.000000000 Z
11
+ date: 2021-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ox
@@ -45,10 +45,14 @@ files:
45
45
  - bin/console
46
46
  - bin/setup
47
47
  - lib/adf_builder.rb
48
- - lib/adf_builder/base.rb
48
+ - lib/adf_builder/base/base.rb
49
49
  - lib/adf_builder/base/prospect.rb
50
50
  - lib/adf_builder/base/request_date.rb
51
- - lib/adf_builder/id.rb
51
+ - lib/adf_builder/customer/customer.rb
52
+ - lib/adf_builder/shared/contact.rb
53
+ - lib/adf_builder/shared/id.rb
54
+ - lib/adf_builder/vehicles/vehicles.rb
55
+ - lib/adf_builder/vendor/vendor.rb
52
56
  - lib/adf_builder/version.rb
53
57
  homepage: https://github.com/jippylong12/adf_builder
54
58
  licenses: