Class: Licensario::License

Inherits:
Base
  • Object
show all
Defined in:
lib/licensario/license.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

api, date_format, establish_connection

Constructor Details

#initialize(attributes = {}) ⇒ License

Returns a new instance of License.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/licensario/license.rb', line 7

def initialize(attributes = {})
  if attributes[:xml_node] or attributes[:xml]
    xml_node = attributes[:xml_node] ? attributes[:xml_node] : Nokogiri::XML(attributes[:xml]).xpath("//licenseCertificate")[0]
    xml_attrs = xml_node.attributes
    {
      id: 'licenseId',
      user_id: 'userId',
      payment_plan_id: 'paymentPlanId',
      issue_date_utc: 'issueDateUTC',
      expiration_date_utc: 'expirationDateUTC',
      is_trial: 'is_trial'
    }.each do |k,v|
      attributes[k] = xml_attrs[v] ? xml_attrs[v].value : nil
    end
    attributes[:included_resources] = []
    xml_node.xpath("//resources/resource").each do |node|
      resource = Licensario::LicensedResource.new(xml_node: node)
      attributes[:included_resources] << resource
    end
    attributes[:included_features] = []
    xml_node.xpath("//features/feature").each do |node|
      feature = Licensario::LicensedFeature.new(xml_node: node)
      attributes[:included_features] << feature
    end
    attributes.delete(:xml_node)
    attributes.delete(:xml)
  end
  attributes[:is_trial] = 'false' if !attributes.has_key?(:is_trial)
  super(attributes)
end

Instance Attribute Details

#expiration_date_utcObject

Returns the value of attribute expiration_date_utc.



5
6
7
# File 'lib/licensario/license.rb', line 5

def expiration_date_utc
  @expiration_date_utc
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/licensario/license.rb', line 5

def id
  @id
end

#included_featuresObject

Returns the value of attribute included_features.



5
6
7
# File 'lib/licensario/license.rb', line 5

def included_features
  @included_features
end

#included_resourcesObject

Returns the value of attribute included_resources.



5
6
7
# File 'lib/licensario/license.rb', line 5

def included_resources
  @included_resources
end

#is_trialObject

Returns the value of attribute is_trial.



5
6
7
# File 'lib/licensario/license.rb', line 5

def is_trial
  @is_trial
end

#issue_date_utcObject

Returns the value of attribute issue_date_utc.



5
6
7
# File 'lib/licensario/license.rb', line 5

def issue_date_utc
  @issue_date_utc
end

#payment_plan_idObject

Returns the value of attribute payment_plan_id.



5
6
7
# File 'lib/licensario/license.rb', line 5

def payment_plan_id
  @payment_plan_id
end

#user_idObject

Returns the value of attribute user_id.



5
6
7
# File 'lib/licensario/license.rb', line 5

def user_id
  @user_id
end

Instance Method Details

#to_sObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/licensario/license.rb', line 48

def to_s
  s = %Q{}
  s += "licenseId: #{id}\n"
  s += "isTrial: #{is_trial}\n"
  s += "userId: #{user_id}\n"
  s += "issued(UTC): #{issue_date_utc}\n"
  s += "expires(UTC): #{expiration_date_utc}\n"
  s += "includedFeatures: #{included_features}\n"
  s += "includedResources: #{included_resources}\n"
  return s
end