Class: JScrambler::Project
- Inherits:
-
Object
- Object
- JScrambler::Project
- Defined in:
- lib/jscrambler/project.rb
Defined Under Namespace
Classes: File
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#finished_at ⇒ Object
readonly
Returns the value of attribute finished_at.
-
#html_files ⇒ Object
readonly
Returns the value of attribute html_files.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#js_files ⇒ Object
readonly
Returns the value of attribute js_files.
-
#received_at ⇒ Object
readonly
Returns the value of attribute received_at.
Instance Method Summary collapse
- #delete ⇒ Object
- #download ⇒ Object
- #files ⇒ Object
-
#initialize(options = {}, client) ⇒ Project
constructor
A new instance of Project.
- #status ⇒ Object
Constructor Details
#initialize(options = {}, client) ⇒ Project
Returns a new instance of Project.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/jscrambler/project.rb', line 6 def initialize(={}, client) raise ArgumentError, 'Cannot create project without ID' unless ['id'] @client = client @id = ['id'] @sources = ['sources'] @received_at = ['received_at'] @finished_at = ['finished_at'] @js_files = ['js_files'] @html_files = ['html_files'] end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
4 5 6 |
# File 'lib/jscrambler/project.rb', line 4 def client @client end |
#finished_at ⇒ Object (readonly)
Returns the value of attribute finished_at.
4 5 6 |
# File 'lib/jscrambler/project.rb', line 4 def finished_at @finished_at end |
#html_files ⇒ Object (readonly)
Returns the value of attribute html_files.
4 5 6 |
# File 'lib/jscrambler/project.rb', line 4 def html_files @html_files end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/jscrambler/project.rb', line 4 def id @id end |
#js_files ⇒ Object (readonly)
Returns the value of attribute js_files.
4 5 6 |
# File 'lib/jscrambler/project.rb', line 4 def js_files @js_files end |
#received_at ⇒ Object (readonly)
Returns the value of attribute received_at.
4 5 6 |
# File 'lib/jscrambler/project.rb', line 4 def received_at @received_at end |
Instance Method Details
#delete ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/jscrambler/project.rb', line 54 def delete client.handle_response(client.api.delete("code/#{id}.zip")) do |json_response| is_deleted = json_response['deleted'] LOGGER.info "Deleted project #{id}" if is_deleted is_deleted end end |
#download ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jscrambler/project.rb', line 38 def download if status == :finished client.handle_response(client.api.get("code/#{id}.zip")) do |response| LOGGER.info "Downloading source files for #{id}..." temp = Tempfile.new(%w(jscrambler .zip)) temp.write(response.force_encoding('UTF-8')) temp.close JScrambler::Archiver.new(temp).unzip(client.config['filesDest']) end delete if client.config['deleteProject'] true else false end end |
#files ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jscrambler/project.rb', line 19 def files @files ||= begin if @sources.nil? @sources = client.handle_response(client.api.get("code/#{id}.json")) do |json_response| json_response['sources'] end end @sources.to_a.map { |file_hash| JScrambler::Project::File.new(file_hash.merge('project_id' => id), client) } end end |
#status ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/jscrambler/project.rb', line 30 def status client.handle_response(client.api.get("code/#{id}.json")) do |json_response| status = json_response['finished_at'] ? :finished : :processing LOGGER.debug "Status for project #{id}: #{status}" status end end |