rest-ftp-daemon 0.2.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +0 -2
- data/Gemfile.lock +0 -8
- data/README.md +6 -4
- data/VERSION +1 -1
- data/bin/rest-ftp-daemon +7 -3
- data/lib/config.rb +5 -0
- data/lib/{rest-ftp-daemon/config.ru → config.ru} +0 -2
- data/lib/rest-ftp-daemon.rb +36 -19
- data/rest-ftp-daemon.gemspec +66 -0
- metadata +4 -35
    
        data/Gemfile
    CHANGED
    
    
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -11,7 +11,6 @@ GEM | |
| 11 11 | 
             
                builder (3.2.2)
         | 
| 12 12 | 
             
                descendants_tracker (0.0.4)
         | 
| 13 13 | 
             
                  thread_safe (~> 0.3, >= 0.3.1)
         | 
| 14 | 
            -
                docile (1.1.5)
         | 
| 15 14 | 
             
                faraday (0.9.0)
         | 
| 16 15 | 
             
                  multipart-post (>= 1.2, < 3)
         | 
| 17 16 | 
             
                git (1.2.7)
         | 
| @@ -62,11 +61,6 @@ GEM | |
| 62 61 | 
             
                shoulda-context (1.2.1)
         | 
| 63 62 | 
             
                shoulda-matchers (2.6.2)
         | 
| 64 63 | 
             
                  activesupport (>= 3.0.0)
         | 
| 65 | 
            -
                simplecov (0.9.0)
         | 
| 66 | 
            -
                  docile (~> 1.1.0)
         | 
| 67 | 
            -
                  multi_json
         | 
| 68 | 
            -
                  simplecov-html (~> 0.8.0)
         | 
| 69 | 
            -
                simplecov-html (0.8.0)
         | 
| 70 64 | 
             
                sinatra (1.4.5)
         | 
| 71 65 | 
             
                  rack (~> 1.4)
         | 
| 72 66 | 
             
                  rack-protection (~> 1.4)
         | 
| @@ -83,7 +77,5 @@ DEPENDENCIES | |
| 83 77 | 
             
              bundler (~> 1.0)
         | 
| 84 78 | 
             
              jeweler (~> 2.0.1)
         | 
| 85 79 | 
             
              json
         | 
| 86 | 
            -
              rdoc (~> 3.12)
         | 
| 87 80 | 
             
              shoulda
         | 
| 88 | 
            -
              simplecov
         | 
| 89 81 | 
             
              sinatra
         | 
    
        data/README.md
    CHANGED
    
    | @@ -14,13 +14,15 @@ As of today, its main features are : | |
| 14 14 |  | 
| 15 15 | 
             
            This project requires ruby >= 1.9 and rubygems installed.
         | 
| 16 16 |  | 
| 17 | 
            -
             | 
| 17 | 
            +
            Quickly install the gem from rubygems.org:
         | 
| 18 18 |  | 
| 19 | 
            -
             ``` gem install  | 
| 19 | 
            +
             ``` gem install rest-ftp-daemon ```
         | 
| 20 20 |  | 
| 21 | 
            -
             | 
| 21 | 
            +
            Start the daemon:
         | 
| 22 22 |  | 
| 23 | 
            -
            ```  | 
| 23 | 
            +
            ``` rest-ftp-daemon start ```
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            For now, daemon logs to APP_LOGTO defined in lib/config.rb
         | 
| 24 26 |  | 
| 25 27 |  | 
| 26 28 | 
             
            ## Basic usage ##
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0. | 
| 1 | 
            +
            0.5.0
         | 
    
        data/bin/rest-ftp-daemon
    CHANGED
    
    | @@ -2,14 +2,18 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            # Libs and init
         | 
| 4 4 | 
             
            require 'thin'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            # Initialize some local constants
         | 
| 5 7 | 
             
            APP_ROOT = File.dirname(__FILE__) + '/../'
         | 
| 6 | 
            -
             | 
| 8 | 
            +
            APP_VER = File.read "#{APP_ROOT}/VERSION"
         | 
| 9 | 
            +
            APP_STARTED = Time.now
         | 
| 10 | 
            +
            APP_DEFAULT_PORT = 3000
         | 
| 7 11 |  | 
| 8 12 | 
             
            # Prepare thin
         | 
| 9 | 
            -
            rackup_file = File.expand_path "#{APP_ROOT}/lib/ | 
| 13 | 
            +
            rackup_file = File.expand_path "#{APP_ROOT}/lib/config.ru"
         | 
| 10 14 | 
             
            argv = ARGV
         | 
| 11 15 | 
             
            argv << ["-R", rackup_file] unless ARGV.include?("-R")
         | 
| 12 | 
            -
            argv << ["-p",  | 
| 16 | 
            +
            argv << ["-p", APP_DEFAULT_PORT.to_s] unless ARGV.include?("-p")
         | 
| 13 17 | 
             
            argv << ["-e", "production"] unless ARGV.include?("-e")
         | 
| 14 18 |  | 
| 15 19 | 
             
            # Start thin
         | 
    
        data/lib/config.rb
    CHANGED
    
    
    
        data/lib/rest-ftp-daemon.rb
    CHANGED
    
    | @@ -1,21 +1,20 @@ | |
| 1 1 | 
             
            class RestFtpDaemon < Sinatra::Base
         | 
| 2 | 
            -
              helpers Sinatra::JSON
         | 
| 3 2 |  | 
| 4 3 | 
             
              # General config
         | 
| 5 4 | 
             
              configure :development, :production do
         | 
| 6 5 |  | 
| 7 6 | 
             
                # Create new thread group
         | 
| 8 7 | 
             
                @@threads = ThreadGroup.new
         | 
| 9 | 
            -
             | 
| 10 | 
            -
                #  | 
| 8 | 
            +
             | 
| 9 | 
            +
                # Some other configuration
         | 
| 10 | 
            +
                set :sessions, false
         | 
| 11 11 | 
             
                # set :logging, true
         | 
| 12 | 
            -
                # set :root, APP_ROOT + '/lib/'
         | 
| 13 12 | 
             
              end
         | 
| 14 13 |  | 
| 15 14 | 
             
              # Server initialization
         | 
| 16 15 | 
             
              def initialize
         | 
| 17 16 | 
             
                # Setup logger
         | 
| 18 | 
            -
                @logger = Logger.new( | 
| 17 | 
            +
                @logger = Logger.new(APP_LOGTO, 'daily')
         | 
| 19 18 | 
             
                @logger.level = Logger::INFO
         | 
| 20 19 |  | 
| 21 20 | 
             
                # Other stuff
         | 
| @@ -27,20 +26,30 @@ class RestFtpDaemon < Sinatra::Base | |
| 27 26 |  | 
| 28 27 | 
             
              # Server global status
         | 
| 29 28 | 
             
              get "/" do
         | 
| 29 | 
            +
                # Debug query
         | 
| 30 | 
            +
                info "GET /"
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                # Build response
         | 
| 30 33 | 
             
                content_type :json
         | 
| 31 | 
            -
                 | 
| 34 | 
            +
                JSON.pretty_generate get_status
         | 
| 32 35 | 
             
              end
         | 
| 33 36 |  | 
| 34 37 | 
             
              # List jobs
         | 
| 35 38 | 
             
              get "/jobs" do
         | 
| 39 | 
            +
                # Debug query
         | 
| 40 | 
            +
                info "GET /jobs"
         | 
| 41 | 
            +
             | 
| 36 42 | 
             
                # Build response
         | 
| 37 43 | 
             
                content_type :json
         | 
| 38 | 
            -
                 | 
| 44 | 
            +
                JSON.pretty_generate get_jobs
         | 
| 39 45 | 
             
                #@@threads.count
         | 
| 40 46 | 
             
              end
         | 
| 41 47 |  | 
| 42 48 | 
             
              # List jobs
         | 
| 43 49 | 
             
              delete "/jobs/:name" do
         | 
| 50 | 
            +
                # Debug query
         | 
| 51 | 
            +
                info "DELETE /jobs/#{params[:name]}"
         | 
| 52 | 
            +
             | 
| 44 53 | 
             
                # Kill this job
         | 
| 45 54 | 
             
                ret = delete_job params[:name]
         | 
| 46 55 |  | 
| @@ -49,22 +58,24 @@ class RestFtpDaemon < Sinatra::Base | |
| 49 58 |  | 
| 50 59 | 
             
                # Build response
         | 
| 51 60 | 
             
                content_type :json
         | 
| 52 | 
            -
                 | 
| 61 | 
            +
                JSON.pretty_generate nil
         | 
| 53 62 | 
             
              end
         | 
| 54 63 |  | 
| 55 64 | 
             
              # Spawn a new thread for this new job
         | 
| 56 65 | 
             
              post '/jobs' do
         | 
| 66 | 
            +
                # Extract payload
         | 
| 57 67 | 
             
                request.body.rewind
         | 
| 58 68 | 
             
                payload = JSON.parse request.body.read
         | 
| 59 | 
            -
                info "POST / with #{payload.to_json}"
         | 
| 60 69 |  | 
| 61 | 
            -
                #  | 
| 62 | 
            -
                 | 
| 70 | 
            +
                # Debug query
         | 
| 71 | 
            +
                info "POST /jobs: #{payload.to_json}"
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                # Spawn a thread for this job
         | 
| 63 74 | 
             
                result = new_job payload
         | 
| 64 75 |  | 
| 65 76 | 
             
                # Build response
         | 
| 66 77 | 
             
                content_type :json
         | 
| 67 | 
            -
                 | 
| 78 | 
            +
                JSON.pretty_generate result
         | 
| 68 79 | 
             
              end
         | 
| 69 80 |  | 
| 70 81 | 
             
              protected
         | 
| @@ -139,13 +150,21 @@ class RestFtpDaemon < Sinatra::Base | |
| 139 150 | 
             
              end
         | 
| 140 151 |  | 
| 141 152 | 
             
              def get_status
         | 
| 153 | 
            +
                info "> get_status"
         | 
| 154 | 
            +
             | 
| 142 155 | 
             
                {
         | 
| 143 | 
            -
                 | 
| 156 | 
            +
                app_name: APP_NAME,
         | 
| 157 | 
            +
                hostname: @@hostname,
         | 
| 158 | 
            +
                version: APP_VER,
         | 
| 159 | 
            +
                started: APP_STARTED,
         | 
| 160 | 
            +
                uptime: (Time.now - APP_STARTED).round(1),
         | 
| 144 161 | 
             
                jobs_count: @@threads.list.count,
         | 
| 145 162 | 
             
                }
         | 
| 146 163 | 
             
              end
         | 
| 147 164 |  | 
| 148 165 | 
             
              def get_jobs
         | 
| 166 | 
            +
                info "> get_jobs"
         | 
| 167 | 
            +
             | 
| 149 168 | 
             
                output = []
         | 
| 150 169 | 
             
                @@threads.list.each do |thread|
         | 
| 151 170 | 
             
                  output << {
         | 
| @@ -160,6 +179,8 @@ class RestFtpDaemon < Sinatra::Base | |
| 160 179 |  | 
| 161 180 |  | 
| 162 181 | 
             
              def delete_job name
         | 
| 182 | 
            +
                info "> delete_job(#{name})"
         | 
| 183 | 
            +
             | 
| 163 184 | 
             
                count = 0
         | 
| 164 185 | 
             
                @@threads.list.collect do |thread|
         | 
| 165 186 | 
             
                  next unless thread[:name] == name
         | 
| @@ -170,7 +191,7 @@ class RestFtpDaemon < Sinatra::Base | |
| 170 191 | 
             
              end
         | 
| 171 192 |  | 
| 172 193 | 
             
              def new_job context = {}
         | 
| 173 | 
            -
                info "new_job | 
| 194 | 
            +
                info "new_job"
         | 
| 174 195 |  | 
| 175 196 | 
             
                # Generate name
         | 
| 176 197 | 
             
                @@last_worker_id +=1
         | 
| @@ -219,12 +240,8 @@ class RestFtpDaemon < Sinatra::Base | |
| 219 240 | 
             
                return { code: 0, errmsg: 'success', name: name, context: context }
         | 
| 220 241 | 
             
              end
         | 
| 221 242 |  | 
| 222 | 
            -
              def log level, msg=""
         | 
| 223 | 
            -
                @logger.send(level.to_s, msg)
         | 
| 224 | 
            -
              end
         | 
| 225 | 
            -
             | 
| 226 243 | 
             
              def info msg=""
         | 
| 227 | 
            -
                 | 
| 244 | 
            +
                @logger.send :info, msg
         | 
| 228 245 | 
             
              end
         | 
| 229 246 |  | 
| 230 247 | 
             
              def job_status code, errmsg
         | 
| @@ -0,0 +1,66 @@ | |
| 1 | 
            +
            # Generated by jeweler
         | 
| 2 | 
            +
            # DO NOT EDIT THIS FILE DIRECTLY
         | 
| 3 | 
            +
            # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
         | 
| 4 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |s|
         | 
| 7 | 
            +
              s.name = "rest-ftp-daemon"
         | 
| 8 | 
            +
              s.version = "0.5.0"
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 | 
            +
              s.authors = ["Bruno"]
         | 
| 12 | 
            +
              s.date = "2014-07-31"
         | 
| 13 | 
            +
              s.description = "A fairly basic FTP client daemon, driven by RESTful webservice calls"
         | 
| 14 | 
            +
              s.email = "rest-ftp-daemon@bmconseil.com"
         | 
| 15 | 
            +
              s.executables = ["rest-ftp-daemon"]
         | 
| 16 | 
            +
              s.extra_rdoc_files = [
         | 
| 17 | 
            +
                "LICENSE.txt",
         | 
| 18 | 
            +
                "README.md"
         | 
| 19 | 
            +
              ]
         | 
| 20 | 
            +
              s.files = [
         | 
| 21 | 
            +
                "Gemfile",
         | 
| 22 | 
            +
                "Gemfile.lock",
         | 
| 23 | 
            +
                "LICENSE.txt",
         | 
| 24 | 
            +
                "README.md",
         | 
| 25 | 
            +
                "Rakefile",
         | 
| 26 | 
            +
                "VERSION",
         | 
| 27 | 
            +
                "bin/rest-ftp-daemon",
         | 
| 28 | 
            +
                "lib/config.rb",
         | 
| 29 | 
            +
                "lib/config.ru",
         | 
| 30 | 
            +
                "lib/errors.rb",
         | 
| 31 | 
            +
                "lib/rest-ftp-daemon.rb",
         | 
| 32 | 
            +
                "rest-ftp-daemon.gemspec",
         | 
| 33 | 
            +
                "test/helper.rb",
         | 
| 34 | 
            +
                "test/test_rest-ftp-daemon.rb"
         | 
| 35 | 
            +
              ]
         | 
| 36 | 
            +
              s.homepage = "http://github.com/bmedici/rest-ftp-daemon"
         | 
| 37 | 
            +
              s.licenses = ["MIT"]
         | 
| 38 | 
            +
              s.require_paths = ["lib"]
         | 
| 39 | 
            +
              s.rubygems_version = "1.8.23"
         | 
| 40 | 
            +
              s.summary = "RESTful FTP client daemon"
         | 
| 41 | 
            +
             | 
| 42 | 
            +
              if s.respond_to? :specification_version then
         | 
| 43 | 
            +
                s.specification_version = 3
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
         | 
| 46 | 
            +
                  s.add_runtime_dependency(%q<sinatra>, [">= 0"])
         | 
| 47 | 
            +
                  s.add_runtime_dependency(%q<json>, [">= 0"])
         | 
| 48 | 
            +
                  s.add_development_dependency(%q<shoulda>, [">= 0"])
         | 
| 49 | 
            +
                  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
         | 
| 50 | 
            +
                  s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
         | 
| 51 | 
            +
                else
         | 
| 52 | 
            +
                  s.add_dependency(%q<sinatra>, [">= 0"])
         | 
| 53 | 
            +
                  s.add_dependency(%q<json>, [">= 0"])
         | 
| 54 | 
            +
                  s.add_dependency(%q<shoulda>, [">= 0"])
         | 
| 55 | 
            +
                  s.add_dependency(%q<bundler>, ["~> 1.0"])
         | 
| 56 | 
            +
                  s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
              else
         | 
| 59 | 
            +
                s.add_dependency(%q<sinatra>, [">= 0"])
         | 
| 60 | 
            +
                s.add_dependency(%q<json>, [">= 0"])
         | 
| 61 | 
            +
                s.add_dependency(%q<shoulda>, [">= 0"])
         | 
| 62 | 
            +
                s.add_dependency(%q<bundler>, ["~> 1.0"])
         | 
| 63 | 
            +
                s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
         | 
| 64 | 
            +
              end
         | 
| 65 | 
            +
            end
         | 
| 66 | 
            +
             | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rest-ftp-daemon
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.5.0
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -59,22 +59,6 @@ dependencies: | |
| 59 59 | 
             
                - - ! '>='
         | 
| 60 60 | 
             
                  - !ruby/object:Gem::Version
         | 
| 61 61 | 
             
                    version: '0'
         | 
| 62 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 63 | 
            -
              name: rdoc
         | 
| 64 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 65 | 
            -
                none: false
         | 
| 66 | 
            -
                requirements:
         | 
| 67 | 
            -
                - - ~>
         | 
| 68 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 69 | 
            -
                    version: '3.12'
         | 
| 70 | 
            -
              type: :development
         | 
| 71 | 
            -
              prerelease: false
         | 
| 72 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 73 | 
            -
                none: false
         | 
| 74 | 
            -
                requirements:
         | 
| 75 | 
            -
                - - ~>
         | 
| 76 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 77 | 
            -
                    version: '3.12'
         | 
| 78 62 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 79 63 | 
             
              name: bundler
         | 
| 80 64 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -107,22 +91,6 @@ dependencies: | |
| 107 91 | 
             
                - - ~>
         | 
| 108 92 | 
             
                  - !ruby/object:Gem::Version
         | 
| 109 93 | 
             
                    version: 2.0.1
         | 
| 110 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 111 | 
            -
              name: simplecov
         | 
| 112 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 113 | 
            -
                none: false
         | 
| 114 | 
            -
                requirements:
         | 
| 115 | 
            -
                - - ! '>='
         | 
| 116 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            -
                    version: '0'
         | 
| 118 | 
            -
              type: :development
         | 
| 119 | 
            -
              prerelease: false
         | 
| 120 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 | 
            -
                none: false
         | 
| 122 | 
            -
                requirements:
         | 
| 123 | 
            -
                - - ! '>='
         | 
| 124 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 125 | 
            -
                    version: '0'
         | 
| 126 94 | 
             
            description: A fairly basic FTP client daemon, driven by RESTful webservice calls
         | 
| 127 95 | 
             
            email: rest-ftp-daemon@bmconseil.com
         | 
| 128 96 | 
             
            executables:
         | 
| @@ -140,9 +108,10 @@ files: | |
| 140 108 | 
             
            - VERSION
         | 
| 141 109 | 
             
            - bin/rest-ftp-daemon
         | 
| 142 110 | 
             
            - lib/config.rb
         | 
| 111 | 
            +
            - lib/config.ru
         | 
| 143 112 | 
             
            - lib/errors.rb
         | 
| 144 113 | 
             
            - lib/rest-ftp-daemon.rb
         | 
| 145 | 
            -
            -  | 
| 114 | 
            +
            - rest-ftp-daemon.gemspec
         | 
| 146 115 | 
             
            - test/helper.rb
         | 
| 147 116 | 
             
            - test/test_rest-ftp-daemon.rb
         | 
| 148 117 | 
             
            homepage: http://github.com/bmedici/rest-ftp-daemon
         | 
| @@ -160,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 160 129 | 
             
                  version: '0'
         | 
| 161 130 | 
             
                  segments:
         | 
| 162 131 | 
             
                  - 0
         | 
| 163 | 
            -
                  hash:  | 
| 132 | 
            +
                  hash: 613480688316128454
         | 
| 164 133 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 165 134 | 
             
              none: false
         | 
| 166 135 | 
             
              requirements:
         |