Class: Envoi::Aspera::WatchService::WatchFolder::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/envoi/aspera/watch_service/watch_folder.rb

Defined Under Namespace

Classes: Snapshot

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, client, definition = nil, snapshots = { }) ⇒ Subscription

Returns a new instance of Subscription.



100
101
102
103
104
105
# File 'lib/envoi/aspera/watch_service/watch_folder.rb', line 100

def initialize(data, client, definition = nil, snapshots = { })
  @attributes = data
  @client     = client
  @definition = definition
  @snapshots  = {}
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



98
99
100
# File 'lib/envoi/aspera/watch_service/watch_folder.rb', line 98

def attributes
  @attributes
end

#clientObject

Returns the value of attribute client.



98
99
100
# File 'lib/envoi/aspera/watch_service/watch_folder.rb', line 98

def client
  @client
end

#definitionObject

Returns the value of attribute definition.



98
99
100
# File 'lib/envoi/aspera/watch_service/watch_folder.rb', line 98

def definition
  @definition
end

#snapshotsObject

Returns the value of attribute snapshots.



98
99
100
# File 'lib/envoi/aspera/watch_service/watch_folder.rb', line 98

def snapshots
  @snapshots
end

Class Method Details

.get_or_create(client, definition, snapshots = { }) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/envoi/aspera/watch_service/watch_folder.rb', line 133

def self.get_or_create(client, definition, snapshots = { })
  watch_folder_path = definition['path']
  scan_period       = definition['scan_period']
  expire_in         = definition['expire_in']

  subscriptions          = nil
  subscriptions_for_path = client.subscription_find_for_path(path: watch_folder_path, subscriptions: subscriptions)
  subscriptions_for_path.delete_if { |s| s['scan_period']['sec'] != scan_period } if scan_period

  if subscriptions_for_path.empty?
    args_out               = { watch_folder_path: watch_folder_path }
    args_out[:scan_period] = scan_period if scan_period
    args_out[:expire_in]   = expire_in if expire_in
    # Create Subscription
    subscription = client.subscription_create(args_out)
  else
    subscription = subscriptions_for_path.first
  end

  new(subscription, client, definition, snapshots)
end

Instance Method Details

#[](key) ⇒ Object



111
112
113
# File 'lib/envoi/aspera/watch_service/watch_folder.rb', line 111

def [](key)
  attributes[key]
end

#identifierObject Also known as: id



115
116
117
# File 'lib/envoi/aspera/watch_service/watch_folder.rb', line 115

def identifier
  attributes['identifier']
end

#loggerObject



107
108
109
# File 'lib/envoi/aspera/watch_service/watch_folder.rb', line 107

def logger
  client.logger
end

#resubscribeObject



128
129
130
# File 'lib/envoi/aspera/watch_service/watch_folder.rb', line 128

def resubscribe
  client.subscription_resubscribe(subscription_id: id)
end

#snapshot_create(args = {}) ⇒ Object



121
122
123
124
125
126
# File 'lib/envoi/aspera/watch_service/watch_folder.rb', line 121

def snapshot_create(args = {})
  args_out                   = args.dup
  args_out[:subscription_id] = attributes['identifier']
  snapshot_id                = client.subscription_snapshot_create(args_out)
  snapshots[snapshot_id]     ||= Snapshot.new(self, snapshot_id)
end