Class: Grocer::Pushpackager::Website

Inherits:
Object
  • Object
show all
Defined in:
lib/grocer/pushpackager/website.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_domainsObject (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_tokenObject

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_idObject (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_stringObject (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_urlObject (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_nameObject (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_jsonObject



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

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


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