Class: RubyGazelle::Gazelle
- Inherits:
-
Object
- Object
- RubyGazelle::Gazelle
- Includes:
- HTTParty
- Defined in:
- lib/gazelle/base.rb
Constant Summary collapse
- REQUESTS =
{index: '/ajax.php?action=index', user_profile: '/ajax.php?action=user', inbox: '/ajax.php?action=inbox', conversation: '/ajax.php?action=inbox&type=viewconv', top10: '/ajax.php?action=top10', user_search: '/ajax.php?action=usersearch', request_search: '/ajax.php?action=requests', torrent_search: '/ajax.php?action=browse', bookmarks: '/ajax.php?action=bookmarks', subscriptions: '/ajax.php?action=subscriptions', forum_categories: '/ajax.php?action=forum&type=main', forum: '/ajax.php?action=forum&type=viewforum', forum_thread: '/ajax.php?action=forum&type=viewthread', artist: '/ajax.php?action=artist', torrent_group: '/ajax.php?action=torrentgroup', request: '/ajax.php?action=request', notifications: '/ajax.php?action=notifications', rippy: '/ajax.php?action=rippy&format=json', announcement: '/ajax.php?action=announcements'}
Class Method Summary collapse
Instance Method Summary collapse
- #announcements ⇒ Object
- #artist(id) ⇒ Object
- #bookmarks(options = {}) ⇒ Object
- #conversation(id) ⇒ Object
- #forum(id, options = {}) ⇒ Object
- #forum_categories ⇒ Object
- #forum_thread(options = {}) ⇒ Object
- #inbox(options = {}) ⇒ Object
- #index ⇒ Object
-
#initialize(login_page, username, password) ⇒ Gazelle
constructor
A new instance of Gazelle.
- #notifications(options = {}) ⇒ Object
- #request(id, options = {}) ⇒ Object
- #rippy ⇒ Object
- #search(type, options) ⇒ Object
- #subscriptions(options = {}) ⇒ Object
- #top(limit = 10, type) ⇒ Object
- #torrent_group(id) ⇒ Object
- #user(id) ⇒ Object
Constructor Details
#initialize(login_page, username, password) ⇒ Gazelle
Returns a new instance of Gazelle.
20 21 22 23 24 |
# File 'lib/gazelle/base.rb', line 20 def initialize(login_page, username, password) @username = username response = Net::HTTP.post_form(URI(login_page), {username: username, password: password}) @cookie = response['Set-Cookie'] end |
Class Method Details
.connect(options, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gazelle/base.rb', line 26 def self.connect(, &block) [:site] ||= 'https://ssl.what.cd' [:login] ||= '/login.php' #throw exception for not providing username if !options[:username] || !options[:password] base_uri [:site] gazelle_connection = new("#{[:site]}#{[:login]}", [:username], [:password]) if block_given? gazelle_connection.instance_eval(&block) end gazelle_connection end |
Instance Method Details
#announcements ⇒ Object
118 119 120 |
# File 'lib/gazelle/base.rb', line 118 def announcements make_request("#{REQUESTS[:announcement]}") end |
#artist(id) ⇒ Object
98 99 100 |
# File 'lib/gazelle/base.rb', line 98 def artist(id) make_request(REQUESTS[:artist], :id => id) end |
#bookmarks(options = {}) ⇒ Object
78 79 80 |
# File 'lib/gazelle/base.rb', line 78 def bookmarks( = {}) make_request(REQUESTS[:bookmarks], ) end |
#conversation(id) ⇒ Object
56 57 58 |
# File 'lib/gazelle/base.rb', line 56 def conversation(id) make_request(REQUESTS[:conversation], :id => id) end |
#forum(id, options = {}) ⇒ Object
90 91 92 |
# File 'lib/gazelle/base.rb', line 90 def forum(id, = {}) make_request(REQUESTS[:forum], {:forumid => id}.merge()) end |
#forum_categories ⇒ Object
86 87 88 |
# File 'lib/gazelle/base.rb', line 86 def forum_categories make_request(REQUESTS[:forum_categories]) end |
#forum_thread(options = {}) ⇒ Object
94 95 96 |
# File 'lib/gazelle/base.rb', line 94 def forum_thread( = {}) make_request(REQUESTS[:forum_thread], ) end |
#inbox(options = {}) ⇒ Object
52 53 54 |
# File 'lib/gazelle/base.rb', line 52 def inbox( = {}) make_request(REQUESTS[:inbox], ) end |
#index ⇒ Object
48 49 50 |
# File 'lib/gazelle/base.rb', line 48 def index make_request(REQUESTS[:index]) end |
#notifications(options = {}) ⇒ Object
110 111 112 |
# File 'lib/gazelle/base.rb', line 110 def notifications( = {}) make_request(REQUESTS[:notifications], ) end |
#request(id, options = {}) ⇒ Object
106 107 108 |
# File 'lib/gazelle/base.rb', line 106 def request(id, = {}) make_request(REQUESTS[:request], {:id => id}.merge()) end |
#rippy ⇒ Object
114 115 116 |
# File 'lib/gazelle/base.rb', line 114 def rippy self.class.get(REQUESTS[:rippy], :headers => {'Cookie' => @cookie})['rippy'] end |
#search(type, options) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/gazelle/base.rb', line 65 def search(type, ) type = type.to_sym if type == :users make_request(REQUESTS[:user_search], ) elsif type == :requests make_request(REQUESTS[:request_search], ) elsif type == :torrents make_request(REQUESTS[:torrent_search], ) else throw Exception end end |
#subscriptions(options = {}) ⇒ Object
82 83 84 |
# File 'lib/gazelle/base.rb', line 82 def subscriptions( = {}) make_request(REQUESTS[:subscriptions], ) end |
#top(limit = 10, type) ⇒ Object
60 61 62 63 |
# File 'lib/gazelle/base.rb', line 60 def top(limit = 10, type) #Users returns empty results. make_request(REQUESTS[:top10], :type => type, :limit => limit) end |
#torrent_group(id) ⇒ Object
102 103 104 |
# File 'lib/gazelle/base.rb', line 102 def torrent_group(id) make_request(REQUESTS[:torrent_group], :id => id) end |
#user(id) ⇒ Object
44 45 46 |
# File 'lib/gazelle/base.rb', line 44 def user(id) make_request(REQUESTS[:user_profile], :id => id) end |