Class: JScrambler::Project::File

Inherits:
Object
  • Object
show all
Defined in:
lib/jscrambler/project/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, client) ⇒ File

Returns a new instance of File.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
# File 'lib/jscrambler/project/file.rb', line 6

def initialize(options={}, client)
  raise ArgumentError, 'Cannot create file without ID' unless options['id']
  @id = options['id']
  @project_id = options['project_id']
  @client = client
  @extension = options['extension']
  @filename = options['filename']
  @size = options['size']
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'lib/jscrambler/project/file.rb', line 4

def client
  @client
end

#extensionObject (readonly)

Returns the value of attribute extension.



4
5
6
# File 'lib/jscrambler/project/file.rb', line 4

def extension
  @extension
end

#filenameObject (readonly)

Returns the value of attribute filename.



4
5
6
# File 'lib/jscrambler/project/file.rb', line 4

def filename
  @filename
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/jscrambler/project/file.rb', line 4

def id
  @id
end

#project_idObject (readonly)

Returns the value of attribute project_id.



4
5
6
# File 'lib/jscrambler/project/file.rb', line 4

def project_id
  @project_id
end

#sizeObject (readonly)

Returns the value of attribute size.



4
5
6
# File 'lib/jscrambler/project/file.rb', line 4

def size
  @size
end

Instance Method Details

#downloadObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/jscrambler/project/file.rb', line 16

def download
  client.handle_response(client.api.get("code/#{project_id}/#{id}.#{extension}")) do |response|
    to_file_path = File.join(client.config['filesDest'], "#{filename}")
    File.delete(to_file_path) if File.exist?(to_file_path)
    file_handler = File.open(to_file_path, 'w')
    file_handler.write(response)
    file_handler.close
  end
  true
end