rgroups 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/rgroups.rb +83 -4
  3. data/rgroups.gemspec +2 -2
  4. metadata +4 -4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -10,17 +10,23 @@ class RGroup
10
10
  @@POST_SETTINGS = '/manage_post'
11
11
  @@ADV_SETTINGS = '/manage_advanced'
12
12
  @@SPAM_SETTINGS = '/manage_spam'
13
+ @@BASE = 'https://groups.google.com'
14
+ @@GAFYD_BASE = 'https://groups.google.com/a/'
15
+ @@SUBS = '/groups/mysubs'
13
16
 
14
17
  def initialize(*gafyd)
15
18
  @scraper = Mechanize.new
16
19
  @scraper.reuse_ssl_sessions = false
17
20
  if (gafyd.length == 0)
18
- @BASE_URL = 'https://groups.google.com/group/'
21
+ @LIST_GROUPS = @@BASE + @@SUBS
22
+ @BASE_URL = @@BASE + '/group/'
19
23
  @LOGIN_URL = 'https://accounts.google.com/ServiceLogin?service=groups2&passive=1209600&continue=https://groups.google.com/&followup=https://groups.google.com/'
20
24
  else
21
- @BASE_URL = 'https://groups.google.com/a/' + gafyd[0] + "/group/"
22
- @LOGIN_URL = 'https://groups.google.com/a/' + gafyd[0]
23
- @GAFYD = true
25
+ @GAFYD = true
26
+ @GAFYD_DOMAIN = gafyd[0]
27
+ @LIST_GROUPS = @@GAFYD_BASE + @GAFYD_DOMAIN + @@SUBS
28
+ @BASE_URL = @@GAFYD_BASE + @GAFYD_DOMAIN + "/group/"
29
+ @LOGIN_URL = @@GAFYD_BASE + @GAFYD_DOMAIN
24
30
  end
25
31
  end
26
32
 
@@ -33,6 +39,79 @@ class RGroup
33
39
  @scraper.submit(f, f.buttons.first)
34
40
  end
35
41
 
42
+ # groups that the logged-in user is subscribed to
43
+ def subscribed_groups
44
+ page = @scraper.get(@LIST_GROUPS)
45
+ groups = []
46
+ page.search('//a[@class="on"]').each do |link|
47
+ parts = link[:href].split("/")
48
+ groups << parts[parts.length - 1]
49
+ end
50
+
51
+ groups
52
+ end
53
+
54
+ #search groups
55
+ #listing groups is not easy when scraping
56
+ #instead, you can search for one
57
+ #returns first 15 results, anything else is real slow
58
+ def search_groups(group)
59
+ if (@GAFYD)
60
+ page = @scraper.get(@@GAFYD_BASE + @GAFYD_DOMAIN)
61
+ else
62
+ page = @scraper.get(@@BASE)
63
+ end
64
+
65
+ form = page.form('gs2')
66
+ form.q = group
67
+ page = @scraper.submit(form, form.button_with(:name => "qt_s"))
68
+ groups = []
69
+ page.search('//a[@class="on"]').each do |link|
70
+ parts = link[:href].split("/")
71
+ parts = parts[parts.length - 1].split("?")
72
+ groups << parts[0] unless parts[0].eql?("advanced_search")
73
+ end
74
+
75
+ return nil if groups.length == 0
76
+ groups
77
+ end
78
+
79
+ #post a message to groups
80
+ def post_message(group, subject, message, send_copy=false, cc='')
81
+ page = @scraper.get(@BASE_URL + group + '/topics')
82
+ if (@GAFYD)
83
+ form = page.form_with(:action => '/a/' + @GAFYD_DOMAIN + '/group/' + group + "/post")
84
+ else
85
+ form = page.form_with(:action => "/group/" + group + "/post")
86
+ end
87
+ page = @scraper.submit(form, form.button_with(:value => "+ New post"))
88
+
89
+ form = page.form('postform')
90
+ form.cc = cc
91
+ form.subject = subject
92
+ form.body = message
93
+
94
+ if (send_copy)
95
+ form.checkbox_with(:name => 'bccme').check
96
+ end
97
+
98
+ @scraper.submit(form, form.button_with(:name => 'Action.Post'))
99
+ end
100
+
101
+ #lists the most recent topics in a group
102
+ def get_topics(group)
103
+ topics = {}
104
+ page = @scraper.get(@BASE_URL + group + '/topics?gvc=2')
105
+ page.search('//div[@class="maincontoutboxatt"]//table//a').each do |link|
106
+ unless(link[:class] == "st")
107
+ topics[link.inner_text.strip] = @@BASE + link[:href]
108
+ end
109
+ end
110
+
111
+ topics
112
+ end
113
+
114
+
36
115
  # add a user
37
116
  # email = email address to add
38
117
  # group = group name
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "rgroups"
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrew Hayworth"]
12
- s.date = "2012-06-18"
12
+ s.date = "2012-06-19"
13
13
  s.description = "This is a Ruby API for accessing and updating Google Groups. It's based on Mechanize, which means it's essentially screen-scraping."
14
14
  s.email = "ahayworth@gmail.com"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgroups
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Hayworth
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-18 00:00:00 Z
18
+ date: 2012-06-19 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  requirement: &id001 !ruby/object:Gem::Requirement