nnmClub_api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f81d8f9acdfb4444ebbbe2ab1e8227f03130a692
4
+ data.tar.gz: a3952f607a0a980739914a38d87a7354c1d08a06
5
+ SHA512:
6
+ metadata.gz: e2a65c1a659b6fb3242ac781136ed1cc0d5e4f5330d75624e646fe64ae43a0deb121aac93b6779601755ee96809c29a74572b5b95bfde3b34bc3227122db7e85
7
+ data.tar.gz: 7d3672ff183eb36e046c32d87b5074a4bc0c43dbf15922808de99bb121c6fa63bf337300c74fbfa82386316ecd3f517dffb0c1dbe745745905f79ce7d1f8df13
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nnmClub_api.gemspec
4
+ group :test do
5
+ gem 'rspec'
6
+ gem 'guard-rspec', require: false
7
+ end
8
+ gem 'mechanize'
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Baranov Sergey
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # NnmClubApi
2
+
3
+ ### Is usefull gem if you need to parse nnm-club.me tracker.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'nnmClub_api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install nnmClub_api
18
+
19
+ ## Usage
20
+
21
+ require 'nnmClub_api'
22
+
23
+ client = NnmclubApi.new('user','pass')
24
+ client.search(:title => "Noize MC")
25
+
26
+ puts client.result
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it ( https://github.com/gemoroy/nnmClub_api/fork )
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,55 @@
1
+ require "nnmClub_api/version"
2
+ require "rubygems"
3
+ require "mechanize"
4
+ require "json"
5
+
6
+ class NnmclubApi
7
+ attr_accessor :agent, :result
8
+
9
+ LOGIN_PAGE = 'http://nnm-club.me/forum/login.php'
10
+ SEARCH_PAGE = 'http://nnm-club.me/forum/tracker.php'
11
+
12
+ ORDER_OPTIONS = { date: 1, name: 2, downloads: 4, shows: 6, seeders: 10,
13
+ leechers: 11, size: 7, last_post: 8, speed_up: 12,
14
+ speed_down: 13, message_count: 5, last_seed: 9 }
15
+ SORT_OPTIONS = {asc: 1, desc: 2}
16
+
17
+ def initialize(username, password)
18
+ @agent = Mechanize.new
19
+ @agent.user_agent_alias = "Mac Safari"
20
+ end
21
+
22
+ def result
23
+ @result.to_json
24
+ end
25
+
26
+ #@param option [Hash] the format type, `:title`
27
+ #@return [Hash] the options keys with search result
28
+ def search(options = {})
29
+ @result = []
30
+ query = prepare_query_string options
31
+ @agent.get query
32
+ parse_search
33
+ end
34
+
35
+ private
36
+ def prepare_query_string(options)
37
+ #?q=lorem+ipsum&w=title
38
+ SEARCH_PAGE+"?nm="+options[:title].gsub(/\s/,'%20')
39
+ end
40
+
41
+ def parse_search
42
+ @agent.page.search("//table[@class='forumline tablesorter']/tbody/tr").map do |row|
43
+ size = row.at("td[6]/u").text.to_i
44
+ title = row.css(".topictitle").text.strip
45
+ seeders = row.css('.seedmed').text.to_i
46
+ leechers = row.css('.leechmed').text.to_i
47
+ torrent_id = row.css('.topictitle').at('a')
48
+
49
+ if !title.nil? && !title.empty? && !torrent_id.nil?
50
+ @result.push ({ title: title, torrent_id: "http://nnm-club.me/forum/#{torrent_id.values.last}",
51
+ seeders: seeders, leechers: leechers, size: size })
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module NnmClubApi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nnmClub_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nnmClub_api"
8
+ spec.version = NnmClubApi::VERSION
9
+ spec.authors = ["Baranov Sergey"]
10
+ spec.email = ["sergey@drummer.ru"]
11
+ spec.summary = %q{ Write a short summary. Required.}
12
+ spec.description = %q{ Write a longer description. Optional.}
13
+ spec.homepage = "https://github.com/gemoroy/nnmClub_api"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,14 @@
1
+ require 'nnmClub_api'
2
+
3
+ describe "NnmclubApi " do
4
+ before { @tracker = NnmclubApi.new('login', 'pass') }
5
+ subject { @tracker }
6
+
7
+ describe "#search" do
8
+ describe "with valid params" do
9
+ it "returns link with term" do
10
+ expect( @tracker.search(title: "Noize MC") ).to eq('http://nnm-club.me/forum/tracker.php?nm=Noize%20MC')
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,78 @@
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
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, make a
10
+ # separate helper file that requires this one and then use it only in the specs
11
+ # that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # The settings below are suggested to provide a good initial experience
19
+ # with RSpec, but feel free to customize to your heart's content.
20
+ =begin
21
+ # These two settings work together to allow you to limit a spec run
22
+ # to individual examples or groups you care about by tagging them with
23
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
24
+ # get run.
25
+ config.filter_run :focus
26
+ config.run_all_when_everything_filtered = true
27
+
28
+ # Many RSpec users commonly either run the entire suite or an individual
29
+ # file, and it's useful to allow more verbose output when running an
30
+ # individual spec file.
31
+ if config.files_to_run.one?
32
+ # Use the documentation formatter for detailed output,
33
+ # unless a formatter has already been configured
34
+ # (e.g. via a command-line flag).
35
+ config.default_formatter = 'doc'
36
+ end
37
+
38
+ # Print the 10 slowest examples and example groups at the
39
+ # end of the spec run, to help surface which specs are running
40
+ # particularly slow.
41
+ config.profile_examples = 10
42
+
43
+ # Run specs in random order to surface order dependencies. If you find an
44
+ # order dependency and want to debug it, you can fix the order by providing
45
+ # the seed, which is printed after each run.
46
+ # --seed 1234
47
+ config.order = :random
48
+
49
+ # Seed global randomization in this process using the `--seed` CLI option.
50
+ # Setting this allows you to use `--seed` to deterministically reproduce
51
+ # test failures related to randomization by passing the same `--seed` value
52
+ # as the one that triggered the failure.
53
+ Kernel.srand config.seed
54
+
55
+ # rspec-expectations config goes here. You can use an alternate
56
+ # assertion/expectation library such as wrong or the stdlib/minitest
57
+ # assertions if you prefer.
58
+ config.expect_with :rspec do |expectations|
59
+ # Enable only the newer, non-monkey-patching expect syntax.
60
+ # For more details, see:
61
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
62
+ expectations.syntax = :expect
63
+ end
64
+
65
+ # rspec-mocks config goes here. You can use an alternate test double
66
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
67
+ config.mock_with :rspec do |mocks|
68
+ # Enable only the newer, non-monkey-patching expect syntax.
69
+ # For more details, see:
70
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
71
+ mocks.syntax = :expect
72
+
73
+ # Prevents you from mocking or stubbing a method that does not exist on
74
+ # a real object. This is generally recommended.
75
+ mocks.verify_partial_doubles = true
76
+ end
77
+ =end
78
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nnmClub_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Baranov Sergey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: " Write a longer description. Optional."
42
+ email:
43
+ - sergey@drummer.ru
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - Gemfile
51
+ - Guardfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/nnmClub_api.rb
56
+ - lib/nnmClub_api/version.rb
57
+ - nnmClub_api.gemspec
58
+ - spec/nnmcluv_api_spec.rb
59
+ - spec/spec_helper.rb
60
+ homepage: https://github.com/gemoroy/nnmClub_api
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.2.2
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Write a short summary. Required.
84
+ test_files:
85
+ - spec/nnmcluv_api_spec.rb
86
+ - spec/spec_helper.rb