wildcard-pair 0.3.1
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 +7 -0
- data/lib/wildcard-pair.rb +5 -0
- data/lib/wildcard-pair/Article.rb +90 -0
- data/lib/wildcard-pair/ArticleCard.rb +84 -0
- data/lib/wildcard-pair/Color.rb +41 -0
- data/lib/wildcard-pair/Media.rb +4 -0
- data/lib/wildcard-pair/Media/Image.rb +46 -0
- data/lib/wildcard-pair/Media/Video.rb +70 -0
- data/lib/wildcard-pair/Offer.rb +102 -0
- data/lib/wildcard-pair/Price.rb +44 -0
- data/lib/wildcard-pair/Product.rb +132 -0
- data/lib/wildcard-pair/ProductCard.rb +117 -0
- data/lib/wildcard-pair/ProductSearchCard.rb +89 -0
- data/lib/wildcard-pair/ProductSearchResult.rb +54 -0
- data/lib/wildcard-pair/Rating.rb +47 -0
- data/lib/wildcard-pair/Review.rb +105 -0
- data/lib/wildcard-pair/ReviewCard.rb +82 -0
- data/lib/wildcard-pair/VideoCard.rb +84 -0
- data/lib/wildcard-pair/hash_mappable.rb +18 -0
- data/lib/wildcard-pair/util/extract_metatags.rb +99 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a87d389d67f030de00b57384d85e7cc5ca9ff253
|
4
|
+
data.tar.gz: f9a7c892fef9e4e230d54b007c5da78455b4a767
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 46aba80a945c50cf02ffc8528be3bcff27c289cda1ae59d2fc518e9b5267813f99fe306964083ab848ebd9a50a0b8b9de732805b138d698270f7c14e0879ab43
|
7
|
+
data.tar.gz: e3346365a27cebeaeb36bc690e76cc9ee5611064147921bb6a7de08791912ddd5a2f5d8bdc01666bba904bd025d282d57553e83a1068b1d5ed0b71b03a7432f8
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#!/usr/bin/env ruby -wKU
|
2
|
+
|
3
|
+
require 'active_model'
|
4
|
+
require_relative 'hash_mappable.rb'
|
5
|
+
require_relative 'Media.rb'
|
6
|
+
|
7
|
+
module WildcardPair
|
8
|
+
class Article
|
9
|
+
|
10
|
+
include ActiveModel::Validations
|
11
|
+
include ActiveModel::Serializers::JSON
|
12
|
+
include WildcardPair::HashMappable
|
13
|
+
include WildcardPair::Media
|
14
|
+
|
15
|
+
# required fields
|
16
|
+
attr_accessor :title, :html_content
|
17
|
+
# optional fields
|
18
|
+
attr_accessor :publication_date, :abstract_content, :source, :author,
|
19
|
+
:updated_date, :is_breaking, :app_link_android, :app_link_ios
|
20
|
+
|
21
|
+
attr_reader :media
|
22
|
+
|
23
|
+
validates :title, presence: true
|
24
|
+
validates :html_content, presence: true
|
25
|
+
validate :validate_media
|
26
|
+
|
27
|
+
def initialize(attributes = {})
|
28
|
+
attributes.each do |name, value|
|
29
|
+
send("#{name}=", value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def attributes
|
34
|
+
instance_values
|
35
|
+
end
|
36
|
+
|
37
|
+
def metatags=(metatags)
|
38
|
+
if metatags.nil? || !metatags.is_a?(Hash)
|
39
|
+
return
|
40
|
+
end
|
41
|
+
|
42
|
+
#see what you can set based on metatags
|
43
|
+
self.title=metatags['title']
|
44
|
+
self.html_content=metatags['html']
|
45
|
+
self.abstract_content=metatags['description']
|
46
|
+
self.media=Media::Image.new image_url: metatags['image_url']
|
47
|
+
self.app_link_ios=metatags['applink_ios']
|
48
|
+
self.app_link_android=metatags['applink_android']
|
49
|
+
end
|
50
|
+
|
51
|
+
def media=(media)
|
52
|
+
if media.is_a? Video
|
53
|
+
@media = map_hash(media, Media::Video.new)
|
54
|
+
elsif media.is_a? Image
|
55
|
+
@media = map_hash(media, Media::Image.new)
|
56
|
+
elsif media.is_a? Hash
|
57
|
+
if media[:type] == 'video'
|
58
|
+
@media = map_hash(media, Media::Video.new)
|
59
|
+
elsif media[:type] == 'image'
|
60
|
+
@media = map_hash(media, Media::Image.new)
|
61
|
+
else
|
62
|
+
@media = media
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def validate_media
|
68
|
+
if @media.nil? then return end
|
69
|
+
|
70
|
+
if !@media.is_a? Media or !@media.valid?
|
71
|
+
errors.add(:media, "Media is invalid")
|
72
|
+
return false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
#exclude validation fields in the JSON output
|
77
|
+
def as_json(options={})
|
78
|
+
super(options.merge({:except => [:errors, :validation_context]}))
|
79
|
+
end
|
80
|
+
|
81
|
+
def to_json(options={})
|
82
|
+
if self.valid?
|
83
|
+
super(options)
|
84
|
+
else
|
85
|
+
raise "Article is not valid - please remedy the following errors:" << self.errors.messages.to_s
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/env ruby -wKU
|
2
|
+
|
3
|
+
require 'active_model'
|
4
|
+
require_relative 'hash_mappable.rb'
|
5
|
+
require_relative 'Media.rb'
|
6
|
+
|
7
|
+
module WildcardPair
|
8
|
+
class ArticleCard
|
9
|
+
private
|
10
|
+
|
11
|
+
attr_accessor :article, :card_type, :pair_version
|
12
|
+
|
13
|
+
public
|
14
|
+
|
15
|
+
include ActiveModel::Validations
|
16
|
+
include ActiveModel::Serializers::JSON
|
17
|
+
include WildcardPair::HashMappable
|
18
|
+
include WildcardPair::Media
|
19
|
+
|
20
|
+
attr_accessor :web_url
|
21
|
+
attr_reader :article, :card_type, :pair_version
|
22
|
+
|
23
|
+
validates :web_url, presence: true
|
24
|
+
validate :validate_article
|
25
|
+
|
26
|
+
def initialize(attributes = {})
|
27
|
+
attributes.each do |name, value|
|
28
|
+
send("#{name}=", value)
|
29
|
+
end
|
30
|
+
|
31
|
+
@card_type = 'article'
|
32
|
+
|
33
|
+
if !Gem.loaded_specs['wildcard-pair'].nil?
|
34
|
+
@pair_version = Gem.loaded_specs['wildcard-pair'].version.to_s
|
35
|
+
else
|
36
|
+
@pair_version = "unknown"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def attributes
|
41
|
+
instance_values
|
42
|
+
end
|
43
|
+
|
44
|
+
def populate_from_metatags(web_url)
|
45
|
+
@web_url=web_url
|
46
|
+
metatags = WildcardPair::ExtractMetaTags.extract(@web_url)
|
47
|
+
|
48
|
+
##now that we've extracted metatags, let's create a Article
|
49
|
+
self.article=WildcardPair::Article.new metatags: metatags
|
50
|
+
end
|
51
|
+
|
52
|
+
def article=(article)
|
53
|
+
@article = map_hash(article, WildcardPair::Article.new)
|
54
|
+
end
|
55
|
+
|
56
|
+
def validate_article
|
57
|
+
if @article.nil? || !@article.is_a?(Article)
|
58
|
+
errors.add(:article, "An article is required")
|
59
|
+
return
|
60
|
+
end
|
61
|
+
|
62
|
+
if !@article.valid?
|
63
|
+
@article.errors.each do |error, msg|
|
64
|
+
errors["article[%s]" % error] = msg
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
#exclude validation fields in the JSON output
|
70
|
+
def as_json(options={})
|
71
|
+
super(options.merge({:except => [:errors, :validation_context]}))
|
72
|
+
end
|
73
|
+
|
74
|
+
def to_json(options={})
|
75
|
+
if self.valid?
|
76
|
+
super(options)
|
77
|
+
else
|
78
|
+
raise "Article Card is not valid - please remedy the following errors:" << self.errors.messages.to_s
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
require 'active_model'
|
3
|
+
require_relative 'hash_mappable.rb'
|
4
|
+
|
5
|
+
module WildcardPair
|
6
|
+
class Color
|
7
|
+
include ActiveModel::Validations
|
8
|
+
include ActiveModel::Serializers::JSON
|
9
|
+
include WildcardPair::HashMappable
|
10
|
+
|
11
|
+
attr_accessor :display_name, :swatch_url, :value, :mapping_color
|
12
|
+
|
13
|
+
validates :mapping_color, allow_nil: true, inclusion: {in: %w(beige black blue bronze brown gold green gray metallic multicolored offwhite orange pink purple red silver transparent turquoise white yellow)}
|
14
|
+
|
15
|
+
def initialize(attributes = {})
|
16
|
+
|
17
|
+
attributes.each do |name, value|
|
18
|
+
send("#{name}=", value)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def attributes
|
23
|
+
instance_values
|
24
|
+
end
|
25
|
+
|
26
|
+
#exclude validation fields in the JSON output
|
27
|
+
def as_json(options={})
|
28
|
+
super(options.merge({:except => [:errors, :validation_context]}))
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def to_json(options = {})
|
33
|
+
if self.valid?
|
34
|
+
super(options)
|
35
|
+
else
|
36
|
+
raise "Color is not valid - please remedy the following errors:" << self.errors.messages.to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby -wKU
|
2
|
+
|
3
|
+
require 'active_model'
|
4
|
+
require_relative '../hash_mappable.rb'
|
5
|
+
require_relative '../Media.rb'
|
6
|
+
|
7
|
+
module WildcardPair::Media
|
8
|
+
class Image
|
9
|
+
|
10
|
+
include ActiveModel::Validations
|
11
|
+
include ActiveModel::Serializers::JSON
|
12
|
+
include WildcardPair::HashMappable
|
13
|
+
include WildcardPair::Media
|
14
|
+
|
15
|
+
attr_accessor :image_url, :image_caption, :type
|
16
|
+
|
17
|
+
validates :image_url, presence: true
|
18
|
+
validates :type, presence: true, inclusion: {in: %w(image), message: 'incorrect media type specified'}
|
19
|
+
|
20
|
+
def initialize(attributes = {})
|
21
|
+
attributes.each do |name, value|
|
22
|
+
send("#{name}=", value)
|
23
|
+
end
|
24
|
+
|
25
|
+
@type = 'image'
|
26
|
+
end
|
27
|
+
|
28
|
+
def attributes
|
29
|
+
instance_values
|
30
|
+
end
|
31
|
+
|
32
|
+
#exclude validation fields in the JSON output
|
33
|
+
def as_json(options={})
|
34
|
+
super(options.merge({:except => [:errors, :validation_context]}))
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_json(options={})
|
38
|
+
if self.valid?
|
39
|
+
super(options)
|
40
|
+
else
|
41
|
+
raise "Image is not valid - please remedy the following errors:" << self.errors.messages.to_s
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env ruby -wKU
|
2
|
+
|
3
|
+
require 'active_model'
|
4
|
+
require_relative '../hash_mappable.rb'
|
5
|
+
|
6
|
+
module WildcardPair::Media
|
7
|
+
class Video
|
8
|
+
|
9
|
+
include ActiveModel::Validations
|
10
|
+
include ActiveModel::Serializers::JSON
|
11
|
+
include WildcardPair::HashMappable
|
12
|
+
include WildcardPair::Media
|
13
|
+
|
14
|
+
# required fields
|
15
|
+
attr_accessor :title, :embedded_url, :embedded_url_width, :embedded_url_height, :type
|
16
|
+
# optional fields
|
17
|
+
attr_accessor :stream_url, :stream_content_type, :publication_date,
|
18
|
+
:description, :poster_image_url, :creator, :source, :app_link_ios,
|
19
|
+
:app_link_android
|
20
|
+
|
21
|
+
validates :title, presence: true
|
22
|
+
validates :embedded_url, presence: true
|
23
|
+
validates :embedded_url_width, presence: true, numericality: {only_integer: true, greater_than_or_equal_to: 0}
|
24
|
+
validates :embedded_url_height, presence: true, numericality: {only_integer: true, greater_than_or_equal_to: 0}
|
25
|
+
validates :type, presence: true, inclusion: {in: %w(video), message: 'incorrect media type specified'}
|
26
|
+
|
27
|
+
def initialize(attributes = {})
|
28
|
+
attributes.each do |name, value|
|
29
|
+
send("#{name}=", value)
|
30
|
+
end
|
31
|
+
|
32
|
+
@type = 'video'
|
33
|
+
end
|
34
|
+
|
35
|
+
def attributes
|
36
|
+
instance_values
|
37
|
+
end
|
38
|
+
|
39
|
+
def metatags=(metatags)
|
40
|
+
if metatags.nil? || !metatags.is_a?(Hash)
|
41
|
+
return
|
42
|
+
end
|
43
|
+
|
44
|
+
#see what you can set based on metatags
|
45
|
+
self.title=metatags['title']
|
46
|
+
self.embedded_url=metatags['video_url']
|
47
|
+
self.embedded_url_height=metatags['video_height']
|
48
|
+
self.embedded_url_width=metatags['video_width']
|
49
|
+
|
50
|
+
self.description=metatags['description']
|
51
|
+
self.poster_image_url=metatags['image_url']
|
52
|
+
self.app_link_ios=metatags['applink_ios']
|
53
|
+
self.app_link_android=metatags['applink_android']
|
54
|
+
end
|
55
|
+
|
56
|
+
#exclude validation fields in the JSON output
|
57
|
+
def as_json(options={})
|
58
|
+
super(options.merge({:except => [:errors, :validation_context]}))
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_json(options={})
|
62
|
+
if self.valid?
|
63
|
+
super(options)
|
64
|
+
else
|
65
|
+
raise "Video is not valid - please remedy the following errors:" << self.errors.messages.to_s
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
|
2
|
+
require 'active_model'
|
3
|
+
require_relative 'hash_mappable.rb'
|
4
|
+
|
5
|
+
module WildcardPair
|
6
|
+
class Offer
|
7
|
+
include ActiveModel::Validations
|
8
|
+
include ActiveModel::Serializers::JSON
|
9
|
+
include WildcardPair::HashMappable
|
10
|
+
|
11
|
+
attr_accessor :description, :availability, :quantity, :weight, :weight_units, :offer_id, :sale_start_date, :sale_end_date, :expiration_date
|
12
|
+
|
13
|
+
attr_reader :price, :original_price, :shipping_cost, :geographic_availability
|
14
|
+
|
15
|
+
validates :price, presence: true
|
16
|
+
validates :description, allow_nil: true, presence: true
|
17
|
+
validates :availability, allow_nil: true, inclusion: {in: %w(Discontinued InStock InStoreOnly LimitedAvailability OnlineOnly OutOfStock PreOrder SoldOut) }
|
18
|
+
validates :weight, allow_nil: true, numericality: {greater_than_or_equal_to: 0}
|
19
|
+
validates :quantity, allow_nil: true, numericality: {only_integer: true, greater_than_or_equal_to: 0}
|
20
|
+
|
21
|
+
validate :validatePrices
|
22
|
+
|
23
|
+
def initialize(attributes = {})
|
24
|
+
attributes.each do |name, value|
|
25
|
+
send("#{name}=", value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def metatags=(metatags)
|
30
|
+
if metatags.nil? || !metatags.is_a?(Hash)
|
31
|
+
return
|
32
|
+
end
|
33
|
+
|
34
|
+
#if price metatag exists, then set it
|
35
|
+
if (!metatags['price'].nil?)
|
36
|
+
self.price=WildcardPair::Price.new price: metatags['price']
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def price=(price)
|
41
|
+
@price = map_hash(price, WildcardPair::Price.new)
|
42
|
+
end
|
43
|
+
|
44
|
+
def original_price=(original_price)
|
45
|
+
@original_price = map_hash(original_price, WildcardPair::Price.new)
|
46
|
+
end
|
47
|
+
|
48
|
+
def shipping_cost=(shipping_cost)
|
49
|
+
@shipping_cost = map_hash(shipping_cost, WildcardPair::Price.new)
|
50
|
+
end
|
51
|
+
|
52
|
+
def attributes
|
53
|
+
instance_values
|
54
|
+
end
|
55
|
+
|
56
|
+
def geographic_availability=(geographic_availability)
|
57
|
+
@geographic_availability ||= Array.new
|
58
|
+
|
59
|
+
if geographic_availability.is_a?(Array)
|
60
|
+
@geographic_availability = geographic_availability
|
61
|
+
else
|
62
|
+
@geographic_availability << geographic_availability
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def validatePrices
|
67
|
+
if @price.nil? || !@price.is_a?(Price) || !@price.valid?
|
68
|
+
errors.add(:price, "Price does not exist or is invalid")
|
69
|
+
return
|
70
|
+
end
|
71
|
+
|
72
|
+
if !@original_price.nil?
|
73
|
+
if !@original_price.is_a?(Price) || !@original_price.valid?
|
74
|
+
errors.add(:original_price, "Original Price is invalid")
|
75
|
+
return
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
if !@shipping_cost.nil?
|
80
|
+
if !@shipping_cost.is_a?(Price) || !@shipping_cost.valid?
|
81
|
+
errors.add(:shipping_cost, 'Shipping Cost is invalid')
|
82
|
+
return
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
#exclude validation fields in the JSON output
|
88
|
+
def as_json(options={})
|
89
|
+
super(options.merge({:except => [:errors, :validation_context]}))
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def to_json(options = {})
|
94
|
+
if self.valid?
|
95
|
+
super(options)
|
96
|
+
else
|
97
|
+
raise "Offer is not valid - please remedy the following errors:" << self.errors.messages.to_s
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|