yahoo-group-data 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ test/yahoo_pages/*.html
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Will Jessop
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # yahoo-group-data gem
2
+
3
+ Yahoo doesn't provide an API to it's publicly available group info, so this gem covers that gap. Use it to find out the publicly available group information of a Yahoo group such as name, description and relevant email addresses.
4
+
5
+ ## Example
6
+
7
+ ``` ruby
8
+ require 'yahoo-group-data'
9
+
10
+ g = YahooGroupData.new("http://tech.groups.yahoo.com/group/OneStopCOBOL/")
11
+
12
+ name = g.name
13
+ description = g.description
14
+
15
+ p = g.post_email
16
+ s = g.subscribe_email
17
+ u = g.unsubscribe_email
18
+ o = g.unsubscribe_email
19
+ ```
20
+
21
+ ## Requirements
22
+
23
+ It's tested with Ruby 1.9.3, it probably works with older versions.
24
+
25
+ ## Installation
26
+
27
+ Add this line to your application's Gemfile:
28
+
29
+ gem 'yahoo-group-data'
30
+
31
+ And then execute:
32
+
33
+ $ bundle
34
+
35
+ Or install it yourself as:
36
+
37
+ $ gem install yahoo-group-data
38
+
39
+ ## TODO
40
+
41
+ * Parse out
42
+ * * Number of members
43
+ * * Founded date
44
+ * * Category
45
+ * * Language
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create new Pull Request
54
+
55
+ *pull requests with tests are more likely to be accepted*
56
+
57
+ ### Testing
58
+
59
+ Rather than distribute a load of Yahoo's HTML pages with the gem there's a rake task to get the ones that are needed. Run:
60
+
61
+ `rake fetch_yahoo_pages`
62
+
63
+ after that:
64
+
65
+ rake test
66
+
67
+ ### If you find a group the gem fails on
68
+
69
+ Tell me about it, or (in preference) update the gem (Hint: start by adding an entry to the groups.yml file), see contributing instructions above.
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ end
9
+
10
+ desc "Run tests"
11
+ task :default => :test
12
+
13
+ desc "Fetch Yahoo Group pages for fixtures"
14
+ task :fetch_yahoo_pages do
15
+ require 'yaml'
16
+ require 'curb'
17
+ groups = YAML.load_file('test/groups.yml')["groups"]
18
+ total_groups = 0
19
+ groups.each do |g|
20
+ curb = Curl::Easy.new(g["url"])
21
+ curb.follow_location = true
22
+ curb.http_get
23
+
24
+ File.open("test/yahoo_pages/#{g['id']}.html", "w") {|f| f.write curb.body_str }
25
+ print "."
26
+ total_groups += 1
27
+ end
28
+ puts
29
+ puts "#{total_groups} group pages fetched"
30
+ end
@@ -0,0 +1,3 @@
1
+ class YahooGroupData
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+ require 'yahoo-group-data/version'
3
+ require 'curb'
4
+ require 'uri'
5
+ require 'nokogiri'
6
+
7
+ class YahooGroupData
8
+ def initialize(url)
9
+ raise ArgumentError "A URL must be passed" unless url
10
+
11
+ curb = Curl::Easy.new(url)
12
+ curb.follow_location = true
13
+ curb.http_get
14
+ @html = curb.body_str
15
+ end
16
+
17
+ def name
18
+ doc.css('span.ygrp-pname').first.content
19
+ end
20
+
21
+ def description
22
+ element = doc.css('span.ygrp-grdescr')
23
+ if element.size > 0
24
+ doc.css('span.ygrp-grdescr').first.content.gsub(/\A[·\s]*/, "")
25
+ end
26
+ end
27
+
28
+ def post_email
29
+ subscribe_email.gsub("-subscribe@", "@")
30
+ end
31
+
32
+ def subscribe_email
33
+ doc.css('div#ygrp-links div.ygrp-contentblock').first.content.match(/(\S*-subscribe@[a-z]*yahoo[a-z]*\.[a-z\.]+)/)[1]
34
+ end
35
+
36
+ def owner_email
37
+ doc.css('div#ygrp-links div.ygrp-contentblock').first.content.match(/(\S*-owner@[a-z]*yahoo[a-z]*\.[a-z\.]+)/)[1]
38
+ end
39
+
40
+ def unsubscribe_email
41
+ doc.css('div#ygrp-links div.ygrp-contentblock').first.content.match(/(\S*-unsubscribe@[a-z]*yahoo[a-z]*\.[a-z\.]+)/)[1]
42
+ end
43
+
44
+ def private?
45
+ @private_group ||= (
46
+ not_found_element = doc.xpath('/html/body/div[3]/center/p/big')
47
+ not_found_element.size > 0 and not_found_element.first.content.strip.match(/Sorry, this group is available to members ONLY./i) ? true : false
48
+ )
49
+ end
50
+
51
+ def defunct?
52
+ @defunct ||= (
53
+ not_found_element = doc.xpath('/html/body/div[3]/div/div/div/h3')
54
+ not_found_element.size > 0 and not_found_element.first.content.strip.match(/Group Not Found|Group nicht gefunden/i) ? true : false
55
+ )
56
+ end
57
+
58
+ private
59
+
60
+ attr_reader :html, :doc, :defunct #, :private_group
61
+
62
+ def doc
63
+ @doc ||= Nokogiri::HTML(html)
64
+ end
65
+ end
data/test/groups.yml ADDED
@@ -0,0 +1,40 @@
1
+ ---
2
+ groups:
3
+ - id: OneStopCOBOL
4
+ url: http://tech.groups.yahoo.com/group/OneStopCOBOL/
5
+ name: OneStopCOBOL
6
+ description: OneStopCOBOL - Official COBOL group
7
+ defunct: false
8
+ post_email: OneStopCOBOL@yahoogroups.com
9
+ subscribe_email: OneStopCOBOL-subscribe@yahoogroups.com
10
+ owner_email: OneStopCOBOL-owner@yahoogroups.com
11
+ unsubscribe_email: OneStopCOBOL-unsubscribe@yahoogroups.com
12
+
13
+ - id: Cambridge-Freegle
14
+ url: http://groups.yahoo.com/group/Cambridge-Freegle/
15
+ name: Cambridge-Freegle
16
+ description:
17
+ defunct: false
18
+ post_email: Cambridge-Freegle@yahoogroups.com
19
+ subscribe_email: Cambridge-Freegle-subscribe@yahoogroups.com
20
+ owner_email: Cambridge-Freegle-owner@yahoogroups.com
21
+ unsubscribe_email: Cambridge-Freegle-unsubscribe@yahoogroups.com
22
+
23
+ - id: Freecycle_MV
24
+ url: http://groups.yahoo.com/group/Freecycle_MV/
25
+ defunct: true
26
+
27
+ - id: blackpool-freecycle
28
+ url: http://groups.yahoo.com/group/blackpool-freecycle/
29
+ defunct: false
30
+ private: true
31
+
32
+ - id: Dursleyfreecycle
33
+ url: http://groups.yahoo.com/group/Dursleyfreecycle/
34
+ name: DursleyFreecycle
35
+ description: DursleyFreecycle(R)
36
+ defunct: false
37
+ post_email: DursleyFreecycle@yahoogroups.co.uk
38
+ subscribe_email: DursleyFreecycle-subscribe@yahoogroups.co.uk
39
+ owner_email: DursleyFreecycle-owner@yahoogroups.co.uk
40
+ unsubscribe_email: DursleyFreecycle-unsubscribe@yahoogroups.co.uk
@@ -0,0 +1,56 @@
1
+ require 'test/unit'
2
+ require 'webmock/test_unit'
3
+ require 'yahoo-group-data'
4
+
5
+ class YahooGroupDataTest < Test::Unit::TestCase
6
+ def test_initialize_with_invalid_params
7
+ assert_raise(ArgumentError) { YahooGroupData.new }
8
+ end
9
+
10
+ def test_initialize_with_valid_params
11
+ url = "http://tech.groups.yahoo.com/group/OneStopCOBOL/"
12
+
13
+ stub_request(:get, url).
14
+ to_return(:status => 200, :body => "", :headers => {})
15
+
16
+ g = YahooGroupData.new(url)
17
+ assert_equal g.class, YahooGroupData
18
+ assert_requested :get, url
19
+ end
20
+
21
+ def test_handling_redirects
22
+ url = "http://tech.groups.yahoo.com/group/OneStopCOBOL"
23
+ stub_request(:get, url).
24
+ to_return(:status => 302, :headers => { 'Location' => "#{url}/" })
25
+ stub_request(:get, "#{url}/").
26
+ to_return(:status => 200, :body => "", :headers => {})
27
+
28
+ g = YahooGroupData.new(url)
29
+ assert_equal g.class, YahooGroupData
30
+ assert_requested :get, url
31
+ assert_requested :get, "#{url}/"
32
+ end
33
+
34
+ # This method will loop over all the html files
35
+ # (see the README on how to download them)
36
+ # then runs the assertions on each one.
37
+ def test_data_extraction
38
+ groups = YAML.load_file('test/groups.yml')["groups"]
39
+ groups.each do |g_data|
40
+ puts "fetching #{g_data["url"]}"
41
+ stub_request(:get, g_data["url"]).
42
+ to_return(:status => 200, :body => File.read("test/yahoo_pages/#{g_data['id']}.html"), :headers => {})
43
+
44
+ group = YahooGroupData.new(g_data["url"])
45
+ unless g_data["defunct"] or g_data["private"]
46
+ assert_equal g_data["name"], group.name
47
+ assert_equal g_data["description"], group.description
48
+ assert_equal g_data["post_email"], group.post_email
49
+ assert_equal g_data["subscribe_email"], group.subscribe_email
50
+ assert_equal g_data["owner_email"], group.owner_email
51
+ assert_equal g_data["unsubscribe_email"], group.unsubscribe_email
52
+ end
53
+ assert_equal g_data["defunct"], group.defunct?
54
+ end
55
+ end
56
+ end
File without changes
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/yahoo-group-data/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Will Jessop"]
6
+ gem.email = ["will@willj.net"]
7
+ gem.description = %q{A lib to fetch public Yahoo group data}
8
+ gem.summary = %q{A lib to fetch the publicly available Yahoo group data from a Yahoo groups page}
9
+ gem.homepage = "https://github.com/wjessop/yahoo-group-data"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "yahoo-group-data"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = YahooGroupData::VERSION
17
+
18
+ gem.add_dependency 'nokogiri', '~> 1.5'
19
+ gem.add_dependency 'curb', '~> 0.8'
20
+ gem.add_development_dependency 'webmock'
21
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yahoo-group-data
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Will Jessop
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: &70185747420720 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.5'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70185747420720
25
+ - !ruby/object:Gem::Dependency
26
+ name: curb
27
+ requirement: &70185747420160 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '0.8'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70185747420160
36
+ - !ruby/object:Gem::Dependency
37
+ name: webmock
38
+ requirement: &70185747419720 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70185747419720
47
+ description: A lib to fetch public Yahoo group data
48
+ email:
49
+ - will@willj.net
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - lib/yahoo-group-data.rb
60
+ - lib/yahoo-group-data/version.rb
61
+ - test/groups.yml
62
+ - test/test_yahoo_group_data.rb
63
+ - test/yahoo_pages/.gitkeep
64
+ - yahoo-group-data.gemspec
65
+ homepage: https://github.com/wjessop/yahoo-group-data
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.10
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: A lib to fetch the publicly available Yahoo group data from a Yahoo groups
89
+ page
90
+ test_files:
91
+ - test/groups.yml
92
+ - test/test_yahoo_group_data.rb
93
+ - test/yahoo_pages/.gitkeep