Class: RubyGazelle::Gazelle

Inherits:
Object
  • Object
show all
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

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(, username, password)
  @username = username
  response = Net::HTTP.post_form(URI(), {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(options, &block)
  options[:site] ||= 'https://ssl.what.cd'

  options[:login] ||= '/login.php'

  #throw exception for not providing username if !options[:username] || !options[:password]

  base_uri options[:site]

  gazelle_connection = new("#{options[:site]}#{options[:login]}", options[:username], options[:password])

  if block_given?
    gazelle_connection.instance_eval(&block)
  end

  gazelle_connection
end

Instance Method Details

#announcementsObject



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(options = {})
  make_request(REQUESTS[:bookmarks], options)
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, options = {})
  make_request(REQUESTS[:forum], {:forumid => id}.merge(options))
end

#forum_categoriesObject



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(options = {})
  make_request(REQUESTS[:forum_thread], options)
end

#inbox(options = {}) ⇒ Object



52
53
54
# File 'lib/gazelle/base.rb', line 52

def inbox(options = {})
  make_request(REQUESTS[:inbox], options)
end

#indexObject



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(options = {})
  make_request(REQUESTS[:notifications], options)
end

#request(id, options = {}) ⇒ Object



106
107
108
# File 'lib/gazelle/base.rb', line 106

def request(id, options = {})
  make_request(REQUESTS[:request], {:id => id}.merge(options))
end

#rippyObject



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, options)
  type = type.to_sym
  if type == :users
    make_request(REQUESTS[:user_search], options)
  elsif type == :requests
    make_request(REQUESTS[:request_search], options)
  elsif type == :torrents
    make_request(REQUESTS[:torrent_search], options)
  else
    throw Exception
  end
end

#subscriptions(options = {}) ⇒ Object



82
83
84
# File 'lib/gazelle/base.rb', line 82

def subscriptions(options = {})
  make_request(REQUESTS[:subscriptions], options)
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