Class: Authentise::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/authentise/model.rb

Overview

Represents a model in the Model Warehouse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, url: nil, upload_url: nil, uuid: nil) ⇒ Model

Returns a new instance of Model.



29
30
31
32
33
34
35
36
37
# File 'lib/authentise/model.rb', line 29

def initialize(name: nil,
               url: nil,
               upload_url: nil,
               uuid: nil)
  @name = name
  @upload_url = upload_url
  @url = url
  @uuid = uuid
end

Instance Attribute Details

#children_urlsObject

Required



6
7
8
# File 'lib/authentise/model.rb', line 6

def children_urls
  @children_urls
end

#content_urlObject

Required



6
7
8
# File 'lib/authentise/model.rb', line 6

def content_url
  @content_url
end

#created_atObject

Required



6
7
8
# File 'lib/authentise/model.rb', line 6

def created_at
  @created_at
end

#manifoldObject

Required



6
7
8
# File 'lib/authentise/model.rb', line 6

def manifold
  @manifold
end

#nameObject

Required



6
7
8
# File 'lib/authentise/model.rb', line 6

def name
  @name
end

#parents_urlsObject

Required



6
7
8
# File 'lib/authentise/model.rb', line 6

def parents_urls
  @parents_urls
end

#snapshot_urlObject

Required



6
7
8
# File 'lib/authentise/model.rb', line 6

def snapshot_url
  @snapshot_url
end

#statusObject

Required



6
7
8
# File 'lib/authentise/model.rb', line 6

def status
  @status
end

#updated_atObject

Required



6
7
8
# File 'lib/authentise/model.rb', line 6

def updated_at
  @updated_at
end

#upload_urlObject

Required



6
7
8
# File 'lib/authentise/model.rb', line 6

def upload_url
  @upload_url
end

#urlObject

Required



6
7
8
# File 'lib/authentise/model.rb', line 6

def url
  @url
end

#uuidObject

Required



6
7
8
# File 'lib/authentise/model.rb', line 6

def uuid
  @uuid
end

Class Method Details

.find_by_url(url: nil, session_token: nil) ⇒ Object

rubocop:enable Metrics/AbcSize



76
77
78
79
80
# File 'lib/authentise/model.rb', line 76

def self.find_by_url(url: nil, session_token: nil)
  model = new(url: url)
  model.fetch(session_token: session_token)
  model
end

.find_by_uuid(uuid: nil, session_token: nil) ⇒ Object



82
83
84
85
86
# File 'lib/authentise/model.rb', line 82

def self.find_by_uuid(uuid: nil, session_token: nil)
  model = new(uuid: uuid)
  model.fetch(session_token: session_token)
  model
end

Instance Method Details

#create(session_token: nil) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/authentise/model.rb', line 39

def create(session_token: nil)
  response = API::Warehouse.create_model(
    session_token: session_token,
    name: name,
  )
  @upload_url = response[:upload_url]
  @url = response[:model_url]
  true
end

#fetch(session_token: nil) ⇒ Object

rubocop:disable Metrics/AbcSize



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/authentise/model.rb', line 57

def fetch(session_token: nil)
  response = API::Warehouse.get_model(uuid: uuid,
                                      url: url,
                                      session_token: session_token)
  @url = response[:url]
  @uuid = response[:uuid]
  @name = response[:name]
  @status = response[:status]
  @snapshot_url = response[:snapshot_url]
  @content_url = response[:content_url]
  @manifold = response[:manifold]
  @parents_urls = response[:parents_urls]
  @children_urls = response[:children_urls]
  @created_at = response[:created_at]
  @updated_at = response[:updated_at]
  true
end

#send_file(path: nil) ⇒ Object



49
50
51
52
53
54
# File 'lib/authentise/model.rb', line 49

def send_file(path: nil)
  API::Warehouse.put_file(
    url: upload_url,
    path: path,
  )
end