rarbg 0.1.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +12 -0
- data/.gitignore +38 -0
- data/.rspec +4 -0
- data/.travis.yml +22 -0
- data/.yardopts +7 -0
- data/CHANGELOG.md +61 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +116 -0
- data/Rakefile +8 -0
- data/bin/console +8 -0
- data/bin/setup +7 -0
- data/lib/rarbg.rb +3 -122
- data/lib/rarbg/api.rb +219 -0
- data/lib/rarbg/version.rb +6 -0
- data/rarbg.gemspec +44 -0
- data/spec/rarbg/list_spec.rb +95 -0
- data/spec/rarbg/rarbg_spec.rb +19 -0
- data/spec/rarbg/search_spec.rb +107 -0
- data/spec/rarbg/token_spec.rb +54 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/stubs.rb +42 -0
- metadata +138 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97d8036d6683ad8f531bfbdce8a3b84ae80cc48d
|
4
|
+
data.tar.gz: 9934b0ac6016d6b8cb9d8b4f62ad674f611603d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8659a8ac02af06b417eabed6e871eea5c2e16dac2c9fdf71f2ea653a17832845c16f722f479f4eb4d8551e6da397dbd83bdedbc22ba3024feefc1b7e69335dd
|
7
|
+
data.tar.gz: b19db1e895fd7cc59ff7ba5104062b63aef09bb89f6ad9d62d492495ea8023f8a10bdecb747e7f0b793715dd25df3c4276e3ef2d72c063531cc22cdc777e8373
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/test/tmp/
|
8
|
+
/test/version_tmp/
|
9
|
+
/tmp/
|
10
|
+
|
11
|
+
## Version specifiers:
|
12
|
+
Gemfile.lock
|
13
|
+
.ruby-version
|
14
|
+
.ruby-gemset
|
15
|
+
|
16
|
+
## Environment normalization:
|
17
|
+
/.bundle/
|
18
|
+
/lib/bundler/man/
|
19
|
+
|
20
|
+
## RSpec:
|
21
|
+
/spec/reports/
|
22
|
+
/spec/examples.txt
|
23
|
+
.rspec_status
|
24
|
+
|
25
|
+
## Documentation cache:
|
26
|
+
/.yardoc/
|
27
|
+
/_yardoc/
|
28
|
+
/doc/
|
29
|
+
/rdoc/
|
30
|
+
|
31
|
+
## Logs:
|
32
|
+
*.log
|
33
|
+
|
34
|
+
## RVM:
|
35
|
+
.rvmrc
|
36
|
+
|
37
|
+
## Project specific:
|
38
|
+
apidocs_v2.txt
|
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
before_install: gem install bundler -v 1.16.1
|
4
|
+
script: bundle exec rspec
|
5
|
+
rvm:
|
6
|
+
- 2.5.1
|
7
|
+
- 2.4.4
|
8
|
+
- 2.3.7
|
9
|
+
- 2.2.10
|
10
|
+
branches:
|
11
|
+
only: master
|
12
|
+
notifications:
|
13
|
+
email: false
|
14
|
+
env:
|
15
|
+
global:
|
16
|
+
- CC_TEST_REPORTER_ID=ca61b641c417ff48e8cff3c0d10e5503539bf81348b0df8daca6c74e2401d4e4
|
17
|
+
before_script:
|
18
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
19
|
+
- chmod +x ./cc-test-reporter
|
20
|
+
- ./cc-test-reporter before-build
|
21
|
+
after_script:
|
22
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/.yardopts
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
5
|
+
and this project adheres to [Semantic Versioning](http://semver.org/).
|
6
|
+
|
7
|
+
## 1.0.0 – 2018-04-02
|
8
|
+
[Release](https://github.com/epistrephein/rarbg/releases/tag/v1.0.0) |
|
9
|
+
[Diff](https://github.com/epistrephein/rarbg/compare/v0.1.4...v1.0.0)
|
10
|
+
|
11
|
+
#### Changed
|
12
|
+
- Codebase has been completely refactored to be more resilient and error-free.
|
13
|
+
- This release is NOT backward compatible with 0.1 versions.
|
14
|
+
- Query parameters now use standard ruby syntax as expected and accept both
|
15
|
+
symbol and string keys.
|
16
|
+
- Compliance with API rate limiting (1req/2s) is now enforced automatically.
|
17
|
+
- Empty results now return an empty array instead of raising an exception.
|
18
|
+
|
19
|
+
#### Removed
|
20
|
+
- Removed `default_params`: query parameters are now passed per request.
|
21
|
+
- Removed `search_string`, `search_imdb`, `search_themoviedb`, `search_tvdb`:
|
22
|
+
search type must be specified as a keyword argument upon `search`.
|
23
|
+
- Removed `RequestError` exception: all API-related errors now raise an
|
24
|
+
`APIError` exception.
|
25
|
+
|
26
|
+
|
27
|
+
## 0.1.4 – 2017-12-22
|
28
|
+
[Release](https://github.com/epistrephein/rarbg/releases/tag/v0.1.4) |
|
29
|
+
[Diff](https://github.com/epistrephein/rarbg/compare/v0.1.3...v0.1.4)
|
30
|
+
|
31
|
+
#### Fixed
|
32
|
+
- Set Faraday middleware before adapter to suppress warning
|
33
|
+
|
34
|
+
|
35
|
+
## 0.1.3 – 2016-12-23
|
36
|
+
[Release](https://github.com/epistrephein/rarbg/releases/tag/v0.1.3) |
|
37
|
+
[Diff](https://github.com/epistrephein/rarbg/compare/v0.1.2...v0.1.3)
|
38
|
+
|
39
|
+
#### Changed
|
40
|
+
- Move `app_id` and `token` params to `call` method to prevent override
|
41
|
+
|
42
|
+
|
43
|
+
## 0.1.2 – 2016-12-21
|
44
|
+
[Release](https://github.com/epistrephein/rarbg/releases/tag/v0.1.2) |
|
45
|
+
[Diff](https://github.com/epistrephein/rarbg/compare/v0.1.1...v0.1.2)
|
46
|
+
|
47
|
+
#### Changed
|
48
|
+
- Sleep for 2 seconds after `get_token` to avoid request limit error
|
49
|
+
|
50
|
+
|
51
|
+
## 0.1.1 – 2016-12-21
|
52
|
+
[Release](https://github.com/epistrephein/rarbg/releases/tag/v0.1.1) |
|
53
|
+
[Diff](https://github.com/epistrephein/rarbg/compare/v0.1.0...v0.1.1)
|
54
|
+
|
55
|
+
#### Fixed
|
56
|
+
- Fix invalid gemspec
|
57
|
+
|
58
|
+
|
59
|
+
## 0.1.0 – 2016-12-21
|
60
|
+
|
61
|
+
Yanked
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
education, socio-economic status, nationality, personal appearance, race,
|
10
|
+
religion, or sexual identity and orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at epistrephein@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
71
|
+
version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016-2018 Tommaso Barbato
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all 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,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
# RARBG
|
2
|
+
[![Gem Version](https://img.shields.io/gem/v/rarbg.svg?colorB=brightgreen&style=flat-square)](https://rubygems.org/gems/rarbg)
|
3
|
+
[![Build status](https://img.shields.io/travis/epistrephein/rarbg/master.svg?style=flat-square)](https://travis-ci.org/epistrephein/rarbg)
|
4
|
+
[![Maintainability](https://img.shields.io/codeclimate/maintainability/epistrephein/rarbg.svg?style=flat-square)](https://codeclimate.com/github/epistrephein/rarbg)
|
5
|
+
[![Coverage](https://img.shields.io/codeclimate/c/epistrephein/rarbg.svg?style=flat-square)](https://codeclimate.com/github/epistrephein/rarbg)
|
6
|
+
[![Dependency Status](https://img.shields.io/gemnasium/epistrephein/rarbg.svg?style=flat-square)](https://gemnasium.com/epistrephein/rarbg)
|
7
|
+
[![Inline docs](http://inch-ci.org/github/epistrephein/rarbg.svg?branch=master&style=flat-square)](http://inch-ci.org/github/epistrephein/rarbg)
|
8
|
+
|
9
|
+
Ruby wrapper for RARBG Torrent API.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Install as a gem
|
14
|
+
|
15
|
+
```shell
|
16
|
+
$ gem install rarbg
|
17
|
+
```
|
18
|
+
|
19
|
+
Or add it to your Gemfile and execute `bundle install`
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'rarbg', '~> 1.0'
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage [![Documentation](https://img.shields.io/badge/docs-yard-blue.svg?style=flat-square)](http://www.rubydoc.info/gems/rarbg)
|
26
|
+
|
27
|
+
This gem wraps all API methods available from [RARBG TorrentAPI](https://torrentapi.org/apidocs_v2.txt).
|
28
|
+
|
29
|
+
An authentication token is automatically generated on first request, stored with timestamp and renewed every 800 seconds.
|
30
|
+
|
31
|
+
#### Getting started
|
32
|
+
|
33
|
+
Require the gem and initialize a new `RARBG::API` object.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
require 'rarbg'
|
37
|
+
|
38
|
+
rarbg = RARBG::API.new
|
39
|
+
```
|
40
|
+
|
41
|
+
#### Methods
|
42
|
+
|
43
|
+
Use `list` to list torrents.
|
44
|
+
Additional parameters are passed as keyword arguments and can be mixed together.
|
45
|
+
|
46
|
+
All successful method calls return an array of hashes.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
# List last 100 torrents.
|
50
|
+
rarbg.list(limit: 100)
|
51
|
+
|
52
|
+
# List all torrents with at least 20 seeders, sorted by seeders.
|
53
|
+
rarbg.list(min_seeders: 100, sort: :seeders)
|
54
|
+
|
55
|
+
# List torrents with extended json infos.
|
56
|
+
rarbg.list(format: :json_extended)
|
57
|
+
```
|
58
|
+
|
59
|
+
Use `search` to search torrents.
|
60
|
+
One search type parameter among `string`, `imdb`, `themoviedb` and `tvdb` is required.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
# Search torrents using literal string query.
|
64
|
+
rarbg.search(string: 'Force Awakens')
|
65
|
+
|
66
|
+
# Search by IMDB id, in `Movies/x264/1080` and `Movies/x264/720`.
|
67
|
+
# Note that 'tt' can be omitted when passing an IMDB id.
|
68
|
+
rarbg.search(imdb: 'tt2488496', category: [44, 45])
|
69
|
+
|
70
|
+
# Search unranked torrents by TheMovieDB id, sorted by last.
|
71
|
+
rarbg.search(themoviedb: 140607, ranked: false, sort: :last)
|
72
|
+
```
|
73
|
+
|
74
|
+
#### Errors
|
75
|
+
|
76
|
+
API endpoint errors will raise a `RARBG::APIError` exception with the API error message.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
rarbg.list(sort: :name)
|
80
|
+
# => RARBG::APIError: Invalid sort
|
81
|
+
|
82
|
+
rarbg.search(string: 'Star Wars', min_seeders: 'notanumber')
|
83
|
+
# => RARBG::APIError: Invalid value for min_seeders
|
84
|
+
|
85
|
+
rarbg.search(imdb: 'tt0121765')
|
86
|
+
# => RARBG::APIError: Service unavailable (503)
|
87
|
+
```
|
88
|
+
|
89
|
+
Parameter validation errors on client side will raise an `ArgumentError`.
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
rarbg.list('a string instead of an hash')
|
93
|
+
# => ArgumentError: Expected params hash
|
94
|
+
|
95
|
+
rarbg.search(limit: 50)
|
96
|
+
# => ArgumentError: At least one parameter required among string, imdb, tvdb, themoviedb for search mode.
|
97
|
+
```
|
98
|
+
|
99
|
+
## Contributing [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg?style=flat-square)](http://makeapullrequest.com)
|
100
|
+
|
101
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/epistrephein/rarbg).
|
102
|
+
|
103
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Code of Conduct](CODE_OF_CONDUCT.md).
|
104
|
+
|
105
|
+
You can contribute changes by forking the project and submitting a pull request. To get started:
|
106
|
+
|
107
|
+
1. Fork the repo
|
108
|
+
2. Install the dependencies (`bin/setup`)
|
109
|
+
3. Create your feature branch (`git checkout -b my-new-feature`)
|
110
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
111
|
+
5. Pass the test suite (`rake spec`)
|
112
|
+
6. Push to the branch (`git push origin my-new-feature`)
|
113
|
+
7. Create a new pull request
|
114
|
+
|
115
|
+
## License [![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)
|
116
|
+
This gem is released as open source under the terms of the [MIT License](LICENSE).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/rarbg.rb
CHANGED
@@ -1,123 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'faraday_middleware'
|
3
|
-
require 'json'
|
4
|
-
require 'time'
|
1
|
+
# frozen_string_literal: true
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
VERSION = '0.1.4'.freeze
|
9
|
-
APP_ID = 'rarbg-rubygem'.freeze
|
10
|
-
API_ENDPOINT = 'https://torrentapi.org/pubapi_v2.php'.freeze
|
11
|
-
TOKEN_EXPIRATION = 800
|
12
|
-
|
13
|
-
# Exception for low level request errors.
|
14
|
-
class RequestError < StandardError; end
|
15
|
-
# Exception for high level API errors.
|
16
|
-
class APIError < StandardError; end
|
17
|
-
|
18
|
-
# API class for performing requests.
|
19
|
-
class API
|
20
|
-
# API +token+ is stored with timestamped +token_time+.
|
21
|
-
attr_reader :token, :token_time
|
22
|
-
|
23
|
-
# Any API call passes +default_params+ unless overidden.
|
24
|
-
attr_accessor :default_params
|
25
|
-
|
26
|
-
# Returns a new API object with +@default_params+ defined in +params+.
|
27
|
-
def initialize(params = {})
|
28
|
-
@default_params = {
|
29
|
-
'limit' => 25,
|
30
|
-
'sort' => 'last',
|
31
|
-
'format' => 'json_extended'
|
32
|
-
}.merge!(params)
|
33
|
-
end
|
34
|
-
|
35
|
-
# Lists all torrents.
|
36
|
-
# Accepts query parameters from +params+.
|
37
|
-
# Returns an array of hashes.
|
38
|
-
def list(params = {})
|
39
|
-
call({ 'mode' => 'list' }, params)
|
40
|
-
end
|
41
|
-
|
42
|
-
# Searches torrents by literal name from +string+.
|
43
|
-
# Accepts query parameters from +params+.
|
44
|
-
# Returns an array of hashes of matching elements.
|
45
|
-
# Raises APIError if no results are found.
|
46
|
-
def search_string(string, params = {})
|
47
|
-
call({ 'mode' => 'search', 'search_string' => string }, params)
|
48
|
-
end
|
49
|
-
|
50
|
-
# Searches by IMDb ID from +imdbid+.
|
51
|
-
# Accepts query parameters from +params+.
|
52
|
-
# Returns an array of hashes of matching elements.
|
53
|
-
# Raises APIError if no results are found.
|
54
|
-
def search_imdb(imdbid, params = {})
|
55
|
-
imdbid = "tt#{imdbid}" unless imdbid =~ /^tt\d+$/
|
56
|
-
call({ 'mode' => 'search', 'search_imdb' => imdbid }, params)
|
57
|
-
end
|
58
|
-
|
59
|
-
# Searches by TVDB ID from +tvdbid+.
|
60
|
-
# Accepts query parameters from +params+.
|
61
|
-
# Returns an array of hashes of matching elements.
|
62
|
-
# Raises APIError if no results are found.
|
63
|
-
def search_tvdb(tvdbid, params = {})
|
64
|
-
call({ 'mode' => 'search', 'search_tvdb' => tvdbid }, params)
|
65
|
-
end
|
66
|
-
|
67
|
-
# Searches by The Movie Database ID from +themoviedbid+
|
68
|
-
# Accepts query parameters from +params+.
|
69
|
-
# Returns an array of hashes of matching elements.
|
70
|
-
# Raises APIError if no results are found.
|
71
|
-
def search_themoviedb(themoviedbid, params = {})
|
72
|
-
call({ 'mode' => 'search', 'search_themoviedb' => themoviedbid }, params)
|
73
|
-
end
|
74
|
-
|
75
|
-
private
|
76
|
-
|
77
|
-
# Performs API call.
|
78
|
-
def call(method_params, custom_params)
|
79
|
-
raise ArgumentError, 'not an Hash' unless custom_params.is_a?(Hash)
|
80
|
-
check_token
|
81
|
-
|
82
|
-
res = request.get do |req|
|
83
|
-
req.params.merge!(@default_params)
|
84
|
-
req.params.merge!(custom_params)
|
85
|
-
req.params.merge!(method_params)
|
86
|
-
|
87
|
-
req.params['app_id'] = APP_ID
|
88
|
-
req.params['token'] = @token
|
89
|
-
end
|
90
|
-
raise RequestError, res.reason_phrase unless res.success?
|
91
|
-
raise APIError, res.body['error'] if res.body['error']
|
92
|
-
|
93
|
-
res.body['torrent_results']
|
94
|
-
end
|
95
|
-
|
96
|
-
# Checks if +token+ is empty or expired.
|
97
|
-
def check_token
|
98
|
-
get_token if @token.nil? || (Time.now - @token_time) >= TOKEN_EXPIRATION
|
99
|
-
end
|
100
|
-
|
101
|
-
# Requests or renews API token.
|
102
|
-
def get_token
|
103
|
-
res = request.get do |req|
|
104
|
-
req.params['get_token'] = 'get_token'
|
105
|
-
end
|
106
|
-
raise RequestError, res.reason_phrase unless res.success?
|
107
|
-
raise APIError, res.body['error'] if res.body['error']
|
108
|
-
sleep 2
|
109
|
-
|
110
|
-
@token_time = Time.now
|
111
|
-
@token = res.body['token']
|
112
|
-
end
|
113
|
-
|
114
|
-
# Setups Faraday request.
|
115
|
-
def request
|
116
|
-
Faraday.new(url: API_ENDPOINT) do |faraday|
|
117
|
-
faraday.response :json
|
118
|
-
faraday.request :url_encoded
|
119
|
-
faraday.adapter Faraday.default_adapter
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
3
|
+
require 'rarbg/version'
|
4
|
+
require 'rarbg/api'
|