wildcard-pair 0.3.1 → 0.4.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
  SHA1:
3
- metadata.gz: a87d389d67f030de00b57384d85e7cc5ca9ff253
4
- data.tar.gz: f9a7c892fef9e4e230d54b007c5da78455b4a767
3
+ metadata.gz: 00458fca5a7f7e4b7a07f28f969214f1e595afa3
4
+ data.tar.gz: f6cc5d383fb3a2541c85248c95b0bf10a2bd518d
5
5
  SHA512:
6
- metadata.gz: 46aba80a945c50cf02ffc8528be3bcff27c289cda1ae59d2fc518e9b5267813f99fe306964083ab848ebd9a50a0b8b9de732805b138d698270f7c14e0879ab43
7
- data.tar.gz: e3346365a27cebeaeb36bc690e76cc9ee5611064147921bb6a7de08791912ddd5a2f5d8bdc01666bba904bd025d282d57553e83a1068b1d5ed0b71b03a7432f8
6
+ metadata.gz: 7c538305caef48cd730255822332f46f83283367cb9846f19ee480e2f456f070febee96eede8914040e928684a802cb2435017d9a3ebf3d6c326617d7837ecf3
7
+ data.tar.gz: 04f44392320122bf777549b00747a2d7ec39b22cdb755665c171dfbc208754434ff5c7849c70061bef3567e36127f3c7cac9d139b97c3b1de6cf521bb6bf8772
@@ -1,16 +1,9 @@
1
1
  #!/usr/bin/env ruby -wKU
2
2
 
3
- require 'active_model'
4
- require_relative 'hash_mappable.rb'
5
- require_relative 'Media.rb'
3
+ require_relative 'ObjectWithMedia.rb'
6
4
 
7
5
  module WildcardPair
8
- class Article
9
-
10
- include ActiveModel::Validations
11
- include ActiveModel::Serializers::JSON
12
- include WildcardPair::HashMappable
13
- include WildcardPair::Media
6
+ class Article < WildcardPair::ObjectWithMedia
14
7
 
15
8
  # required fields
16
9
  attr_accessor :title, :html_content
@@ -18,21 +11,8 @@ module WildcardPair
18
11
  attr_accessor :publication_date, :abstract_content, :source, :author,
19
12
  :updated_date, :is_breaking, :app_link_android, :app_link_ios
20
13
 
21
- attr_reader :media
22
-
23
14
  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
15
+ validates :abstract_content, presence: true
36
16
 
37
17
  def metatags=(metatags)
38
18
  if metatags.nil? || !metatags.is_a?(Hash)
@@ -47,44 +27,5 @@ module WildcardPair
47
27
  self.app_link_ios=metatags['applink_ios']
48
28
  self.app_link_android=metatags['applink_android']
49
29
  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
30
  end
90
31
  end
@@ -1,44 +1,24 @@
1
1
  #!/usr/bin/env ruby -wKU
2
2
 
3
- require 'active_model'
4
- require_relative 'hash_mappable.rb'
5
- require_relative 'Media.rb'
3
+ require_relative 'Card.rb'
6
4
 
7
5
  module WildcardPair
8
- class ArticleCard
6
+ class ArticleCard < WildcardPair::Card
9
7
  private
10
8
 
11
- attr_accessor :article, :card_type, :pair_version
9
+ attr_accessor :article
12
10
 
13
11
  public
14
12
 
15
- include ActiveModel::Validations
16
- include ActiveModel::Serializers::JSON
17
- include WildcardPair::HashMappable
18
13
  include WildcardPair::Media
19
14
 
20
- attr_accessor :web_url
21
- attr_reader :article, :card_type, :pair_version
15
+ attr_reader :article
22
16
 
23
- validates :web_url, presence: true
24
17
  validate :validate_article
25
18
 
26
19
  def initialize(attributes = {})
27
- attributes.each do |name, value|
28
- send("#{name}=", value)
29
- end
30
-
20
+ super
31
21
  @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
22
  end
43
23
 
44
24
  def populate_from_metatags(web_url)
@@ -65,20 +45,6 @@ module WildcardPair
65
45
  end
66
46
  end
67
47
  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
48
  end
83
49
  end
84
50
 
@@ -0,0 +1,82 @@
1
+ require 'active_model'
2
+ require_relative 'hash_mappable.rb'
3
+ require_relative 'Creator.rb'
4
+
5
+ module WildcardPair
6
+ class Card
7
+ private
8
+
9
+ attr_accessor :card_type, :pair_version, :creator
10
+
11
+ public
12
+
13
+ include ActiveModel::Validations
14
+ include ActiveModel::Serializers::JSON
15
+ include WildcardPair::HashMappable
16
+
17
+ attr_accessor :web_url, :keywords, :app_link_android, :app_link_ios
18
+ attr_reader :card_type, :pair_version, :creator
19
+
20
+ validates :web_url, presence: true
21
+ validate :validate_keywords
22
+ validate :validate_creator
23
+
24
+ def initialize(attributes = {})
25
+ attributes.each do |name, value|
26
+ send("#{name}=", value)
27
+ end
28
+
29
+ if !Gem.loaded_specs['wildcard-pair'].nil?
30
+ @pair_version = Gem.loaded_specs['wildcard-pair'].version.to_s
31
+ else
32
+ @pair_version = "unknown"
33
+ end
34
+ end
35
+
36
+ def attributes
37
+ instance_values
38
+ end
39
+
40
+ def validate_keywords
41
+ if !@keywords.nil? and !@keywords.instance_of? Array
42
+ errors.add(:keywords, "Keywords must be an array of strings")
43
+ return
44
+ end
45
+
46
+ if !@keywords.nil?
47
+ @keywords.each do |k|
48
+ if !k.instance_of? String
49
+ errors.add(:keywords, "Keywords must be an array of strings")
50
+ return
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ def creator=(creator)
57
+ @creator = map_hash(creator, WildcardPair::Creator.new)
58
+ end
59
+
60
+ def validate_creator
61
+ if @creator.nil? then return end
62
+
63
+ if !@creator.is_a? Creator or !@creator.valid?
64
+ errors.add(:creator, "Creator is invalid")
65
+ return false
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 self.card_type.capitalize + " Card is not valid - please remedy the following errors:" << self.errors.messages.to_s
79
+ end
80
+ end
81
+ end
82
+ end
@@ -1,41 +1,13 @@
1
+ #!/usr/bin/env ruby -wKU
1
2
 
2
- require 'active_model'
3
- require_relative 'hash_mappable.rb'
3
+ require_relative 'Object.rb'
4
4
 
5
5
  module WildcardPair
6
- class Color
7
- include ActiveModel::Validations
8
- include ActiveModel::Serializers::JSON
9
- include WildcardPair::HashMappable
6
+ class Color < WildcardPair::Object
10
7
 
11
8
  attr_accessor :display_name, :swatch_url, :value, :mapping_color
12
9
 
10
+ validates :display_name, presence: true
13
11
  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
12
  end
41
13
  end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby -wKU
2
+
3
+ require_relative 'Object.rb'
4
+
5
+ module WildcardPair
6
+ class Creator < WildcardPair::Object
7
+
8
+ attr_accessor :name, :favicon, :ios_app_store_url, :android_app_store_url, :url
9
+
10
+ validates :name, presence: true
11
+ validates :favicon, presence: true
12
+ end
13
+ end
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby -wKU
2
+
3
+ require_relative 'Card.rb'
4
+
5
+ module WildcardPair
6
+ class ImageCard < WildcardPair::Card
7
+ private
8
+
9
+ attr_accessor :media
10
+
11
+ public
12
+
13
+ include WildcardPair::Media
14
+
15
+ attr_reader :media
16
+
17
+ validate :validate_media
18
+
19
+ def initialize(attributes = {})
20
+ super
21
+ @card_type = 'image'
22
+ end
23
+
24
+ def populate_from_metatags(web_url)
25
+ @web_url=web_url
26
+ metatags = WildcardPair::ExtractMetaTags.extract(@web_url)
27
+
28
+ ##now that we've extracted metatags, let's create an Image object with it
29
+ self.media=WildcardPair::Media::Image.new metatags: metatags
30
+ self.app_link_ios = metatags['applink_ios']
31
+ self.app_link_android = metatags['applink_android']
32
+ end
33
+
34
+ def media=(media)
35
+ @media = map_hash(media, WildcardPair::Media::Image.new)
36
+ end
37
+
38
+ def validate_media
39
+ if @media.nil? || !@media.is_a?(Image)
40
+ errors.add(:media, "An image is required")
41
+ return
42
+ end
43
+
44
+ if !@media.valid?
45
+ @media.errors.each do |error, msg|
46
+ errors["media[%s]" % error] = msg = msg
47
+ end
48
+ end
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby -wKU
2
+
3
+ require_relative 'Card.rb'
4
+
5
+ module WildcardPair
6
+ class LinkCard < WildcardPair::Card
7
+ private
8
+
9
+ attr_accessor :target
10
+
11
+ public
12
+
13
+ attr_reader :target
14
+
15
+ validate :validate_target
16
+
17
+ def initialize(attributes = {})
18
+ super
19
+ @card_type = 'link'
20
+ end
21
+
22
+ def target=(target)
23
+ @target = map_hash(target, WildcardPair::Target.new)
24
+ end
25
+
26
+ def validate_target
27
+ if @target.nil? || !@target.is_a?(Target)
28
+ errors.add(:target, "A target is required")
29
+ return
30
+ end
31
+
32
+ if !@target.valid?
33
+ @target.errors.each do |error, msg|
34
+ errors["media[%s]" % error] = msg = msg
35
+ end
36
+ end
37
+ end
38
+
39
+ end
40
+ end
@@ -1,46 +1,35 @@
1
1
  #!/usr/bin/env ruby -wKU
2
2
 
3
- require 'active_model'
4
- require_relative '../hash_mappable.rb'
5
3
  require_relative '../Media.rb'
4
+ require_relative '../Object.rb'
6
5
 
7
6
  module WildcardPair::Media
8
- class Image
7
+ class Image < WildcardPair::Object
9
8
 
10
- include ActiveModel::Validations
11
- include ActiveModel::Serializers::JSON
12
- include WildcardPair::HashMappable
13
9
  include WildcardPair::Media
14
10
 
15
- attr_accessor :image_url, :image_caption, :type
11
+ attr_accessor :image_url, :image_caption, :type,
12
+ :title, :author, :width, :height, :publication_date
16
13
 
17
14
  validates :image_url, presence: true
18
15
  validates :type, presence: true, inclusion: {in: %w(image), message: 'incorrect media type specified'}
16
+ validates :width, allow_nil: true, numericality: {only_integer: true, greater_than_or_equal_to: 0}
17
+ validates :height, allow_nil: true, numericality: {only_integer: true, greater_than_or_equal_to: 0}
19
18
 
20
19
  def initialize(attributes = {})
21
- attributes.each do |name, value|
22
- send("#{name}=", value)
23
- end
24
-
20
+ super
25
21
  @type = 'image'
26
22
  end
27
23
 
28
- def attributes
29
- instance_values
30
- end
24
+ def metatags=(metatags)
25
+ if metatags.nil? || !metatags.is_a?(Hash)
26
+ return
27
+ end
31
28
 
32
- #exclude validation fields in the JSON output
33
- def as_json(options={})
34
- super(options.merge({:except => [:errors, :validation_context]}))
29
+ #see what you can set based on metatags
30
+ self.title=metatags['title']
31
+ self.image_caption=metatags['description']
32
+ self.image_url=metatags['image_url']
35
33
  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
34
  end
46
35
  end
@@ -1,14 +1,11 @@
1
1
  #!/usr/bin/env ruby -wKU
2
2
 
3
- require 'active_model'
4
- require_relative '../hash_mappable.rb'
3
+ require_relative '../Media.rb'
4
+ require_relative '../Object.rb'
5
5
 
6
6
  module WildcardPair::Media
7
- class Video
7
+ class Video < WildcardPair::Object
8
8
 
9
- include ActiveModel::Validations
10
- include ActiveModel::Serializers::JSON
11
- include WildcardPair::HashMappable
12
9
  include WildcardPair::Media
13
10
 
14
11
  # required fields
@@ -25,17 +22,10 @@ module WildcardPair::Media
25
22
  validates :type, presence: true, inclusion: {in: %w(video), message: 'incorrect media type specified'}
26
23
 
27
24
  def initialize(attributes = {})
28
- attributes.each do |name, value|
29
- send("#{name}=", value)
30
- end
31
-
25
+ super
32
26
  @type = 'video'
33
27
  end
34
28
 
35
- def attributes
36
- instance_values
37
- end
38
-
39
29
  def metatags=(metatags)
40
30
  if metatags.nil? || !metatags.is_a?(Hash)
41
31
  return
@@ -52,19 +42,5 @@ module WildcardPair::Media
52
42
  self.app_link_ios=metatags['applink_ios']
53
43
  self.app_link_android=metatags['applink_android']
54
44
  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
45
  end
70
46
  end
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby -wKU
2
+
3
+ require 'active_model'
4
+ require_relative 'hash_mappable.rb'
5
+
6
+ module WildcardPair
7
+ class Object
8
+ include ActiveModel::Validations
9
+ include ActiveModel::Serializers::JSON
10
+ include WildcardPair::HashMappable
11
+
12
+ def initialize(attributes = {})
13
+ attributes.each do |name, value|
14
+ send("#{name}=", value)
15
+ end
16
+ end
17
+
18
+ def attributes
19
+ instance_values
20
+ end
21
+
22
+ #exclude validation fields in the JSON output
23
+ def as_json(options={})
24
+ super(options.merge({:except => [:errors, :validation_context]}))
25
+ end
26
+
27
+ def to_json(options={})
28
+ if self.valid?
29
+ super(options)
30
+ else
31
+ raise self.class.to_s + " is not valid - please remedy the following errors:" << self.errors.messages.to_s
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby -wKU
2
+
3
+ require_relative 'Object.rb'
4
+ require_relative 'Media.rb'
5
+
6
+ module WildcardPair
7
+ class ObjectWithMedia < WildcardPair::Object
8
+
9
+ include WildcardPair::Media
10
+
11
+ attr_reader :media
12
+ validate :validate_media
13
+
14
+ def media=(media)
15
+ if media.is_a? Video
16
+ @media = map_hash(media, Media::Video.new)
17
+ elsif media.is_a? Image
18
+ @media = map_hash(media, Media::Image.new)
19
+ elsif media.is_a? Hash
20
+ if media[:type] == 'video'
21
+ @media = map_hash(media, Media::Video.new)
22
+ elsif media[:type] == 'image'
23
+ @media = map_hash(media, Media::Image.new)
24
+ else
25
+ @media = media
26
+ end
27
+ end
28
+ end
29
+
30
+ def validate_media
31
+ if @media.nil? then return end
32
+
33
+ if !@media.is_a? Media or !@media.valid?
34
+ errors.add(:media, "Media is invalid")
35
+ return false
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,12 +1,7 @@
1
-
2
- require 'active_model'
3
- require_relative 'hash_mappable.rb'
1
+ require_relative 'Object.rb'
4
2
 
5
3
  module WildcardPair
6
- class Offer
7
- include ActiveModel::Validations
8
- include ActiveModel::Serializers::JSON
9
- include WildcardPair::HashMappable
4
+ class Offer < WildcardPair::Object
10
5
 
11
6
  attr_accessor :description, :availability, :quantity, :weight, :weight_units, :offer_id, :sale_start_date, :sale_end_date, :expiration_date
12
7
 
@@ -19,12 +14,6 @@ module WildcardPair
19
14
  validates :quantity, allow_nil: true, numericality: {only_integer: true, greater_than_or_equal_to: 0}
20
15
 
21
16
  validate :validatePrices
22
-
23
- def initialize(attributes = {})
24
- attributes.each do |name, value|
25
- send("#{name}=", value)
26
- end
27
- end
28
17
 
29
18
  def metatags=(metatags)
30
19
  if metatags.nil? || !metatags.is_a?(Hash)
@@ -49,10 +38,6 @@ module WildcardPair
49
38
  @shipping_cost = map_hash(shipping_cost, WildcardPair::Price.new)
50
39
  end
51
40
 
52
- def attributes
53
- instance_values
54
- end
55
-
56
41
  def geographic_availability=(geographic_availability)
57
42
  @geographic_availability ||= Array.new
58
43
 
@@ -83,20 +68,5 @@ module WildcardPair
83
68
  end
84
69
  end
85
70
  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
71
  end
102
72
  end
@@ -1,44 +1,17 @@
1
-
2
- require_relative 'hash_mappable.rb'
3
- require 'active_model'
1
+ require_relative 'Object.rb'
4
2
 
5
3
  module WildcardPair
6
- class Price
7
- include ActiveModel::Validations
8
- include ActiveModel::Serializers::JSON
9
- include WildcardPair::HashMappable
4
+ class Price < WildcardPair::Object
10
5
 
11
6
  attr_accessor :price, :currency
12
7
 
13
8
  validates :price, presence: true, numericality: {greater_than_or_equal_to: 0}
14
9
 
15
10
  def initialize(attributes = {})
16
-
17
11
  #let's set currency to USD by default
18
12
  @currency = "USD"
19
13
 
20
- attributes.each do |name, value|
21
- send("#{name}=", value)
22
- end
14
+ super
23
15
  end
24
-
25
- def attributes
26
- instance_values
27
- end
28
-
29
- #exclude validation fields in the JSON output
30
- def as_json(options={})
31
- super(options.merge({:except => [:errors, :validation_context]}))
32
- end
33
-
34
-
35
- def to_json(options = {})
36
- if self.valid?
37
- super(options)
38
- else
39
- raise "Price is not valid - please remedy the following errors:" << self.errors.messages.to_s
40
- end
41
- end
42
-
43
16
  end
44
17
  end
@@ -1,14 +1,9 @@
1
1
  #!/usr/bin/env ruby -wKU
2
2
 
3
- require 'active_model'
4
- require_relative 'hash_mappable.rb'
3
+ require_relative 'Object.rb'
5
4
 
6
5
  module WildcardPair
7
- class Product
8
-
9
- include ActiveModel::Validations
10
- include ActiveModel::Serializers::JSON
11
- include WildcardPair::HashMappable
6
+ class Product < WildcardPair::Object
12
7
 
13
8
  attr_accessor :name, :merchant, :brand, :description, :gender, :rating, :rating_scale, :rating_count, :sizes, :model, :app_link_ios, :app_link_android
14
9
  attr_reader :colors, :images, :related_items, :referenced_items, :options
@@ -20,16 +15,6 @@ module WildcardPair
20
15
  validate :validateColors
21
16
  validate :validateImages
22
17
 
23
- def initialize(attributes = {})
24
- attributes.each do |name, value|
25
- send("#{name}=", value)
26
- end
27
- end
28
-
29
- def attributes
30
- instance_values
31
- end
32
-
33
18
  def metatags=(metatags)
34
19
  if metatags.nil? || !metatags.is_a?(Hash)
35
20
  return
@@ -114,19 +99,5 @@ module WildcardPair
114
99
  return
115
100
  end
116
101
  end
117
-
118
- #exclude validation fields in the JSON output
119
- def as_json(options={})
120
- super(options.merge({:except => [:errors, :validation_context]}))
121
- end
122
-
123
- def to_json(options={})
124
- if self.valid?
125
- super(options)
126
- else
127
- raise "Product is not valid - please remedy the following errors:" << self.errors.messages.to_s
128
- end
129
- end
130
-
131
102
  end
132
103
  end
@@ -1,43 +1,23 @@
1
1
  #!/usr/bin/env ruby -wKU
2
2
 
3
- require 'active_model'
4
- require_relative 'hash_mappable.rb'
3
+ require_relative 'Card.rb'
5
4
 
6
5
  module WildcardPair
7
- class ProductCard
6
+ class ProductCard < WildcardPair::Card
8
7
  private
9
8
 
10
- attr_accessor :offers, :product, :card_type, :pair_version
9
+ attr_accessor :offers, :product
11
10
 
12
11
  public
13
12
 
14
- include ActiveModel::Validations
15
- include ActiveModel::Serializers::JSON
16
- include WildcardPair::HashMappable
13
+ attr_reader :offers, :product
17
14
 
18
- attr_accessor :web_url
19
- attr_reader :offers, :card_type, :pair_version, :product
20
-
21
- validates :web_url, presence: true
22
15
  validate :validateOffers
23
16
  validate :validateProduct
24
17
 
25
18
  def initialize(attributes = {})
26
- attributes.each do |name, value|
27
- send("#{name}=", value)
28
- end
29
-
19
+ super
30
20
  @card_type = 'product'
31
-
32
- if !Gem.loaded_specs['wildcard-pair'].nil?
33
- @pair_version = Gem.loaded_specs['wildcard-pair'].version.to_s
34
- else
35
- @pair_version = "unknown"
36
- end
37
- end
38
-
39
- def attributes
40
- instance_values
41
21
  end
42
22
 
43
23
  def populate_from_metatags(web_url)
@@ -99,18 +79,6 @@ module WildcardPair
99
79
  end
100
80
  end
101
81
 
102
- #exclude validation fields in the JSON output
103
- def as_json(options={})
104
- super(options.merge({:except => [:errors, :validation_context]}))
105
- end
106
-
107
- def to_json(options={})
108
- if self.valid?
109
- super(options)
110
- else
111
- raise "Product Card is not valid - please remedy the following errors:" << self.errors.messages.to_s
112
- end
113
- end
114
82
 
115
83
  end
116
84
  end
@@ -1,14 +1,9 @@
1
1
  #!/usr/bin/env ruby -wKU
2
2
 
3
- require 'active_model'
4
- require_relative 'hash_mappable.rb'
3
+ require_relative 'Object.rb'
5
4
 
6
5
  module WildcardPair
7
- class Rating
8
-
9
- include ActiveModel::Validations
10
- include ActiveModel::Serializers::JSON
11
- include WildcardPair::HashMappable
6
+ class Rating < WildcardPair::Object
12
7
 
13
8
  # required fields
14
9
  attr_accessor :rating, :minimum_rating, :maximum_rating
@@ -19,29 +14,5 @@ module WildcardPair
19
14
  validates :minimum_rating, presence: true, numericality: {greater_than_or_equal_to: 0}
20
15
  validates :maximum_rating, presence: true, numericality: {greater_than_or_equal_to: 0}
21
16
  validates :number_of_ratings, allow_nil: true, numericality: {only_integer: true, greater_than_or_equal_to: 0}
22
-
23
- def initialize(attributes = {})
24
- attributes.each do |name, value|
25
- send("#{name}=", value)
26
- end
27
- end
28
-
29
- def attributes
30
- instance_values
31
- end
32
-
33
- #exclude validation fields in the JSON output
34
- def as_json(options={})
35
- super(options.merge({:except => [:errors, :validation_context]}))
36
- end
37
-
38
- def to_json(options={})
39
- if self.valid?
40
- super(options)
41
- else
42
- raise "Video is not valid - please remedy the following errors:" << self.errors.messages.to_s
43
- end
44
- end
45
-
46
17
  end
47
18
  end
@@ -1,16 +1,9 @@
1
1
  #!/usr/bin/env ruby -wKU
2
2
 
3
- require 'active_model'
4
- require_relative 'hash_mappable.rb'
5
- require_relative 'Media.rb'
3
+ require_relative 'ObjectWithMedia.rb'
6
4
 
7
5
  module WildcardPair
8
- class Review
9
-
10
- include ActiveModel::Validations
11
- include ActiveModel::Serializers::JSON
12
- include WildcardPair::HashMappable
13
- include WildcardPair::Media
6
+ class Review < WildcardPair::ObjectWithMedia
14
7
 
15
8
  # required fields
16
9
  attr_accessor :title, :html_content
@@ -23,7 +16,6 @@ module WildcardPair
23
16
  validates :title, presence: true
24
17
  validates :html_content, presence: true
25
18
 
26
- validate :validate_media
27
19
  validate :validate_rating
28
20
 
29
21
  def metatags=(metatags)
@@ -40,45 +32,10 @@ module WildcardPair
40
32
  self.app_link_android=metatags['applink_android']
41
33
  end
42
34
 
43
- def media=(media)
44
- if media.is_a? Video
45
- @media = map_hash(media, Media::Video.new)
46
- elsif media.is_a? Image
47
- @media = map_hash(media, Media::Image.new)
48
- elsif media.is_a? Hash
49
- if media[:type] == 'video'
50
- @media = map_hash(media, Media::Video.new)
51
- elsif media[:type] == 'image'
52
- @media = map_hash(media, Media::Image.new)
53
- else
54
- @media = media
55
- end
56
- end
57
- end
58
-
59
- def validate_media
60
- if @media.nil? then return end
61
-
62
- if !@media.is_a? Media or !@media.valid?
63
- errors.add(:media, "Media is invalid")
64
- return false
65
- end
66
- end
67
-
68
35
  def rating=(rating)
69
36
  @rating = map_hash(rating, WildcardPair::Rating.new)
70
37
  end
71
38
 
72
- def initialize(attributes = {})
73
- attributes.each do |name, value|
74
- send("#{name}=", value)
75
- end
76
- end
77
-
78
- def attributes
79
- instance_values
80
- end
81
-
82
39
  def validate_rating
83
40
  if @rating.nil? then return end
84
41
 
@@ -87,19 +44,5 @@ module WildcardPair
87
44
  return false
88
45
  end
89
46
  end
90
-
91
- #exclude validation fields in the JSON output
92
- def as_json(options={})
93
- super(options.merge({:except => [:errors, :validation_context]}))
94
- end
95
-
96
- def to_json(options={})
97
- if self.valid?
98
- super(options)
99
- else
100
- raise "Video is not valid - please remedy the following errors:" << self.errors.messages.to_s
101
- end
102
- end
103
-
104
47
  end
105
48
  end
@@ -1,42 +1,22 @@
1
1
  #!/usr/bin/env ruby -wKU
2
2
 
3
- require 'active_model'
4
- require_relative 'hash_mappable.rb'
3
+ require_relative 'Card.rb'
5
4
 
6
5
  module WildcardPair
7
- class ReviewCard
6
+ class ReviewCard < WildcardPair::Card
8
7
  private
9
8
 
10
- attr_accessor :review, :card_type, :pair_version
9
+ attr_accessor :review
11
10
 
12
11
  public
13
12
 
14
- include ActiveModel::Validations
15
- include ActiveModel::Serializers::JSON
16
- include WildcardPair::HashMappable
13
+ attr_reader :review
17
14
 
18
- attr_accessor :web_url
19
- attr_reader :review, :card_type, :pair_version
20
-
21
- validates :web_url, presence: true
22
15
  validate :validate_review
23
16
 
24
17
  def initialize(attributes = {})
25
- attributes.each do |name, value|
26
- send("#{name}=", value)
27
- end
28
-
18
+ super
29
19
  @card_type = 'review'
30
-
31
- if !Gem.loaded_specs['wildcard-pair'].nil?
32
- @pair_version = Gem.loaded_specs['wildcard-pair'].version.to_s
33
- else
34
- @pair_version = "unknown"
35
- end
36
- end
37
-
38
- def attributes
39
- instance_values
40
20
  end
41
21
 
42
22
  def populate_from_metatags(web_url)
@@ -64,19 +44,6 @@ module WildcardPair
64
44
  end
65
45
  end
66
46
 
67
- #exclude validation fields in the JSON output
68
- def as_json(options={})
69
- super(options.merge({:except => [:errors, :validation_context]}))
70
- end
71
-
72
- def to_json(options={})
73
- if self.valid?
74
- super(options)
75
- else
76
- raise "Review Card is not valid - please remedy the following errors:" << self.errors.messages.to_s
77
- end
78
- end
79
-
80
47
  end
81
48
  end
82
49
 
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby -wKU
2
+
3
+ require_relative 'ObjectWithMedia.rb'
4
+
5
+ module WildcardPair
6
+ class Summary < WildcardPair::ObjectWithMedia
7
+
8
+ attr_accessor :title, :description
9
+
10
+ validates :title, presence: true
11
+ validates :description, presence: true
12
+ end
13
+ end
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby -wKU
2
+
3
+ require_relative 'Card.rb'
4
+
5
+ module WildcardPair
6
+ class SummaryCard < WildcardPair::Card
7
+ private
8
+
9
+ attr_accessor :summary
10
+
11
+ public
12
+
13
+ attr_reader :summary
14
+
15
+ validate :validate_summary
16
+
17
+ def initialize(attributes = {})
18
+ super
19
+ @card_type = 'summary'
20
+ end
21
+
22
+ def summary=(summary)
23
+ @summary = map_hash(summary, WildcardPair::Summary.new)
24
+ end
25
+
26
+ def validate_summary
27
+ if @summary.nil? || !@summary.is_a?(Summary)
28
+ errors.add(:summary, "A summary is required")
29
+ return
30
+ end
31
+
32
+ if !@summary.valid?
33
+ @summary.errors.each do |error, msg|
34
+ errors["summary[%s]" % error] = msg
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby -wKU
2
+
3
+ require_relative 'Object.rb'
4
+
5
+ module WildcardPair
6
+ class Target < WildcardPair::Object
7
+
8
+ attr_accessor :url, :title, :description, :publication_date
9
+
10
+ validates :url, presence: true
11
+ end
12
+ end
@@ -1,44 +1,24 @@
1
1
  #!/usr/bin/env ruby -wKU
2
2
 
3
- require 'active_model'
4
- require_relative 'hash_mappable.rb'
5
- require_relative 'Media.rb'
3
+ require_relative 'Card.rb'
6
4
 
7
5
  module WildcardPair
8
- class VideoCard
6
+ class VideoCard < WildcardPair::Card
9
7
  private
10
8
 
11
- attr_accessor :media, :card_type, :pair_version
9
+ attr_accessor :media
12
10
 
13
11
  public
14
12
 
15
- include ActiveModel::Validations
16
- include ActiveModel::Serializers::JSON
17
- include WildcardPair::HashMappable
18
13
  include WildcardPair::Media
19
14
 
20
- attr_accessor :web_url
21
- attr_reader :media, :card_type, :pair_version
15
+ attr_reader :media
22
16
 
23
- validates :web_url, presence: true
24
17
  validate :validate_media
25
18
 
26
19
  def initialize(attributes = {})
27
- attributes.each do |name, value|
28
- send("#{name}=", value)
29
- end
30
-
20
+ super
31
21
  @card_type = 'video'
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
22
  end
43
23
 
44
24
  def populate_from_metatags(web_url)
@@ -66,19 +46,5 @@ module WildcardPair
66
46
  end
67
47
  end
68
48
 
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 "Video Card is not valid - please remedy the following errors:" << self.errors.messages.to_s
79
- end
80
- end
81
-
82
49
  end
83
- end
84
-
50
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wildcard-pair
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karthik Senthil
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-12 00:00:00.000000000 Z
11
+ date: 2015-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: statsd-ruby
@@ -81,10 +81,16 @@ files:
81
81
  - lib/wildcard-pair.rb
82
82
  - lib/wildcard-pair/Article.rb
83
83
  - lib/wildcard-pair/ArticleCard.rb
84
+ - lib/wildcard-pair/Card.rb
84
85
  - lib/wildcard-pair/Color.rb
86
+ - lib/wildcard-pair/Creator.rb
87
+ - lib/wildcard-pair/ImageCard.rb
88
+ - lib/wildcard-pair/LinkCard.rb
85
89
  - lib/wildcard-pair/Media.rb
86
90
  - lib/wildcard-pair/Media/Image.rb
87
91
  - lib/wildcard-pair/Media/Video.rb
92
+ - lib/wildcard-pair/Object.rb
93
+ - lib/wildcard-pair/ObjectWithMedia.rb
88
94
  - lib/wildcard-pair/Offer.rb
89
95
  - lib/wildcard-pair/Price.rb
90
96
  - lib/wildcard-pair/Product.rb
@@ -94,6 +100,9 @@ files:
94
100
  - lib/wildcard-pair/Rating.rb
95
101
  - lib/wildcard-pair/Review.rb
96
102
  - lib/wildcard-pair/ReviewCard.rb
103
+ - lib/wildcard-pair/Summary.rb
104
+ - lib/wildcard-pair/SummaryCard.rb
105
+ - lib/wildcard-pair/Target.rb
97
106
  - lib/wildcard-pair/VideoCard.rb
98
107
  - lib/wildcard-pair/hash_mappable.rb
99
108
  - lib/wildcard-pair/util/extract_metatags.rb
@@ -117,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
126
  version: '0'
118
127
  requirements: []
119
128
  rubyforge_project:
120
- rubygems_version: 2.4.3
129
+ rubygems_version: 2.2.2
121
130
  signing_key:
122
131
  specification_version: 4
123
132
  summary: Wildcard Pair Ruby SDK