trans-api 0.0.2 → 0.0.4
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.
- checksums.yaml +4 -12
- data/.gitignore +1 -0
- data/Gemfile.lock +11 -8
- data/LICENSE.txt +1 -1
- data/README.md +72 -13
- data/lib/trans-api.rb +8 -1
- data/lib/trans-api/connect.rb +3 -0
- data/lib/trans-api/file.rb +64 -52
- data/lib/trans-api/session.rb +53 -21
- data/lib/trans-api/torrent.rb +14 -3
- data/lib/trans-api/version.rb +1 -1
- data/test/unit/trans_connect.rb +24 -22
- data/test/unit/trans_session_object.rb +59 -2
- data/test/unit/trans_torrent_object.rb +20 -3
- data/trans-api.gemspec +6 -6
- metadata +32 -36
- data/examples/basic_setup.rb +0 -78
- data/examples/torrents/debian-6.0.6-amd64-CD-10.iso.torrent +0 -0
- data/test/test_helper.rb +0 -8
    
        checksums.yaml
    CHANGED
    
    | @@ -1,15 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
             | 
| 5 | 
            -
              data.tar.gz: !binary |-
         | 
| 6 | 
            -
                NDZhNjBkNTZjYmYyMjM4NDU5NzJmMDBmZWQzMzMwMjYwNTNmYjExYg==
         | 
| 3 | 
            +
              metadata.gz: 4750d6488dcb9805c0bbd635509b4cc2b82f664e
         | 
| 4 | 
            +
              data.tar.gz: 112eebe82c5696c795c38d311047cb6bc154d396
         | 
| 7 5 | 
             
            SHA512:
         | 
| 8 | 
            -
              metadata.gz:  | 
| 9 | 
            -
             | 
| 10 | 
            -
                YTdjYTEwMTg5NGU2NjZkZDJjNTE4NjdkN2EzZmRiMTAzODljZTM3ZjZlNDlm
         | 
| 11 | 
            -
                YjY3ZTRlMTgzNjlhOWNkOThmMTViMzdhZGU2ZTY3ZmQ5YjMyZDc=
         | 
| 12 | 
            -
              data.tar.gz: !binary |-
         | 
| 13 | 
            -
                NDY5MjgyOGZmODQ1N2ZiYWNhMmMyMjUwMzg3MTMxYWU3OTRjNTJlMzYzMTUy
         | 
| 14 | 
            -
                ZWZiYjI0NmZjYjZjMDljNDgzNDVkZmZlYWQ1N2FlZmEzMmY3NzNkMWNmNGJm
         | 
| 15 | 
            -
                YjNiYTFiMjQ0N2UyNzhkYTVhNDNlM2VjNWYzODM1Nzc0YTU3Zjk=
         | 
| 6 | 
            +
              metadata.gz: 2d6928aee4bdebfe1272677a7b88dbe56df591922aeaf38d175d5c109fbd8b149a7519259d8322e202223319601a61a0d82d73084becf8126019b45af12acea5
         | 
| 7 | 
            +
              data.tar.gz: 6baef1393173ee402a8487bf7656702c399d39f0b490047ad306a4807546c28561ef23810ab49bd90316ffbe6bafb3132cd12eac69b787d6766ec3ade5b00a21
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,17 +1,20 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                trans-api (0.0. | 
| 5 | 
            -
                  json
         | 
| 6 | 
            -
                  nokogiri
         | 
| 4 | 
            +
                trans-api (0.0.3)
         | 
| 5 | 
            +
                  json (> 1.6.1)
         | 
| 6 | 
            +
                  nokogiri (> 1.5.0)
         | 
| 7 7 |  | 
| 8 8 | 
             
            GEM
         | 
| 9 9 | 
             
              remote: https://rubygems.org/
         | 
| 10 10 | 
             
              specs:
         | 
| 11 | 
            -
                json (1. | 
| 12 | 
            -
                json (1. | 
| 13 | 
            -
                 | 
| 14 | 
            -
                nokogiri (1. | 
| 11 | 
            +
                json (1.8.1)
         | 
| 12 | 
            +
                json (1.8.1-java)
         | 
| 13 | 
            +
                mini_portile (0.5.2)
         | 
| 14 | 
            +
                nokogiri (1.6.1)
         | 
| 15 | 
            +
                  mini_portile (~> 0.5.0)
         | 
| 16 | 
            +
                nokogiri (1.6.1-java)
         | 
| 17 | 
            +
                  mini_portile (~> 0.5.0)
         | 
| 15 18 | 
             
                test-unit (2.5.2)
         | 
| 16 19 |  | 
| 17 20 | 
             
            PLATFORMS
         | 
| @@ -19,5 +22,5 @@ PLATFORMS | |
| 19 22 | 
             
              ruby
         | 
| 20 23 |  | 
| 21 24 | 
             
            DEPENDENCIES
         | 
| 22 | 
            -
              test-unit
         | 
| 25 | 
            +
              test-unit (> 2.0.0)
         | 
| 23 26 | 
             
              trans-api!
         | 
    
        data/LICENSE.txt
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            # Trans::Api
         | 
| 2 2 |  | 
| 3 | 
            -
            Trans::Api is an ruby implementation for Transmission RPC. Based on RPC spec 13328
         | 
| 3 | 
            +
            Trans::Api is an ruby implementation for Transmission RPC (bittorrent client). Based on RPC spec 13328
         | 
| 4 4 | 
             
            https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt
         | 
| 5 5 |  | 
| 6 6 | 
             
            It required for the Transmission RPC to run the 'remote access':
         | 
| @@ -10,22 +10,22 @@ OSX: | |
| 10 10 | 
             
              Transmission > Preferences > Remote (tab) > Enable remote access
         | 
| 11 11 |  | 
| 12 12 |  | 
| 13 | 
            -
            ### Platforms
         | 
| 13 | 
            +
            ### Platforms (tested)
         | 
| 14 14 |  | 
| 15 15 | 
             
            This gem is (build and) tested with:
         | 
| 16 16 |  | 
| 17 | 
            -
              OSX Lion, Mountain Lion
         | 
| 17 | 
            +
              OSX Lion, Mountain Lion, Mavericks
         | 
| 18 18 |  | 
| 19 | 
            -
              Ruby 1.9.3
         | 
| 19 | 
            +
              Ruby 1.9.3, 2.1.0
         | 
| 20 20 |  | 
| 21 | 
            -
              Rails: 3.2.8, 3.2.9
         | 
| 21 | 
            +
              Rails: 3.2.8, 3.2.9, 4.0.3
         | 
| 22 22 |  | 
| 23 | 
            -
              Transmission 2.73 (13589)
         | 
| 23 | 
            +
              Transmission 2.73 (13589) - 2.82 (14160)
         | 
| 24 24 |  | 
| 25 25 |  | 
| 26 26 | 
             
            ### Roadmap
         | 
| 27 27 |  | 
| 28 | 
            -
            * Version (0.0.1) | 
| 28 | 
            +
            * Version (0.0.1)
         | 
| 29 29 |  | 
| 30 30 | 
             
              Initial project import.
         | 
| 31 31 |  | 
| @@ -39,26 +39,48 @@ This gem is (build and) tested with: | |
| 39 39 |  | 
| 40 40 | 
             
              Torrent object 'waitfor' helper to check for lambda after/before calling it's chained cousin
         | 
| 41 41 |  | 
| 42 | 
            +
            * Version (0.0.3)
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              Querying name before add (duplicate detect), not hammering torrent-add (due to a transmission BUG)
         | 
| 45 | 
            +
             | 
| 46 | 
            +
              Added some File internal fields (total and completed transfer)
         | 
| 47 | 
            +
             | 
| 48 | 
            +
            * Version (0.0.4)
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              Added Session.alt_speed_time_day_options, returns a list of values to set `alt_speed_time_day`
         | 
| 51 | 
            +
             | 
| 52 | 
            +
              Added Session.reload!, that reconnects to the client (for example using alternate configs)
         | 
| 53 | 
            +
             | 
| 54 | 
            +
              Added Session.update_blocklist!, updating the current set blocklist
         | 
| 55 | 
            +
             | 
| 56 | 
            +
             | 
| 57 | 
            +
            ### Changelog
         | 
| 58 | 
            +
             | 
| 59 | 
            +
            * Version (0.0.3)
         | 
| 60 | 
            +
              
         | 
| 61 | 
            +
              Torrent.add_metainfo(base64, filename, options={}) -> requires a filename parameter
         | 
| 62 | 
            +
             | 
| 63 | 
            +
            * Version (0.0.4)
         | 
| 64 | 
            +
             | 
| 65 | 
            +
              TBA
         | 
| 42 66 |  | 
| 43 67 | 
             
            ### Known Issues
         | 
| 44 68 |  | 
| 45 69 | 
             
            The Transmission RPC call 'torrent-remove' (implemented as torrent.delete! and Torrent::delete_all!) will crash the daemon! This is NOT a known Transmission issue.
         | 
| 46 70 |  | 
| 71 | 
            +
            Due to a Transmission bug (https://trac.transmissionbt.com/ticket/5614) duplicate torrents are accepted by the RPC call. The GUI will eventually crash the daemon, when interacting with these duplicate files (or instances). Torrent.add_file/ add_metainfo queries for duplicates to omit this bug.
         | 
| 72 | 
            +
             | 
| 47 73 |  | 
| 48 74 | 
             
            ## Installation
         | 
| 49 75 |  | 
| 50 76 | 
             
            Add this line to your application's Gemfile:
         | 
| 51 77 |  | 
| 52 | 
            -
                gem 'trans-api',  | 
| 78 | 
            +
                gem 'trans-api', github: "dblommesteijn/trans-api"
         | 
| 53 79 |  | 
| 54 80 | 
             
            And then execute:
         | 
| 55 81 |  | 
| 56 82 | 
             
                $ bundle
         | 
| 57 83 |  | 
| 58 | 
            -
            Or install it yourself as:
         | 
| 59 | 
            -
             | 
| 60 | 
            -
                $ gem install trans-api
         | 
| 61 | 
            -
             | 
| 62 84 |  | 
| 63 85 | 
             
            ## Setup
         | 
| 64 86 |  | 
| @@ -157,8 +179,19 @@ Trans::Api::Torrent.delete_all torrents | |
| 157 179 | 
             
            Add torrent file
         | 
| 158 180 |  | 
| 159 181 | 
             
            ```ruby
         | 
| 182 | 
            +
            file = File.open('some file here')
         | 
| 160 183 | 
             
            options = {paused: true}
         | 
| 161 | 
            -
            Trans::Api::Torrent.add_file  | 
| 184 | 
            +
            Trans::Api::Torrent.add_file file, options
         | 
| 185 | 
            +
            ```
         | 
| 186 | 
            +
             | 
| 187 | 
            +
            Add torrent file (via base64)
         | 
| 188 | 
            +
             | 
| 189 | 
            +
            ```ruby
         | 
| 190 | 
            +
            file = File.open('some file here')
         | 
| 191 | 
            +
            file_name = File.basename(file, ".*") # required >= 0.0.3/ master
         | 
| 192 | 
            +
            options = {paused: true}
         | 
| 193 | 
            +
            base64_file_contents = Base64.encode64 file.read
         | 
| 194 | 
            +
            Trans::Api::Torrent.add_metainfo base64_file_contents, file_name, options
         | 
| 162 195 | 
             
            ```
         | 
| 163 196 |  | 
| 164 197 | 
             
            Get all fields
         | 
| @@ -284,6 +317,29 @@ Reset (reload object, request information and not saving changes) | |
| 284 317 | 
             
            session.reset!
         | 
| 285 318 | 
             
            ```
         | 
| 286 319 |  | 
| 320 | 
            +
            Reload (reload the client connection, and configuration)
         | 
| 321 | 
            +
             | 
| 322 | 
            +
            ```ruby
         | 
| 323 | 
            +
            session.reload!
         | 
| 324 | 
            +
            ```
         | 
| 325 | 
            +
             | 
| 326 | 
            +
            Enable set and update blocklist
         | 
| 327 | 
            +
             | 
| 328 | 
            +
            ```ruby
         | 
| 329 | 
            +
            # set an url
         | 
| 330 | 
            +
            session.blocklist_url = "http://list.iblocklist.com/?list=bt_level3&fileformat=p2p&archiveformat=gz"
         | 
| 331 | 
            +
            # enable blocklist
         | 
| 332 | 
            +
            session.blocklist_enable = true
         | 
| 333 | 
            +
            # save changes
         | 
| 334 | 
            +
            session.save!
         | 
| 335 | 
            +
            # force update 
         | 
| 336 | 
            +
            begin
         | 
| 337 | 
            +
              session.update_blocklist!
         | 
| 338 | 
            +
            rescue Exception => e
         | 
| 339 | 
            +
              # handle http exceptions here!
         | 
| 340 | 
            +
            end
         | 
| 341 | 
            +
            ```
         | 
| 342 | 
            +
             | 
| 287 343 | 
             
            NOTE: defined session fields are defined as instance methods to the Session object
         | 
| 288 344 |  | 
| 289 345 |  | 
| @@ -332,3 +388,6 @@ file.stat | |
| 332 388 |  | 
| 333 389 | 
             
            NOTE: changed preferences (want, unwant) set options on the linked Torrent object, after saving torrent (torrent.save!) file mutations are stored.
         | 
| 334 390 |  | 
| 391 | 
            +
             | 
| 392 | 
            +
             | 
| 393 | 
            +
             | 
    
        data/lib/trans-api.rb
    CHANGED
    
    | @@ -5,8 +5,15 @@ require File.expand_path(File.dirname(__FILE__) + "/trans-api/session") | |
| 5 5 | 
             
            require File.expand_path(File.dirname(__FILE__) + "/trans-api/torrent")
         | 
| 6 6 | 
             
            require File.expand_path(File.dirname(__FILE__) + "/trans-api/file")
         | 
| 7 7 |  | 
| 8 | 
            +
            # boolean helper
         | 
| 9 | 
            +
            if Boolean.nil?
         | 
| 10 | 
            +
              module Boolean; end
         | 
| 11 | 
            +
              class TrueClass; include Boolean; end
         | 
| 12 | 
            +
              class FalseClass; include Boolean; end
         | 
| 13 | 
            +
            end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            # trans api placeholder
         | 
| 8 16 | 
             
            module Trans
         | 
| 9 17 | 
             
              module Api
         | 
| 10 | 
            -
                # placeholder
         | 
| 11 18 | 
             
              end
         | 
| 12 19 | 
             
            end
         | 
    
        data/lib/trans-api/connect.rb
    CHANGED
    
    | @@ -152,8 +152,11 @@ module Trans | |
| 152 152 | 
             
                    data = METHODS[:torrent_add]
         | 
| 153 153 | 
             
                    data[:arguments] = argument_name_to_api arguments
         | 
| 154 154 | 
             
                    ret = self.do(:post, data)
         | 
| 155 | 
            +
                    # puts JSON.parse(ret[:response].body).inspect
         | 
| 155 156 | 
             
                    torrents = JSON.parse ret[:response].body.gsub("-","_"), {symbolize_names: true}
         | 
| 156 157 | 
             
                    raise torrents[:result] unless valid? torrents, data[:tag]
         | 
| 158 | 
            +
                    # omiting BUG: https://trac.transmissionbt.com/ticket/5614
         | 
| 159 | 
            +
                    return torrents[:arguments][:torrent_duplicate] if torrents[:arguments].include?(:torrent_duplicate)
         | 
| 157 160 | 
             
                    torrents[:arguments][:torrent_added]
         | 
| 158 161 | 
             
                  end
         | 
| 159 162 |  | 
    
        data/lib/trans-api/file.rb
    CHANGED
    
    | @@ -1,56 +1,68 @@ | |
| 1 1 |  | 
| 2 2 |  | 
| 3 3 | 
             
            module Trans
         | 
| 4 | 
            -
             | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
            # | 
| 17 | 
            -
            # | 
| 18 | 
            -
            # | 
| 19 | 
            -
            # | 
| 20 | 
            -
            # | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 4 | 
            +
              module Api
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                class File
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def initialize(options={})
         | 
| 9 | 
            +
                    @torrent = options.delete :torrent
         | 
| 10 | 
            +
                    @torrent_fields = options.delete :fields
         | 
| 11 | 
            +
                    @fields = options[:file]
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                    # set default stats
         | 
| 14 | 
            +
                    @torrent_fields[:files_unwanted] ||= []
         | 
| 15 | 
            +
                    @torrent_fields[:files_wanted] ||= []
         | 
| 16 | 
            +
            #       if @fields[:fileStat][:wanted] == false
         | 
| 17 | 
            +
            #         @torrent_fields[:files_unwanted] << self.id
         | 
| 18 | 
            +
            #       else
         | 
| 19 | 
            +
            #         @torrent_fields[:files_wanted] << self.id
         | 
| 20 | 
            +
            #       end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                    @client = Client.new
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  def id
         | 
| 26 | 
            +
                    @fields[:id]
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  def name
         | 
| 30 | 
            +
                    @fields[:name]
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  def stat
         | 
| 34 | 
            +
                    @fields[:fileStat]
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  def bytes_completed
         | 
| 38 | 
            +
                    @fields[:bytesCompleted]
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  def bytes_total
         | 
| 42 | 
            +
                    @fields[:length]
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                  def priority
         | 
| 46 | 
            +
                    @fields[:fileStat][:priority]
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  def unwant
         | 
| 50 | 
            +
                    @torrent_fields[:files_wanted].delete self.id if @torrent_fields[:files_wanted].include? self.id
         | 
| 51 | 
            +
                    @torrent_fields[:files_unwanted] << self.id unless @torrent_fields[:files_unwanted].include? self.id
         | 
| 52 | 
            +
                    @fields[:fileStat][:wanted] = false
         | 
| 53 | 
            +
                  end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                  def want
         | 
| 56 | 
            +
                    @torrent_fields[:files_wanted] << self.id unless @torrent_fields[:files_wanted].include? self.id
         | 
| 57 | 
            +
                    @torrent_fields[:files_unwanted].delete self.id if @torrent_fields[:files_unwanted].include? self.id
         | 
| 58 | 
            +
                    @fields[:fileStat][:wanted] = true
         | 
| 59 | 
            +
                  end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                  def wanted?
         | 
| 62 | 
            +
                    @fields[:fileStat][:wanted]
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
              end
         | 
| 56 68 | 
             
            end
         | 
    
        data/lib/trans-api/session.rb
    CHANGED
    
    | @@ -16,27 +16,7 @@ module Trans | |
| 16 16 |  | 
| 17 17 |  | 
| 18 18 | 
             
                  def initialize
         | 
| 19 | 
            -
                     | 
| 20 | 
            -
                    self.reset!
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                    # map fields to accessors
         | 
| 23 | 
            -
                    @fields.each do |k, v|
         | 
| 24 | 
            -
                      # setter
         | 
| 25 | 
            -
                      self.metaclass.send(:define_method, "#{k}=") do |value|
         | 
| 26 | 
            -
                        if v.class == value.class
         | 
| 27 | 
            -
                          @fields[k] = value
         | 
| 28 | 
            -
                        else
         | 
| 29 | 
            -
                          msg = "invalid type: #{value.class}, expected: #{v.class}"
         | 
| 30 | 
            -
                          @last_error[:message] = msg
         | 
| 31 | 
            -
                          raise msg
         | 
| 32 | 
            -
                        end
         | 
| 33 | 
            -
                      end
         | 
| 34 | 
            -
                      # getter
         | 
| 35 | 
            -
                      self.metaclass.send(:define_method, "#{k}") do
         | 
| 36 | 
            -
                        @fields[k]
         | 
| 37 | 
            -
                      end
         | 
| 38 | 
            -
                    end
         | 
| 39 | 
            -
             | 
| 19 | 
            +
                    self.reload!
         | 
| 40 20 | 
             
                  end
         | 
| 41 21 |  | 
| 42 22 | 
             
                  def fields
         | 
| @@ -71,12 +51,64 @@ module Trans | |
| 71 51 | 
             
                    @fields = @client.connect.session_get
         | 
| 72 52 | 
             
                    @old_fields = @fields.clone
         | 
| 73 53 | 
             
                    @last_error = {error: "", message: ""}
         | 
| 54 | 
            +
                    nil
         | 
| 55 | 
            +
                  end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                  def reload!
         | 
| 58 | 
            +
                    @client = Client.new
         | 
| 59 | 
            +
                    self.reset!
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                    # map fields to accessors
         | 
| 62 | 
            +
                    @fields.each do |k, v|
         | 
| 63 | 
            +
                      # setter
         | 
| 64 | 
            +
                      self.metaclass.send(:define_method, "#{k}=") do |value|
         | 
| 65 | 
            +
                        if v.class == value.class || value.is_a?(::Boolean)
         | 
| 66 | 
            +
                          @fields[k] = value
         | 
| 67 | 
            +
                        else
         | 
| 68 | 
            +
                          msg = "invalid type: #{value.class}, expected: #{v.class}"
         | 
| 69 | 
            +
                          @last_error[:message] = msg
         | 
| 70 | 
            +
                          raise msg
         | 
| 71 | 
            +
                        end
         | 
| 72 | 
            +
                      end
         | 
| 73 | 
            +
                      # getter
         | 
| 74 | 
            +
                      self.metaclass.send(:define_method, "#{k}") do
         | 
| 75 | 
            +
                        @fields[k]
         | 
| 76 | 
            +
                      end
         | 
| 77 | 
            +
                    end
         | 
| 74 78 | 
             
                  end
         | 
| 75 79 |  | 
| 80 | 
            +
                  def update_blocklist!
         | 
| 81 | 
            +
                    @client.connect.blocklist_update
         | 
| 82 | 
            +
                  end
         | 
| 83 | 
            +
             | 
| 84 | 
            +
             | 
| 85 | 
            +
                  # blocklist-update
         | 
| 86 | 
            +
             | 
| 76 87 |  | 
| 77 88 | 
             
                  def metaclass
         | 
| 78 89 | 
             
                    class << self; self; end
         | 
| 79 90 | 
             
                  end
         | 
| 91 | 
            +
             | 
| 92 | 
            +
                  class << self
         | 
| 93 | 
            +
                    def alt_speed_time_day_options
         | 
| 94 | 
            +
                      ret = []
         | 
| 95 | 
            +
                      ret << ["Sunday", 1]
         | 
| 96 | 
            +
                      ret << ["Monday", 2]
         | 
| 97 | 
            +
                      ret << ["Tuesday", 4]
         | 
| 98 | 
            +
                      ret << ["Wednesday", 8]
         | 
| 99 | 
            +
                      ret << ["Thursday", 16]
         | 
| 100 | 
            +
                      ret << ["Friday", 32]
         | 
| 101 | 
            +
                      ret << ["Weekdays", 62]
         | 
| 102 | 
            +
                      ret << ["Saturday", 64]
         | 
| 103 | 
            +
                      ret << ["Weekends", 65]
         | 
| 104 | 
            +
                      ret << ["Every Day", 127]
         | 
| 105 | 
            +
                      ret.sort{|a,b| a.last <=> b.last}
         | 
| 106 | 
            +
                    end
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                    def encryption_levels
         | 
| 109 | 
            +
                      ["required", "preferred", "tolerated"].map{|t| [t.humanize, t]}
         | 
| 110 | 
            +
                    end
         | 
| 111 | 
            +
                  end
         | 
| 80 112 | 
             
                end
         | 
| 81 113 |  | 
| 82 114 | 
             
              end
         | 
    
        data/lib/trans-api/torrent.rb
    CHANGED
    
    | @@ -1,6 +1,8 @@ | |
| 1 1 | 
             
            module Trans
         | 
| 2 2 | 
             
              module Api
         | 
| 3 3 |  | 
| 4 | 
            +
                require 'pathname'
         | 
| 5 | 
            +
             | 
| 4 6 | 
             
                #
         | 
| 5 7 | 
             
                # Torrent class
         | 
| 6 8 | 
             
                #
         | 
| @@ -86,8 +88,10 @@ module Trans | |
| 86 88 | 
             
                    torrent = @client.connect.torrent_get([:files, :fileStats], [self.id]).first
         | 
| 87 89 | 
             
                    @fields[:files] = torrent[:files]
         | 
| 88 90 | 
             
                    @fields[:fileStatus] = torrent[:fileStats]
         | 
| 89 | 
            -
                    @fields[:files].each_with_index | 
| 90 | 
            -
                       | 
| 91 | 
            +
                    @fields[:files].each_with_index do |f,i| 
         | 
| 92 | 
            +
                      ret << Trans::Api::File.new( torrent: self, fields: @fields,
         | 
| 93 | 
            +
                        file: f.merge(id: i).merge(fileStat: torrent[:fileStats][i]))
         | 
| 94 | 
            +
                    end
         | 
| 91 95 | 
             
                    ret
         | 
| 92 96 | 
             
                  end
         | 
| 93 97 |  | 
| @@ -199,6 +203,9 @@ module Trans | |
| 199 203 |  | 
| 200 204 | 
             
                    def add_file(filename, options={})
         | 
| 201 205 | 
             
                      raise "file not found: #{filename}" unless ::File.exists? filename
         | 
| 206 | 
            +
                      # filter duplicates
         | 
| 207 | 
            +
                      find = Trans::Api::Torrent.find_by_field_value(:name, ::File.basename(filename, ".*"))
         | 
| 208 | 
            +
                      return find unless find.nil?
         | 
| 202 209 | 
             
                      client = Client.new
         | 
| 203 210 | 
             
                      options[:filename] = filename
         | 
| 204 211 | 
             
                      torrent = client.connect.torrent_add options
         | 
| @@ -206,8 +213,12 @@ module Trans | |
| 206 213 | 
             
                      Torrent.new torrent: torrent
         | 
| 207 214 | 
             
                    end
         | 
| 208 215 |  | 
| 209 | 
            -
                    def add_metainfo(metainfo, options={})
         | 
| 216 | 
            +
                    def add_metainfo(metainfo, name, options={})
         | 
| 217 | 
            +
                      raise "name empty" if name.nil? || name == ""
         | 
| 210 218 | 
             
                      options[:metainfo] = metainfo
         | 
| 219 | 
            +
                      # filter duplicates
         | 
| 220 | 
            +
                      find = Trans::Api::Torrent.find_by_field_value(:name, name)
         | 
| 221 | 
            +
                      return find unless find.nil?
         | 
| 211 222 | 
             
                      client = Client.new
         | 
| 212 223 | 
             
                      torrent = client.connect.torrent_add options
         | 
| 213 224 | 
             
                      torrent = client.connect.torrent_get( @@default_fields, [torrent[:id]]).first
         | 
    
        data/lib/trans-api/version.rb
    CHANGED
    
    
    
        data/test/unit/trans_connect.rb
    CHANGED
    
    | @@ -2,7 +2,8 @@ require 'rubygems' | |
| 2 2 | 
             
            require 'test/unit'
         | 
| 3 3 | 
             
            require File.expand_path(File.dirname(__FILE__) + "/../../lib/trans-api")
         | 
| 4 4 |  | 
| 5 | 
            -
             | 
| 5 | 
            +
            # run with config options
         | 
| 6 | 
            +
            #CONFIG="{\"host\":\"localhost\",\"port\":9091,\"user\":\"admin\",\"pass\":\"admin\",\"path\":\"/transmission/rpc\"}" ruby -I test test/unit/trans_connect.rb
         | 
| 6 7 |  | 
| 7 8 | 
             
            #
         | 
| 8 9 | 
             
            # Unit test for Transmission RPC+json
         | 
| @@ -12,10 +13,11 @@ require File.expand_path(File.dirname(__FILE__) + "/../../lib/trans-api") | |
| 12 13 |  | 
| 13 14 | 
             
            class TransConnect < Test::Unit::TestCase
         | 
| 14 15 |  | 
| 15 | 
            -
              CONFIG = { host: "localhost", port: 9091, user: "admin", pass: "admin", path: "/transmission/rpc" }
         | 
| 16 | 
            -
             | 
| 17 16 | 
             
              def setup
         | 
| 18 | 
            -
                 | 
| 17 | 
            +
                @CONFIG = { host: "localhost", port: 9091, user: "admin", pass: "admin", path: "/transmission/rpc" }
         | 
| 18 | 
            +
                @CONFIG = JSON.parse(ENV["CONFIG"], symbolize_names: true) if ENV.include? "CONFIG"
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                Trans::Api::Client.config = @CONFIG
         | 
| 19 21 |  | 
| 20 22 | 
             
                # add a testing torrent
         | 
| 21 23 | 
             
                file = File.expand_path(File.dirname(__FILE__) + "/torrents/debian-6.0.6-amd64-CD-1.iso.torrent")
         | 
| @@ -24,7 +26,7 @@ class TransConnect < Test::Unit::TestCase | |
| 24 26 | 
             
              end
         | 
| 25 27 |  | 
| 26 28 | 
             
              def teardown
         | 
| 27 | 
            -
                Trans::Api::Client.config = CONFIG
         | 
| 29 | 
            +
                Trans::Api::Client.config = @CONFIG
         | 
| 28 30 |  | 
| 29 31 | 
             
                # remove the testing torrent
         | 
| 30 32 | 
             
                id = @torrent.id
         | 
| @@ -39,19 +41,19 @@ class TransConnect < Test::Unit::TestCase | |
| 39 41 | 
             
              # SESSIONS
         | 
| 40 42 |  | 
| 41 43 | 
             
              def test_session_get
         | 
| 42 | 
            -
                tc = Trans::Api::Connect.new CONFIG
         | 
| 44 | 
            +
                tc = Trans::Api::Connect.new @CONFIG
         | 
| 43 45 | 
             
                session = tc.session_get
         | 
| 44 46 | 
             
                assert session.size > 0, "no arguments found"
         | 
| 45 47 | 
             
              end
         | 
| 46 48 |  | 
| 47 49 | 
             
              def test_session_stats
         | 
| 48 | 
            -
                tc = Trans::Api::Connect.new CONFIG
         | 
| 50 | 
            +
                tc = Trans::Api::Connect.new @CONFIG
         | 
| 49 51 | 
             
                session = tc.session_stats
         | 
| 50 52 | 
             
                assert session.size > 0, "no arguments found"
         | 
| 51 53 | 
             
              end
         | 
| 52 54 |  | 
| 53 55 | 
             
              def test_session_set
         | 
| 54 | 
            -
                tc = Trans::Api::Connect.new CONFIG
         | 
| 56 | 
            +
                tc = Trans::Api::Connect.new @CONFIG
         | 
| 55 57 |  | 
| 56 58 | 
             
                # get session
         | 
| 57 59 | 
             
                session_get = tc.session_get
         | 
| @@ -91,7 +93,7 @@ class TransConnect < Test::Unit::TestCase | |
| 91 93 | 
             
              end
         | 
| 92 94 |  | 
| 93 95 | 
             
              def test_session_close
         | 
| 94 | 
            -
                tc = Trans::Api::Connect.new CONFIG
         | 
| 96 | 
            +
                tc = Trans::Api::Connect.new @CONFIG
         | 
| 95 97 | 
             
                session_get = tc.session_get
         | 
| 96 98 | 
             
                #NOTE: will shut the daemon down!!
         | 
| 97 99 | 
             
                #    session_close = tc.session_close
         | 
| @@ -101,7 +103,7 @@ class TransConnect < Test::Unit::TestCase | |
| 101 103 | 
             
              # TORRENTS
         | 
| 102 104 |  | 
| 103 105 | 
             
              def test_torrent_get
         | 
| 104 | 
            -
                tc = Trans::Api::Connect.new CONFIG
         | 
| 106 | 
            +
                tc = Trans::Api::Connect.new @CONFIG
         | 
| 105 107 |  | 
| 106 108 | 
             
                # receive torrent list
         | 
| 107 109 | 
             
                torrents = tc.torrent_get([:id, :name, :status])
         | 
| @@ -126,7 +128,7 @@ class TransConnect < Test::Unit::TestCase | |
| 126 128 | 
             
              end
         | 
| 127 129 |  | 
| 128 130 | 
             
              def test_torrent_set
         | 
| 129 | 
            -
                tc = Trans::Api::Connect.new CONFIG
         | 
| 131 | 
            +
                tc = Trans::Api::Connect.new @CONFIG
         | 
| 130 132 |  | 
| 131 133 | 
             
                # get torrent list
         | 
| 132 134 | 
             
                torrents = tc.torrent_get([:id, :name, :bandwidthPriority])
         | 
| @@ -156,7 +158,7 @@ class TransConnect < Test::Unit::TestCase | |
| 156 158 |  | 
| 157 159 |  | 
| 158 160 | 
             
              def test_torrent_start_stop_single
         | 
| 159 | 
            -
                tc = Trans::Api::Connect.new CONFIG
         | 
| 161 | 
            +
                tc = Trans::Api::Connect.new @CONFIG
         | 
| 160 162 |  | 
| 161 163 | 
             
                torrents = tc.torrent_get([:id, :name, :status])
         | 
| 162 164 |  | 
| @@ -202,7 +204,7 @@ class TransConnect < Test::Unit::TestCase | |
| 202 204 | 
             
              end
         | 
| 203 205 |  | 
| 204 206 | 
             
              def test_torrent_start_stop_multi
         | 
| 205 | 
            -
                tc = Trans::Api::Connect.new CONFIG
         | 
| 207 | 
            +
                tc = Trans::Api::Connect.new @CONFIG
         | 
| 206 208 | 
             
                torrents = tc.torrent_get([:id, :name, :status])
         | 
| 207 209 |  | 
| 208 210 |  | 
| @@ -241,7 +243,7 @@ class TransConnect < Test::Unit::TestCase | |
| 241 243 | 
             
              end
         | 
| 242 244 |  | 
| 243 245 | 
             
              def test_torrent_add_remove_single
         | 
| 244 | 
            -
                tc = Trans::Api::Connect.new CONFIG
         | 
| 246 | 
            +
                tc = Trans::Api::Connect.new @CONFIG
         | 
| 245 247 |  | 
| 246 248 | 
             
                # add test file
         | 
| 247 249 | 
             
                file = File.expand_path(File.dirname(__FILE__) + "/torrents/debian-6.0.6-amd64-CD-2.iso.torrent")
         | 
| @@ -266,7 +268,7 @@ class TransConnect < Test::Unit::TestCase | |
| 266 268 |  | 
| 267 269 |  | 
| 268 270 | 
             
              def test_torrent_files_unwatched
         | 
| 269 | 
            -
                tc = Trans::Api::Connect.new CONFIG
         | 
| 271 | 
            +
                tc = Trans::Api::Connect.new @CONFIG
         | 
| 270 272 | 
             
                torrents = tc.torrent_get([:id, :name, :status, :files, :fileStats])
         | 
| 271 273 |  | 
| 272 274 | 
             
                torrents.each do |torrent|
         | 
| @@ -278,7 +280,7 @@ class TransConnect < Test::Unit::TestCase | |
| 278 280 |  | 
| 279 281 |  | 
| 280 282 | 
             
              def test_torrent_start_now
         | 
| 281 | 
            -
                tc = Trans::Api::Connect.new CONFIG
         | 
| 283 | 
            +
                tc = Trans::Api::Connect.new @CONFIG
         | 
| 282 284 | 
             
                # get first torrent
         | 
| 283 285 | 
             
                torrent = tc.torrent_get([:id, :name, :status]).first
         | 
| 284 286 | 
             
                # start now
         | 
| @@ -290,7 +292,7 @@ class TransConnect < Test::Unit::TestCase | |
| 290 292 | 
             
              end
         | 
| 291 293 |  | 
| 292 294 | 
             
              def test_torrent_verify
         | 
| 293 | 
            -
                tc = Trans::Api::Connect.new CONFIG
         | 
| 295 | 
            +
                tc = Trans::Api::Connect.new @CONFIG
         | 
| 294 296 | 
             
                torrents = tc.torrent_get([:id, :name, :status])
         | 
| 295 297 |  | 
| 296 298 | 
             
                torrents.each do |torrent|
         | 
| @@ -302,7 +304,7 @@ class TransConnect < Test::Unit::TestCase | |
| 302 304 | 
             
              end
         | 
| 303 305 |  | 
| 304 306 | 
             
              def test_torrent_reannounce
         | 
| 305 | 
            -
                tc = Trans::Api::Connect.new CONFIG
         | 
| 307 | 
            +
                tc = Trans::Api::Connect.new @CONFIG
         | 
| 306 308 | 
             
                torrents = tc.torrent_get([:id, :name, :status])
         | 
| 307 309 |  | 
| 308 310 | 
             
                torrents.each do |torrent|
         | 
| @@ -314,7 +316,7 @@ class TransConnect < Test::Unit::TestCase | |
| 314 316 |  | 
| 315 317 |  | 
| 316 318 | 
             
              def test_torrent_set_location
         | 
| 317 | 
            -
                tc = Trans::Api::Connect.new CONFIG
         | 
| 319 | 
            +
                tc = Trans::Api::Connect.new @CONFIG
         | 
| 318 320 |  | 
| 319 321 | 
             
                # new target
         | 
| 320 322 | 
             
                file = File.expand_path(File.dirname(__FILE__) + "/torrents/download_tmp/")
         | 
| @@ -341,14 +343,14 @@ class TransConnect < Test::Unit::TestCase | |
| 341 343 | 
             
              # MISC
         | 
| 342 344 |  | 
| 343 345 | 
             
              def test_blocklist_update
         | 
| 344 | 
            -
                tc = Trans::Api::Connect.new CONFIG
         | 
| 346 | 
            +
                tc = Trans::Api::Connect.new @CONFIG
         | 
| 345 347 | 
             
                response = tc.blocklist_update
         | 
| 346 348 | 
             
                assert response.include? :blocklist_size
         | 
| 347 349 | 
             
                assert response[:blocklist_size].class == Fixnum
         | 
| 348 350 | 
             
              end
         | 
| 349 351 |  | 
| 350 352 | 
             
              def test_port_test
         | 
| 351 | 
            -
                tc = Trans::Api::Connect.new CONFIG
         | 
| 353 | 
            +
                tc = Trans::Api::Connect.new @CONFIG
         | 
| 352 354 | 
             
                response = tc.port_test
         | 
| 353 355 | 
             
                assert response.include? :port_is_open
         | 
| 354 356 | 
             
                assert response[:port_is_open].class == FalseClass || response[:port_is_open].class == TrueClass
         | 
| @@ -358,7 +360,7 @@ class TransConnect < Test::Unit::TestCase | |
| 358 360 | 
             
              # QUEUE
         | 
| 359 361 |  | 
| 360 362 | 
             
              def test_queue_movement
         | 
| 361 | 
            -
                tc = Trans::Api::Connect.new CONFIG
         | 
| 363 | 
            +
                tc = Trans::Api::Connect.new @CONFIG
         | 
| 362 364 |  | 
| 363 365 | 
             
                torrents = []
         | 
| 364 366 |  | 
| @@ -4,6 +4,8 @@ require 'test/unit' | |
| 4 4 | 
             
            require File.expand_path(File.dirname(__FILE__) + "/../../lib/trans-api")
         | 
| 5 5 |  | 
| 6 6 |  | 
| 7 | 
            +
            # run with config options
         | 
| 8 | 
            +
            #CONFIG="{\"host\":\"localhost\",\"port\":9091,\"user\":\"admin\",\"pass\":\"admin\",\"path\":\"/transmission/rpc\"}" ruby -I test test/unit/trans_session_object.rb
         | 
| 7 9 |  | 
| 8 10 | 
             
            #
         | 
| 9 11 | 
             
            # Unit test for Transmission RPC+json
         | 
| @@ -13,10 +15,14 @@ require File.expand_path(File.dirname(__FILE__) + "/../../lib/trans-api") | |
| 13 15 |  | 
| 14 16 | 
             
            class TransSessionObject < Test::Unit::TestCase
         | 
| 15 17 |  | 
| 16 | 
            -
               | 
| 18 | 
            +
              BLOCKLIST = "http://list.iblocklist.com/?list=bt_level3&fileformat=p2p&archiveformat=gz"
         | 
| 19 | 
            +
             | 
| 17 20 |  | 
| 18 21 | 
             
              def setup
         | 
| 19 | 
            -
                 | 
| 22 | 
            +
                @CONFIG = { host: "localhost", port: 9091, user: "admin", pass: "admin", path: "/transmission/rpc" }
         | 
| 23 | 
            +
                @CONFIG = JSON.parse(ENV["CONFIG"], symbolize_names: true) if ENV.include? "CONFIG"
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                Trans::Api::Client.config = @CONFIG
         | 
| 20 26 | 
             
              end
         | 
| 21 27 |  | 
| 22 28 |  | 
| @@ -79,4 +85,55 @@ class TransSessionObject < Test::Unit::TestCase | |
| 79 85 | 
             
              end
         | 
| 80 86 |  | 
| 81 87 |  | 
| 88 | 
            +
              def test_swap_configs
         | 
| 89 | 
            +
                # test default operation
         | 
| 90 | 
            +
                session = Trans::Api::Session.instance
         | 
| 91 | 
            +
                assert session.fields_and_values.size > 0, "no fields and values loaded"
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                # insert a broken config
         | 
| 94 | 
            +
                broken_config = { host: "localhost", port: 9091, user: "akdljflkasjdlfk", pass: "alskdfjlkajsdfl", path: "/transmission/rpc" }
         | 
| 95 | 
            +
                Trans::Api::Client.config = broken_config
         | 
| 96 | 
            +
                session.reload!
         | 
| 97 | 
            +
                assert session.stats!.nil?, "stat should be broken!"
         | 
| 98 | 
            +
              end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
             | 
| 101 | 
            +
              def test_set_blocklist
         | 
| 102 | 
            +
                session = Trans::Api::Session.instance
         | 
| 103 | 
            +
                session.blocklist_enabled = false
         | 
| 104 | 
            +
                session.blocklist_url = ""
         | 
| 105 | 
            +
                session.save!
         | 
| 106 | 
            +
                # verify
         | 
| 107 | 
            +
                session.reload!
         | 
| 108 | 
            +
                assert session.blocklist_url == "", "url not updated"
         | 
| 109 | 
            +
                assert session.blocklist_enabled == false, "boolean not toggled"
         | 
| 110 | 
            +
                # save blocklist to session
         | 
| 111 | 
            +
                session = Trans::Api::Session.instance
         | 
| 112 | 
            +
                session.blocklist_url = BLOCKLIST
         | 
| 113 | 
            +
                session.blocklist_enabled = true
         | 
| 114 | 
            +
                session.save!
         | 
| 115 | 
            +
                # verify
         | 
| 116 | 
            +
                session.reload!
         | 
| 117 | 
            +
                assert session.blocklist_url == BLOCKLIST, "blocklist not saved!"
         | 
| 118 | 
            +
                # force blocklist update
         | 
| 119 | 
            +
                response = session.update_blocklist!
         | 
| 120 | 
            +
                session.reload!
         | 
| 121 | 
            +
                assert session.blocklist_size == response[:blocklist_size], "blocklist not updated"
         | 
| 122 | 
            +
              end
         | 
| 123 | 
            +
             | 
| 124 | 
            +
              def test_set_wrong_blocklist
         | 
| 125 | 
            +
                session = Trans::Api::Session.instance
         | 
| 126 | 
            +
                session.blocklist_enabled = false
         | 
| 127 | 
            +
                session.blocklist_url = ""
         | 
| 128 | 
            +
                session.save!
         | 
| 129 | 
            +
                session.reload!
         | 
| 130 | 
            +
                begin
         | 
| 131 | 
            +
                  session.update_blocklist!
         | 
| 132 | 
            +
                  assert false, "should not be possible without an url"
         | 
| 133 | 
            +
                rescue Exception => e
         | 
| 134 | 
            +
                  assert true
         | 
| 135 | 
            +
                end
         | 
| 136 | 
            +
              end
         | 
| 137 | 
            +
             | 
| 138 | 
            +
             | 
| 82 139 | 
             
            end
         | 
| @@ -3,6 +3,8 @@ require 'rubygems' | |
| 3 3 | 
             
            require 'test/unit'
         | 
| 4 4 | 
             
            require File.expand_path(File.dirname(__FILE__) + "/../../lib/trans-api")
         | 
| 5 5 |  | 
| 6 | 
            +
            # run with config options
         | 
| 7 | 
            +
            #CONFIG="{\"host\":\"localhost\",\"port\":9091,\"user\":\"admin\",\"pass\":\"admin\",\"path\":\"/transmission/rpc\"}" ruby -I test test/unit/trans_torrent_object.rb
         | 
| 6 8 |  | 
| 7 9 |  | 
| 8 10 | 
             
            #
         | 
| @@ -13,10 +15,11 @@ require File.expand_path(File.dirname(__FILE__) + "/../../lib/trans-api") | |
| 13 15 |  | 
| 14 16 | 
             
            class TransTorrentObject < Test::Unit::TestCase
         | 
| 15 17 |  | 
| 16 | 
            -
              CONFIG = { host: "localhost", port: 8078, user: "pinguin", pass: "100110", path: "/transmission/rpc" }
         | 
| 17 | 
            -
             | 
| 18 18 | 
             
              def setup
         | 
| 19 | 
            -
                 | 
| 19 | 
            +
                @CONFIG = { host: "localhost", port: 9091, user: "admin", pass: "admin", path: "/transmission/rpc" }
         | 
| 20 | 
            +
                @CONFIG = JSON.parse(ENV["CONFIG"], symbolize_names: true) if ENV.include? "CONFIG"
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                Trans::Api::Client.config = @CONFIG
         | 
| 20 23 | 
             
                Trans::Api::Torrent.default_fields = [ :id, :status, :name ]
         | 
| 21 24 |  | 
| 22 25 | 
             
                # add a testing torrent
         | 
| @@ -250,6 +253,15 @@ class TransTorrentObject < Test::Unit::TestCase | |
| 250 253 | 
             
                assert torrent.downloadDir == file
         | 
| 251 254 | 
             
              end
         | 
| 252 255 |  | 
| 256 | 
            +
              def test_duplicate_file_upload
         | 
| 257 | 
            +
                # add test torrents
         | 
| 258 | 
            +
                file = File.expand_path(File.dirname(__FILE__) + "/torrents/debian-6.0.6-amd64-CD-2.iso.torrent")
         | 
| 259 | 
            +
                # hammer duplicate torrent
         | 
| 260 | 
            +
                torrent = nil
         | 
| 261 | 
            +
                10.times { |t| torrent = Trans::Api::Torrent.add_file(file, paused: true) }
         | 
| 262 | 
            +
                assert Trans::Api::Torrent.all.size == 2
         | 
| 263 | 
            +
                torrent.delete!
         | 
| 264 | 
            +
              end
         | 
| 253 265 |  | 
| 254 266 | 
             
              def test_queue_movement
         | 
| 255 267 | 
             
                # get queueposition as well
         | 
| @@ -350,7 +362,12 @@ class TransTorrentObject < Test::Unit::TestCase | |
| 350 362 | 
             
                torrent = Trans::Api::Torrent.add_metainfo(metainfo, paused: true)
         | 
| 351 363 | 
             
                assert torrent.name == "debian-6.0.6-amd64-CD-5.iso"
         | 
| 352 364 | 
             
                torrent.delete!
         | 
| 365 | 
            +
              end
         | 
| 353 366 |  | 
| 367 | 
            +
              def test_find_torrent_by_value_name
         | 
| 368 | 
            +
                torrent = Trans::Api::Torrent.find_by_field_value(:name, "debian-6.0.6-amd64-CD-1.iso")
         | 
| 369 | 
            +
                assert !torrent.nil?
         | 
| 370 | 
            +
                assert torrent.name == "debian-6.0.6-amd64-CD-1.iso"
         | 
| 354 371 | 
             
              end
         | 
| 355 372 |  | 
| 356 373 |  | 
    
        data/trans-api.gemspec
    CHANGED
    
    | @@ -8,14 +8,14 @@ Gem::Specification.new do |gem| | |
| 8 8 | 
             
              gem.version       = Trans::Api::VERSION
         | 
| 9 9 | 
             
              gem.authors       = ["Dennis Blommesteijn"]
         | 
| 10 10 | 
             
              gem.email         = ["dennis@blommesteijn.com"]
         | 
| 11 | 
            -
              gem.description   = %q{Transmission RPC API for Ruby on Rails (gem) | 
| 12 | 
            -
              gem.summary       = %q{Transmission RPC API for Ruby on Rails (gem)}
         | 
| 13 | 
            -
              gem.homepage      = ""
         | 
| 11 | 
            +
              gem.description   = %q{Transmission (bittorrent client) RPC API for Ruby on Rails (gem)}
         | 
| 12 | 
            +
              gem.summary       = %q{Transmission (bittorrent client) RPC API for Ruby on Rails (gem)}
         | 
| 13 | 
            +
              gem.homepage      = "https://github.com/dblommesteijn/trans-api"
         | 
| 14 14 |  | 
| 15 15 | 
             
              # dependencies
         | 
| 16 | 
            -
              gem.add_dependency 'nokogiri'
         | 
| 17 | 
            -
              gem.add_dependency 'json'
         | 
| 18 | 
            -
              gem.add_development_dependency "test-unit"
         | 
| 16 | 
            +
              gem.add_dependency 'nokogiri', "> 1.5.0"
         | 
| 17 | 
            +
              gem.add_dependency 'json', "> 1.6.1"
         | 
| 18 | 
            +
              gem.add_development_dependency "test-unit", "> 2.0.0"
         | 
| 19 19 |  | 
| 20 20 | 
             
              gem.files         = `git ls-files`.split($/)
         | 
| 21 21 | 
             
              gem.executables   = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
         | 
    
        metadata
    CHANGED
    
    | @@ -1,58 +1,58 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: trans-api
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Dennis Blommesteijn
         | 
| 8 | 
            -
            autorequire:
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2014-03-26 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: nokogiri
         | 
| 15 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 16 | 
            -
                requirements:
         | 
| 17 | 
            -
                - - ">="
         | 
| 18 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            -
                    version: '0'
         | 
| 20 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 21 16 | 
             
                requirements:
         | 
| 22 | 
            -
                - - " | 
| 17 | 
            +
                - - ">"
         | 
| 23 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 24 | 
            -
                    version:  | 
| 25 | 
            -
              prerelease: false
         | 
| 19 | 
            +
                    version: 1.5.0
         | 
| 26 20 | 
             
              type: :runtime
         | 
| 27 | 
            -
             | 
| 28 | 
            -
              name: json
         | 
| 21 | 
            +
              prerelease: false
         | 
| 29 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 30 23 | 
             
                requirements:
         | 
| 31 | 
            -
                - - " | 
| 24 | 
            +
                - - ">"
         | 
| 32 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version:  | 
| 26 | 
            +
                    version: 1.5.0
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: json
         | 
| 34 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 35 30 | 
             
                requirements:
         | 
| 36 | 
            -
                - - " | 
| 31 | 
            +
                - - ">"
         | 
| 37 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 38 | 
            -
                    version:  | 
| 39 | 
            -
              prerelease: false
         | 
| 33 | 
            +
                    version: 1.6.1
         | 
| 40 34 | 
             
              type: :runtime
         | 
| 41 | 
            -
             | 
| 42 | 
            -
              name: test-unit
         | 
| 35 | 
            +
              prerelease: false
         | 
| 43 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 44 37 | 
             
                requirements:
         | 
| 45 | 
            -
                - - " | 
| 38 | 
            +
                - - ">"
         | 
| 46 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            -
                    version:  | 
| 40 | 
            +
                    version: 1.6.1
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: test-unit
         | 
| 48 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 49 44 | 
             
                requirements:
         | 
| 50 | 
            -
                - - " | 
| 45 | 
            +
                - - ">"
         | 
| 51 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 52 | 
            -
                    version:  | 
| 53 | 
            -
              prerelease: false
         | 
| 47 | 
            +
                    version: 2.0.0
         | 
| 54 48 | 
             
              type: :development
         | 
| 55 | 
            -
             | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - ">"
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: 2.0.0
         | 
| 55 | 
            +
            description: Transmission (bittorrent client) RPC API for Ruby on Rails (gem)
         | 
| 56 56 | 
             
            email:
         | 
| 57 57 | 
             
            - dennis@blommesteijn.com
         | 
| 58 58 | 
             
            executables: []
         | 
| @@ -65,8 +65,6 @@ files: | |
| 65 65 | 
             
            - LICENSE.txt
         | 
| 66 66 | 
             
            - README.md
         | 
| 67 67 | 
             
            - Rakefile
         | 
| 68 | 
            -
            - examples/basic_setup.rb
         | 
| 69 | 
            -
            - examples/torrents/debian-6.0.6-amd64-CD-10.iso.torrent
         | 
| 70 68 | 
             
            - lib/trans-api.rb
         | 
| 71 69 | 
             
            - lib/trans-api/client.rb
         | 
| 72 70 | 
             
            - lib/trans-api/connect.rb
         | 
| @@ -74,7 +72,6 @@ files: | |
| 74 72 | 
             
            - lib/trans-api/session.rb
         | 
| 75 73 | 
             
            - lib/trans-api/torrent.rb
         | 
| 76 74 | 
             
            - lib/trans-api/version.rb
         | 
| 77 | 
            -
            - test/test_helper.rb
         | 
| 78 75 | 
             
            - test/unit/torrents/debian-6.0.6-amd64-CD-1.iso.torrent
         | 
| 79 76 | 
             
            - test/unit/torrents/debian-6.0.6-amd64-CD-2.iso.torrent
         | 
| 80 77 | 
             
            - test/unit/torrents/debian-6.0.6-amd64-CD-3.iso.torrent
         | 
| @@ -86,10 +83,10 @@ files: | |
| 86 83 | 
             
            - test/unit/trans_session_object.rb
         | 
| 87 84 | 
             
            - test/unit/trans_torrent_object.rb
         | 
| 88 85 | 
             
            - trans-api.gemspec
         | 
| 89 | 
            -
            homepage:  | 
| 86 | 
            +
            homepage: https://github.com/dblommesteijn/trans-api
         | 
| 90 87 | 
             
            licenses: []
         | 
| 91 88 | 
             
            metadata: {}
         | 
| 92 | 
            -
            post_install_message:
         | 
| 89 | 
            +
            post_install_message: 
         | 
| 93 90 | 
             
            rdoc_options: []
         | 
| 94 91 | 
             
            require_paths:
         | 
| 95 92 | 
             
            - lib
         | 
| @@ -104,13 +101,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 104 101 | 
             
                - !ruby/object:Gem::Version
         | 
| 105 102 | 
             
                  version: '0'
         | 
| 106 103 | 
             
            requirements: []
         | 
| 107 | 
            -
            rubyforge_project:
         | 
| 108 | 
            -
            rubygems_version: 2. | 
| 109 | 
            -
            signing_key:
         | 
| 104 | 
            +
            rubyforge_project: 
         | 
| 105 | 
            +
            rubygems_version: 2.2.2
         | 
| 106 | 
            +
            signing_key: 
         | 
| 110 107 | 
             
            specification_version: 4
         | 
| 111 | 
            -
            summary: Transmission RPC API for Ruby on Rails (gem)
         | 
| 108 | 
            +
            summary: Transmission (bittorrent client) RPC API for Ruby on Rails (gem)
         | 
| 112 109 | 
             
            test_files:
         | 
| 113 | 
            -
            - test/test_helper.rb
         | 
| 114 110 | 
             
            - test/unit/torrents/debian-6.0.6-amd64-CD-1.iso.torrent
         | 
| 115 111 | 
             
            - test/unit/torrents/debian-6.0.6-amd64-CD-2.iso.torrent
         | 
| 116 112 | 
             
            - test/unit/torrents/debian-6.0.6-amd64-CD-3.iso.torrent
         | 
    
        data/examples/basic_setup.rb
    DELETED
    
    | @@ -1,78 +0,0 @@ | |
| 1 | 
            -
            #!/usr/bin/env ruby
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            # setup
         | 
| 4 | 
            -
            require 'rubygems'
         | 
| 5 | 
            -
            require "bundler/setup"
         | 
| 6 | 
            -
            require 'trans-api'
         | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
            class BasicSetup
         | 
| 10 | 
            -
             | 
| 11 | 
            -
              include Trans::Api
         | 
| 12 | 
            -
             | 
| 13 | 
            -
              CONFIG = { host: "localhost", port: 9091, user: "admin", pass: "admin", path: "/transmission/rpc" }
         | 
| 14 | 
            -
              FIELDS = [ :id, :status, :name ]
         | 
| 15 | 
            -
             | 
| 16 | 
            -
              def initialize
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                # connection information (rpc location)
         | 
| 19 | 
            -
                Client.config = CONFIG
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                # default loading torrent fields
         | 
| 22 | 
            -
                Torrent.default_fields = FIELDS
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                #TODO: add a section for session here!!
         | 
| 25 | 
            -
             | 
| 26 | 
            -
              end
         | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
              def add_torrent
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                # selecting a file to add (debian demo file)
         | 
| 32 | 
            -
                file = ::File.expand_path(::File.dirname(__FILE__) + "/torrents/debian-6.0.6-amd64-CD-10.iso.torrent")
         | 
| 33 | 
            -
             | 
| 34 | 
            -
                # adding a torrent using static call on Torrent object (paused transfer)
         | 
| 35 | 
            -
                @torrent = Torrent.add_file file, paused: true
         | 
| 36 | 
            -
                # return variable is an instance of the torrent file
         | 
| 37 | 
            -
                # an exception can be raised on invalid request
         | 
| 38 | 
            -
             | 
| 39 | 
            -
                # NOTE: we will store it for later use (removing this torrent, not the whole list)
         | 
| 40 | 
            -
             | 
| 41 | 
            -
              end
         | 
| 42 | 
            -
             | 
| 43 | 
            -
              def remove_torrent
         | 
| 44 | 
            -
             | 
| 45 | 
            -
                #TODO: remove torrent here!
         | 
| 46 | 
            -
             | 
| 47 | 
            -
              end
         | 
| 48 | 
            -
             | 
| 49 | 
            -
              def iterating_torrents
         | 
| 50 | 
            -
             | 
| 51 | 
            -
                torrents = Torrent.all
         | 
| 52 | 
            -
             | 
| 53 | 
            -
                torrents.each do |torrent|
         | 
| 54 | 
            -
             | 
| 55 | 
            -
                  puts "#{torrent.name} -> #{torrent.status_name}"
         | 
| 56 | 
            -
             | 
| 57 | 
            -
                end
         | 
| 58 | 
            -
             | 
| 59 | 
            -
              end
         | 
| 60 | 
            -
             | 
| 61 | 
            -
            end
         | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
            # initiate BasicSetup object, and run its methods
         | 
| 66 | 
            -
            begin
         | 
| 67 | 
            -
             | 
| 68 | 
            -
              bs = BasicSetup.new
         | 
| 69 | 
            -
              bs.add_torrent
         | 
| 70 | 
            -
              bs.iterating_torrents
         | 
| 71 | 
            -
             | 
| 72 | 
            -
            rescue Exception => e
         | 
| 73 | 
            -
              puts e
         | 
| 74 | 
            -
            end
         | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| Binary file |