Class: HandleSystem::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/handle_system/record.rb

Overview

Handle Record entry

Author:

  • David Walker

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataHash (readonly)

Returns the internal hash data.

Returns:

  • (Hash)

    the internal hash data



11
12
13
# File 'lib/handle_system/record.rb', line 11

def data
  @data
end

#emailString (readonly)

Returns email address added to record.

Returns:

  • (String)

    email address added to record



20
21
22
# File 'lib/handle_system/record.rb', line 20

def email
  @email
end

#handleString (readonly)

Returns handle identifier.

Returns:

  • (String)

    handle identifier



14
15
16
# File 'lib/handle_system/record.rb', line 14

def handle
  @handle
end

#hs_adminString (readonly)

Returns handle administrator.

Returns:

  • (String)

    handle administrator



23
24
25
# File 'lib/handle_system/record.rb', line 23

def hs_admin
  @hs_admin
end

#urlString (readonly)

Returns the url we registered.

Returns:

  • (String)

    the url we registered



17
18
19
# File 'lib/handle_system/record.rb', line 17

def url
  @url
end

Instance Method Details

#from_json(json) ⇒ Object

Populate Record from JSON

Parameters:

  • data (JSON)

    the handle server record as json



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/handle_system/record.rb', line 55

def from_json(json)
  @data = json
  @handle = json['handle']
  json['values'].each do |part|
    value = part['data']['value']
    @url = value if part['type'] == 'URL'
    @has_admin = value if part['type'] == 'EMAIL'
    @email = value if part['type'] == 'HS_ADMIN'
  end
  self
end

#from_values(handle, url, email = nil, hs_admin = nil) ⇒ Object

Populate Record from values

Parameters:

  • handle (String)

    e.g., 20.500.12345/876

  • url (String)

    the url we want to register

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

    email address to add to record

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

    handle administrator to add to record



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/handle_system/record.rb', line 33

def from_values(handle, url, email = nil, hs_admin = nil)
  @handle = handle
  @url = url
  @email = email
  @hs_admin = hs_admin

  values = [build_url_field(url)]
  values.push(build_email_field(email)) unless email.nil?
  values.push(build_admin_field(hs_admin)) unless hs_admin.nil?
  @data = {
    'values': values,
    'handle': handle,
    'responseCode': 1
  }
  self
end

#json<String>

Returns JSON string.

Returns:

  • (<String>)

    JSON string



70
71
72
# File 'lib/handle_system/record.rb', line 70

def json
  @data.to_json
end