rutracker_api 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d8432e4a26f5ae68930befb739c5fbfb4ed124fc
4
+ data.tar.gz: be616b460c87218ea21daed91a0f0796c26e300c
5
+ SHA512:
6
+ metadata.gz: cc982d09c8b6fbe7c05af893414f10e559c980232f7b072be8c75abd7fd91094a7c011fe22011d7db11defda6dbed9840a347bc5a0b6e47f9fde1af252d148f5
7
+ data.tar.gz: 61ab1d9a914c4135c684230b9092ec28265a73bc8647fadbdc6031d4514c56e8856b664599a14b77d281904bf788dcc08410742b5fd352294b50055f4d4f576e
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+ .env
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.rvmrc ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 2.0.0" > .rvmrc
9
+ environment_id="ruby-2.0.0-p247@rutracker_api"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.23.13 (stable)" # 1.10.1 seems like a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | __rvm_awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
27
+ do
28
+ if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
29
+ then \. "${__hook}" || true
30
+ fi
31
+ done
32
+ unset __hook
33
+ if (( ${rvm_use_flag:=1} >= 1 )) # display automatically
34
+ then
35
+ if [[ $- == *i* ]] # check for interactive shells
36
+ then printf "%b" "Using: $(tput setaf 2 2>/dev/null)$GEM_HOME$(tput sgr0 2>/dev/null)
37
+ " # show the user the ruby and gemset they are using in green
38
+ else printf "%b" "Using: $GEM_HOME
39
+ " # don't use colors in non-interactive shells
40
+ fi
41
+ fi
42
+ else
43
+ # If the environment file has not yet been created, use the RVM CLI to select.
44
+ rvm --create use "$environment_id" || {
45
+ echo "Failed to create RVM environment '${environment_id}'."
46
+ return 1
47
+ }
48
+ fi
49
+
50
+ # If you use bundler, this might be useful to you:
51
+ # if [[ -s Gemfile ]] && {
52
+ # ! builtin command -v bundle >/dev/null ||
53
+ # builtin command -v bundle | GREP_OPTIONS="" \grep $rvm_path/bin/bundle >/dev/null
54
+ # }
55
+ # then
56
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
57
+ # gem install bundler
58
+ # fi
59
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
60
+ # then
61
+ # bundle install | GREP_OPTIONS="" \grep -vE '^Using|Your bundle is complete'
62
+ # fi
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :test do
4
+ gem 'rspec'
5
+ end
6
+ gem 'dotenv-rails'
7
+ gem 'mechanize'
@@ -0,0 +1,47 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.2.4)
5
+ domain_name (0.5.14)
6
+ unf (>= 0.0.5, < 1.0.0)
7
+ dotenv (0.9.0)
8
+ dotenv-rails (0.9.0)
9
+ dotenv (= 0.9.0)
10
+ http-cookie (1.0.2)
11
+ domain_name (~> 0.5)
12
+ mechanize (2.7.2)
13
+ domain_name (~> 0.5, >= 0.5.1)
14
+ http-cookie (~> 1.0.0)
15
+ mime-types (~> 1.17, >= 1.17.2)
16
+ net-http-digest_auth (~> 1.1, >= 1.1.1)
17
+ net-http-persistent (~> 2.5, >= 2.5.2)
18
+ nokogiri (~> 1.4)
19
+ ntlm-http (~> 0.1, >= 0.1.1)
20
+ webrobots (>= 0.0.9, < 0.2)
21
+ mime-types (1.25)
22
+ mini_portile (0.5.2)
23
+ net-http-digest_auth (1.4)
24
+ net-http-persistent (2.9)
25
+ nokogiri (1.6.0)
26
+ mini_portile (~> 0.5.0)
27
+ ntlm-http (0.1.1)
28
+ rspec (2.14.1)
29
+ rspec-core (~> 2.14.0)
30
+ rspec-expectations (~> 2.14.0)
31
+ rspec-mocks (~> 2.14.0)
32
+ rspec-core (2.14.7)
33
+ rspec-expectations (2.14.3)
34
+ diff-lcs (>= 1.1.3, < 2.0)
35
+ rspec-mocks (2.14.4)
36
+ unf (0.1.3)
37
+ unf_ext
38
+ unf_ext (0.0.6)
39
+ webrobots (0.1.1)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ dotenv-rails
46
+ mechanize
47
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Dmytro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,2 @@
1
+ rutracker-parser
2
+ ================
@@ -0,0 +1,3 @@
1
+ RUTRACKER_LOGIN: login
2
+ RUTRACKER_PASS: password
3
+
@@ -0,0 +1,78 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rubygems'
3
+ require 'mechanize'
4
+ require 'dotenv'
5
+
6
+ class RutrackerApi
7
+
8
+ Dotenv.load
9
+ attr_accessor :agent
10
+
11
+ LOGIN_PAGE = 'http://login.rutracker.org/forum/login.php'
12
+ SEARCH_PAGE = 'http://rutracker.org/forum/tracker.php'
13
+
14
+ ORDER_OPTIONS = { date: 1, name: 2, downloads: 4, shows: 6, seeders: 10,
15
+ leechers: 11, size: 7, last_post: 8, speed_up: 12,
16
+ speed_down: 13, message_count: 5, last_seed: 9 }
17
+ SORT_OPTIONS = {asc: 1, desc: 2}
18
+
19
+ def initialize
20
+ @agent = Mechanize.new
21
+ @agent.user_agent_alias = 'Mac Safari'
22
+ login
23
+ end
24
+
25
+ # Advance search throw rutracker
26
+ #
27
+ # @param option [Hash] the format type, `:category`, `:term`, `:sort`, `:order_by`
28
+ # @return [Hash] the options keys with search result
29
+ def search(options = {})
30
+ query = prepare_query_string options
31
+ @agent.get query
32
+ parse_search
33
+ end
34
+
35
+ def find_user(nick)
36
+ # TODO: add parser for user pages
37
+ @agent.get 'http://rutracker.org/forum/profile.php?mode=viewprofile&u=' + nick
38
+ end
39
+
40
+ private
41
+ def login
42
+ @agent.post(LOGIN_PAGE, login_username: ENV["RUTRACKER_LOGIN"],
43
+ login_password: ENV["RUTRACKER_PASS"], login: 'Вход')
44
+ end
45
+
46
+ def prepare_query_string(options)
47
+ prepared = { f: options[:category], nm: options[:term],
48
+ s: SORT_OPTIONS[options[:sort]], o: ORDER_OPTIONS[options[:order_by]] }
49
+
50
+ query = SEARCH_PAGE + '?'
51
+ if prepared[:nm]
52
+ query.gsub! '&', ''
53
+ query << "nm=%22#{prepared[:nm]}%22"
54
+ end
55
+ query << "&f=#{prepared[:f]}" if prepared[:f]
56
+ query << "&f=#{prepared[:o]}" if prepared[:order_by]
57
+ query << "&f=#{prepared[:s]}" if prepared[:sort]
58
+ query
59
+ end
60
+
61
+ def parse_search
62
+ @agent.page.search("//table[@class='forumline tablesorter']/tbody/tr").map do |row|
63
+ description = row.at("td[4]").text.strip
64
+ torrent_id = row.at("td[4]//a").attributes['data-topic_id'].text.to_i
65
+ size = row.at("td[6]/a").text.chomp(" ↓")
66
+ seeders = row.at("td[7]").text.to_i
67
+ leechers = row.at("td[8]").text.to_i
68
+ downloads = row.at("td[9]").text.to_i
69
+ date = DateTime.strptime(row.at("td[10]/u").text, '%s')
70
+ author = row.css(".u-name/a").text
71
+ user_id = row.css(".u-name/a")[0]['href'].scan(/\d+/)[0].to_i
72
+
73
+ { description: description, torrent_id: torrent_id, size: size,
74
+ seeders: seeders, leechers: leechers, downloads: downloads,
75
+ date: date, author: author, user_id: user_id }
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'rutracker_api'
3
+ s.version = '0.0.0'
4
+ s.summary = "API for rutracker.org"
5
+ s.description = "Provide simple api for rutracker.org"
6
+
7
+ s.authors = ['Dmytro Bignyak']
8
+ s.email = 'bignyak@bigmir.net'
9
+ s.homepage = 'https://github.com/deril/rutracker_api'
10
+ s.license = 'MIT'
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.extra_rdoc_files = ['README.rdoc']
15
+ s.require_paths = ['lib']
16
+
17
+ s.add_dependency 'mechanize', ['>=2.7.2']
18
+ s.add_dependency 'dotenv-rails', ['>=0.9.0']
19
+
20
+ s.add_development_dependency 'bundler', ['>= 1.0.0']
21
+ s.add_development_dependency 'rake', ['>= 0']
22
+ s.add_development_dependency 'rspec', ['>= 0']
23
+ s.add_development_dependency 'rdoc', ['>= 0']
24
+ end
@@ -0,0 +1,33 @@
1
+ require 'rutracker_api'
2
+ describe "Rutracker Api" do
3
+ before { @tracker = RutrackerApi.new }
4
+ subject { @tracker }
5
+
6
+ describe "#search" do
7
+ describe "with invalid params" do
8
+ it "raise exeption with wrong search term" do
9
+ expect{@tracker.search("&8")}.to raise_error("Wrong search term")
10
+ end
11
+ end
12
+
13
+ describe "with valid params" do
14
+
15
+ it "returns link with term" do
16
+ expect( @tracker.search("Super Man") ).to eq('http://rutracker.org/forum/tracker.php?nm=Super Man')
17
+ end
18
+ it "returns link with category" do
19
+ expect( @tracker.search("Super Man", {category: '2,5'}) )
20
+ .to eq('http://rutracker.org/forum/tracker.php?nm=Super Man&f[]=2&f[]=5')
21
+ end
22
+ it "returns link with order_by key" do
23
+ expect( @tracker.search("Super Man", {order_by: 'name'}) )
24
+ .to eq('http://rutracker.org/forum/tracker.php?nm=Super Man&o=2')
25
+ end
26
+ it "returns link with sort_by key" do
27
+ expect( @tracker.search("Super Man", {sort_by: 'asc'}) )
28
+ .to eq('http://rutracker.org/forum/tracker.php?nm=Super Man&s=1')
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rutracker_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Dmytro Bignyak
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mechanize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.7.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.7.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rdoc
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Provide simple api for rutracker.org
98
+ email: bignyak@bigmir.net
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files:
102
+ - README.rdoc
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - .rvmrc
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE
110
+ - README.rdoc
111
+ - env.example
112
+ - lib/rutracker_api.rb
113
+ - rutracker_api.gemspec
114
+ - spec/rutracker_api_spec.rb
115
+ - spec/spec_helper.rb
116
+ homepage: https://github.com/deril/rutracker_api
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.1.10
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: API for rutracker.org
140
+ test_files:
141
+ - spec/rutracker_api_spec.rb
142
+ - spec/spec_helper.rb