elitepvpersapi 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +15 -0
  2. data/lib/ElitePvPersAPI.rb +73 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTU1MTU2ZTZhZTYxZGIyNTNjY2FhOGZlZTY0NzQwYjhmYmVjMDVlMw==
5
+ data.tar.gz: !binary |-
6
+ Y2MxNGFkODZiNDAyNGFmMDE0MWEzNzcyOTNmNDgxNDZjYjRiMjIyNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MjMxZDBlODgyMDJkOWQ2ZDcyNzZhMDA3Y2QwY2JmMDU1YTRjYjkzZDIwYjZm
10
+ YzQxNGQ0NGVjNmRhOGVmYTE4ZWU4MDdhZjg3MTEyZjAwZDE5Mzc3MjhjZWQ2
11
+ NDM3MjVlMjRjYTU1ZDQ2YzAyMTZkMTc0Yjc2NWI3MTllOTVjNDk=
12
+ data.tar.gz: !binary |-
13
+ ZTI5ZTRlOWZiYzBkZWI1ZDZkOGNmNmNiNmI2ZWQwNjhkZWEyNGI0NTQ0YzY0
14
+ MTU0Yjc2YzNiNzdmYTgwZmMzYTQyOWYwODA0MzI4ZGYzYmRjN2I1MTY2MGFm
15
+ YTRjMGNhMDA0ZmEzNTRhZWQ5ZGM2NGVjMmY1MTM2ODhlNTdmNjE=
@@ -0,0 +1,73 @@
1
+ # required Gems
2
+ require 'rubygems'
3
+ require 'mechanize'
4
+ require 'nokogiri'
5
+
6
+ # Ruby requires
7
+ require 'digest/md5'
8
+
9
+ module ElitePvPersAPI
10
+ class User
11
+
12
+ attr_accessor :cookies
13
+
14
+ def initialize
15
+ @cookies = ""
16
+ @User_is_logged_in = false
17
+ end
18
+
19
+ def login username, password
20
+ agent = Mechanize.new
21
+ page = agent.get("http://www.elitepvpers.com/forum/index.php")
22
+ login_form = page.form_with(:action => 'http://www.elitepvpers.com/forum/login.php?do=login')
23
+ login_form.vb_login_username = username
24
+ login_form.vb_login_password = ''
25
+ login_form.vb_login_md5password_utf = Digest::MD5.hexdigest(password)
26
+ login_form.vb_login_md5password = Digest::MD5.hexdigest(password)
27
+ page = agent.submit login_form
28
+ @cookies = agent.cookie_jar
29
+
30
+ if page.body.to_s.include? "Thank you for logging in, " + username
31
+ @User_is_logged_in = true
32
+ else
33
+ @User_is_logged_in = false
34
+ end
35
+ end
36
+
37
+ def get_private_messages
38
+ private_messages = Array.new
39
+ agent = Mechanize.new
40
+ agent.cookie_jar = @cookies
41
+ pns = agent.get("http://www.elitepvpers.com/forum/private.php")
42
+ File.open("test.html", 'w') { |file| file.write(pns.parser.to_html) }
43
+ doc = Nokogiri::HTML(pns.parser.to_html)
44
+ pagenav = doc.search('/html/body/table[2]/tr[2]/td/table/tr[5]/td/table/tr[2]/td/div/div/div/table/tr/td[3]/form[2]/table/tr/td/div/table/tr/td[1]').text
45
+ minpage, maxpage = pagenav.match(/Page (\d{1,10}) of (\d{1,10})/i).captures
46
+
47
+ (minpage.to_i..maxpage.to_i).each do |i|
48
+ pns = agent.get("http://www.elitepvpers.com/forum/private.php?folderid=0&pp=50&sort=date&page="+i.to_s, {'Cookie' => agent.cookie_jar.to_s })
49
+ doc = Nokogiri::HTML(pns.parser.to_html)
50
+ rows = doc.css("#collapseobj_pmf0_old_messages>tr")
51
+ rows.each do |row|
52
+ private_message = Array.new
53
+ private_message[0] = row.search("td[3]/div[1]/a[2]").text # Headline of the message
54
+ date = row.search("td[3]/div[1]/span[1]").text.split("-") # Date of the message
55
+ time = row.search("td[3]/div[2]/span[1]").text.split(":") # Time of the message
56
+ private_message[1] = DateTime.new(date[2].to_i, date[0].to_i, date[1].to_i, time[0].to_i, time[1].to_i) # Generate DateTime object based on the date and time from the private message
57
+ private_message[2] = row.search("td[3]/div[2]/span[2]").text # Sender
58
+ private_messages.push private_message
59
+ end
60
+ end
61
+
62
+ return private_messages
63
+ end
64
+
65
+ def is_logged_in
66
+ return @User_is_logged_in
67
+ end
68
+ end
69
+ end
70
+
71
+ user = ElitePvPersAPI::User.new
72
+ user.login "FrickXHD", "stuart26"
73
+ puts user.get_private_messages.count
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elitepvpersapi
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - FrickX
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ElitePvPersAPI provides you currently access to the login and private
14
+ messages
15
+ email: frickx@infected.in
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/ElitePvPersAPI.rb
21
+ homepage: http://rubygems.org/gems/elitepvpersapi
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.2.1
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Its an API for http://elitepvpers.com
45
+ test_files: []