Class: Puree::Organisation

Inherits:
Resource show all
Defined in:
lib/puree/organisation.rb

Overview

Organisation resource

Instance Method Summary collapse

Methods inherited from Resource

#content, #created, #get, #modified, #response, #set_content, #uuid

Constructor Details

#initialize(endpoint: nil, username: nil, password: nil) ⇒ Organisation

Returns a new instance of Organisation.

Parameters:

  • endpoint (String) (defaults to: nil)
  • optional

    username [String]

  • optional

    password [String]



10
11
12
13
14
15
# File 'lib/puree/organisation.rb', line 10

def initialize(endpoint: nil, username: nil, password: nil)
  super(api: :organisation,
        endpoint: endpoint,
        username: username,
        password: password)
end

Instance Method Details

#addressArray<Hash>

Address

Returns:

  • (Array<Hash>)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/puree/organisation.rb', line 20

def address
  path = '//addresses/classifiedAddress'
  xpath_result =  xpath_query path

  data = []

  xpath_result.each do |d|
    o = {}
    o['street'] = d.xpath('street').text.strip
    o['building'] = d.xpath('building').text.strip
    o['postcode'] = d.xpath('postalCode').text.strip
    o['city'] = d.xpath('city').text.strip
    o['country'] = d.xpath('country/term/localizedString').text.strip
    data << o
  end
  data.uniq
end

#emailArray<String>

Email

Returns:

  • (Array<String>)


41
42
43
44
45
46
47
# File 'lib/puree/organisation.rb', line 41

def email
  path = '//emails/classificationDefinedStringFieldExtension/value'
  xpath_result =  xpath_query path
  arr = []
  xpath_result.each { |i| arr << i.text.strip }
  arr.uniq
end

#metadataHash

All metadata

Returns:

  • (Hash)


103
104
105
106
107
108
109
110
111
112
113
# File 'lib/puree/organisation.rb', line 103

def 
  o = super
  o['address'] = address
  o['email'] = email
  o['name'] = name
  o['parent'] = parent
  o['phone'] = phone
  o['type'] = type
  o['url'] = url
  o
end

#nameString

Name

Returns:

  • (String)


52
53
54
55
# File 'lib/puree/organisation.rb', line 52

def name
  data = node 'name'
  !data.nil? && !data.empty? ? data['localizedString']['__content__'].strip : ''
end

#parentHash

Parent

Returns:

  • (Hash)


60
61
62
63
64
65
66
67
# File 'lib/puree/organisation.rb', line 60

def parent
  data = organisation
  o = {}
  if !data.empty?
    o = data.first
  end
  o
end

#phoneArray<String>

Phone

Returns:

  • (Array<String>)


72
73
74
75
76
77
78
# File 'lib/puree/organisation.rb', line 72

def phone
  path = '//phoneNumbers/classificationDefinedStringFieldExtension/value'
  xpath_result =  xpath_query path
  arr = []
  xpath_result.each { |i| arr << i.text.strip }
  arr.uniq
end

#typeString

Type

Returns:

  • (String)


83
84
85
86
87
# File 'lib/puree/organisation.rb', line 83

def type
  path = '//content/typeClassification/term/localizedString'
  xpath_result = xpath_query path
  xpath_result ? xpath_result.text.strip : ''
end

#urlArray<String>

URL

Returns:

  • (Array<String>)


92
93
94
95
96
97
98
# File 'lib/puree/organisation.rb', line 92

def url
  path = '//content/webAddresses/classificationDefinedFieldExtension/value/localizedString'
  xpath_result = xpath_query path
  arr = []
  xpath_result.each { |i| arr << i.text.strip }
  arr.uniq
end