Class: Grocer::Pushpackager::Website
- Inherits:
-
Object
- Object
- Grocer::Pushpackager::Website
- Defined in:
- lib/grocer/pushpackager/website.rb
Instance Attribute Summary collapse
-
#allowed_domains ⇒ Object
readonly
Returns the value of attribute allowed_domains.
-
#authentication_token ⇒ Object
Returns the value of attribute authentication_token.
-
#push_id ⇒ Object
readonly
Returns the value of attribute push_id.
-
#url_format_string ⇒ Object
readonly
Returns the value of attribute url_format_string.
-
#web_service_url ⇒ Object
readonly
Returns the value of attribute web_service_url.
-
#website_name ⇒ Object
readonly
Returns the value of attribute website_name.
Instance Method Summary collapse
-
#initialize(config = {}) ⇒ Website
constructor
A new instance of Website.
- #to_json ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(config = {}) ⇒ Website
Returns a new instance of Website.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/grocer/pushpackager/website.rb', line 10 def initialize(config = {}) @website_name = config[:websiteName] @push_id = config[:websitePushID] @allowed_domains = [] if config[:allowedDomains] @allowed_domains = config[:allowedDomains].map{|domain| URI(domain)} end @url_format_string = config[:urlFormatString] @web_service_url = URI(config[:webServiceURL]) @authentication_token = config[:authenticationToken] end |
Instance Attribute Details
#allowed_domains ⇒ Object (readonly)
Returns the value of attribute allowed_domains.
8 9 10 |
# File 'lib/grocer/pushpackager/website.rb', line 8 def allowed_domains @allowed_domains end |
#authentication_token ⇒ Object
Returns the value of attribute authentication_token.
7 8 9 |
# File 'lib/grocer/pushpackager/website.rb', line 7 def authentication_token @authentication_token end |
#push_id ⇒ Object (readonly)
Returns the value of attribute push_id.
8 9 10 |
# File 'lib/grocer/pushpackager/website.rb', line 8 def push_id @push_id end |
#url_format_string ⇒ Object (readonly)
Returns the value of attribute url_format_string.
8 9 10 |
# File 'lib/grocer/pushpackager/website.rb', line 8 def url_format_string @url_format_string end |
#web_service_url ⇒ Object (readonly)
Returns the value of attribute web_service_url.
8 9 10 |
# File 'lib/grocer/pushpackager/website.rb', line 8 def web_service_url @web_service_url end |
#website_name ⇒ Object (readonly)
Returns the value of attribute website_name.
8 9 10 |
# File 'lib/grocer/pushpackager/website.rb', line 8 def website_name @website_name end |
Instance Method Details
#to_json ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/grocer/pushpackager/website.rb', line 32 def to_json raise "Invalid website" unless valid? { websiteName: @website_name.to_s, websitePushID: @push_id.to_s, allowedDomains: @allowed_domains.map{|domain| domain.to_s}, urlFormatString: @url_format_string.to_s, authenticationToken: @authentication_token.to_s, webServiceURL: @web_service_url.to_s, }.to_json end |
#valid? ⇒ Boolean
22 23 24 25 26 27 28 29 30 |
# File 'lib/grocer/pushpackager/website.rb', line 22 def valid? raise ArgumentError if not @website_name or @website_name.empty? raise ArgumentError if not @push_id or @push_id.empty? raise ArgumentError if not @url_format_string or @url_format_string.empty? raise ArgumentError if not @web_service_url or @web_service_url.to_s.empty? or not ['http', 'https'].include?(@web_service_url.scheme) raise ArgumentError if not @authentication_token or @authentication_token.empty? raise ArgumentError, "Allowed domains" unless @allowed_domains.count > 0 true end |