yahoo-group-data 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,4 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
- test/yahoo_pages/*.html
18
+ test/yahoo_pages/*.html
19
+ coverage
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # yahoo-group-data gem
2
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.
3
+ Yahoo doesn't provide an API to it's publicly available group info, so this gem covers that gap. Use it to find information about a Yahoo group such as name, description and relevant email addresses.
4
4
 
5
5
  ## Example
6
6
 
@@ -83,6 +83,8 @@ after that:
83
83
 
84
84
  $ rake test
85
85
 
86
+ Because of the dynamic nature of Yahoo groups it's quite possible that the number of members a group has in groups.yml will have diverged with the number of members in reality when you pull down the pages using "rake fetch_yahoo_pages". If you see any of these divergences just update groups.yml appropriately.
87
+
86
88
  ### If you find a group the gem fails on
87
89
 
88
90
  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.
@@ -1,3 +1,3 @@
1
1
  class YahooGroupData
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -4,6 +4,7 @@ require 'curb'
4
4
  require 'uri'
5
5
  require 'nokogiri'
6
6
  require 'date'
7
+ require 'yajl'
7
8
 
8
9
  class YahooGroupData
9
10
  def initialize(url)
@@ -16,7 +17,11 @@ class YahooGroupData
16
17
  end
17
18
 
18
19
  def name
19
- @name ||= no_data? ? nil : doc.css('span.ygrp-pname').first.content
20
+ @name ||= if not_found? || age_restricted?
21
+ nil
22
+ else
23
+ doc.css('span.ygrp-pname').first.content
24
+ end
20
25
  end
21
26
 
22
27
  def description
@@ -43,10 +48,8 @@ class YahooGroupData
43
48
  end
44
49
 
45
50
  def private?
46
- @private_group ||= (
47
- doc.xpath('/html/body/div[3]/center/p/big').size > 0 and
48
- doc.xpath('/html/body/div[3]/center/p/big').first.content.strip.match(/Sorry, this group is available to members ONLY./i)
49
- ) ? true : false
51
+ return nil if not_found? || matches_age_restricted?
52
+ matches_private?
50
53
  end
51
54
 
52
55
  def not_found?
@@ -59,7 +62,8 @@ class YahooGroupData
59
62
  end
60
63
 
61
64
  def age_restricted?
62
- @age_restricted ||= (doc.xpath('/html/body/div[3]/div/div/div/h4').size > 0 and doc.xpath('/html/body/div[3]/div/div/div/h4').first.inner_html.strip.match(/You've reached an Age-Restricted Area/i)) ? true : false
65
+ return nil if not_found? or matches_private?
66
+ matches_age_restricted?
63
67
  end
64
68
 
65
69
  def founded
@@ -71,16 +75,50 @@ class YahooGroupData
71
75
  end
72
76
 
73
77
  def num_members
74
- Integer(doc.xpath('//ul[@class="ygrp-ul ygrp-info"]//li[1]').inner_html.split(':')[1].strip)
78
+ @num_members ||= no_data? ? nil : Integer(doc.xpath('//ul[@class="ygrp-ul ygrp-info"]//li[1]').inner_html.split(':')[1])
75
79
  end
76
80
 
77
81
  def category
78
82
  return unless has_category?
79
- doc.xpath('/html/body/div[3]/table/tr/td/div[2]/div[2]/div/ul/li[2]/a').inner_html
83
+ @category ||= no_data? ? nil : doc.xpath('/html/body/div[3]/table/tr/td/div[2]/div[2]/div/ul/li[2]/a').inner_html
84
+ end
85
+
86
+ def to_json
87
+
88
+ data_methods = %w{
89
+ private?
90
+ not_found?
91
+ age_restricted?
92
+ name
93
+ description
94
+ post_email
95
+ subscribe_email
96
+ owner_email
97
+ unsubscribe_email
98
+ language
99
+ num_members
100
+ category
101
+ founded
102
+ }
103
+
104
+ data_hash = {}
105
+ data_methods.map {|dm| data_hash[dm.tr('?', '')] = send(dm)}
106
+ Yajl::Encoder.encode(data_hash)
80
107
  end
81
108
 
82
109
  private
83
110
 
111
+ def matches_private?
112
+ @matches_private ||= (
113
+ doc.xpath('/html/body/div[3]/center/p/big').size > 0 and
114
+ doc.xpath('/html/body/div[3]/center/p/big').first.content.strip.match(/Sorry, this group is available to members ONLY./i)
115
+ ) ? true : false
116
+ end
117
+
118
+ def matches_age_restricted?
119
+ @matches_age_restricted ||= (doc.xpath('/html/body/div[3]/div/div/div/h4').size > 0 and doc.xpath('/html/body/div[3]/div/div/div/h4').first.inner_html.strip.match(/You've reached an Age-Restricted Area/i)) ? true : false
120
+ end
121
+
84
122
  def no_data?
85
123
  private? or age_restricted? or not_found?
86
124
  end
data/test/groups.yml CHANGED
@@ -8,7 +8,7 @@ groups:
8
8
  not_found: false
9
9
  private: false
10
10
  age_restricted: false
11
- founded: Jun 24, 2008
11
+ founded: 2008-06-24
12
12
  language: English
13
13
  num_members: 151
14
14
  category: COBOL
@@ -25,9 +25,9 @@ groups:
25
25
  not_found: false
26
26
  private: false
27
27
  age_restricted: false
28
- founded: Aug 24, 2011
28
+ founded: 2011-08-24
29
29
  language: English
30
- num_members: 160
30
+ num_members: 164
31
31
  category: Recycling
32
32
  post_email: Cambridge-Freegle@yahoogroups.com
33
33
  subscribe_email: Cambridge-Freegle-subscribe@yahoogroups.com
@@ -93,7 +93,7 @@ groups:
93
93
  not_found: false
94
94
  private: false
95
95
  age_restricted: false
96
- founded: Sep 13, 2009
96
+ founded: 2009-09-13
97
97
  language: English
98
98
  num_members: 1
99
99
  category: Recycling
@@ -110,9 +110,9 @@ groups:
110
110
  not_found: false
111
111
  private: false
112
112
  age_restricted: false
113
- founded: Mar 30, 2007
113
+ founded: 2007-03-30
114
114
  language: English
115
- num_members: 2985
115
+ num_members: 2973
116
116
  category:
117
117
  post_email: redcar-cleveland-freegle@yahoogroups.com
118
118
  subscribe_email: redcar-cleveland-freegle-subscribe@yahoogroups.com
@@ -120,14 +120,14 @@ groups:
120
120
  unsubscribe_email: redcar-cleveland-freegle-unsubscribe@yahoogroups.com
121
121
 
122
122
  # Foreign language, particularly for the date format
123
- - id:
123
+ - id: freecycle-michelstadt
124
124
  url: http://de.groups.yahoo.com/group/freecycle-michelstadt/
125
125
  name: freecycle-michelstadt
126
126
  description: Freecycle Michelstadt / Odenwald
127
127
  not_found: false
128
128
  private: false
129
129
  age_restricted: false
130
- founded: Mai 6, 2004
130
+ founded: 2004-05-06
131
131
  language: Deutsch
132
132
  num_members: 63
133
133
  category: Kostenlos
data/test/test_helper.rb CHANGED
@@ -1,13 +1,7 @@
1
1
  # encoding: utf-8
2
- def date_str_to_english(date_str)
3
- date_str.
4
- gsub(/ene/i, "Jan").
5
- gsub(/fév|fev/i, "Feb").
6
- gsub(/mar|mrz/i, "Mar").
7
- gsub(/avr|abr/i, "Apr").
8
- gsub(/mai|maj/i, "May").
9
- gsub(/aoû|ago/i, "Aug").
10
- gsub(/set/i, "Sep").
11
- gsub(/okt|out/i, "Oct").
12
- gsub(/déc|dez|dic/i, "Dec")
13
- end
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ add_filter "/test/"
6
+ add_filter "lib/yahoo-group-data/version.rb"
7
+ end
@@ -3,8 +3,35 @@ require 'test_helper'
3
3
  require 'webmock/test_unit'
4
4
  require 'yahoo-group-data'
5
5
  require 'date'
6
+ require 'yajl'
6
7
 
7
8
  class YahooGroupDataTest < Test::Unit::TestCase
9
+
10
+ def test_to_json
11
+ YAML.load_file('test/groups.yml')["groups"].each do |original_group|
12
+ stub_request(:get, original_group["url"]).
13
+ to_return(:status => 200, :body => File.read("test/yahoo_pages/#{original_group['id']}.html"), :headers => {})
14
+
15
+ g = YahooGroupData.new(original_group["url"])
16
+ puts original_group["url"]
17
+ data = Yajl::Parser.parse(g.to_json)
18
+
19
+ assert_equal original_group['private'], data['private']
20
+ assert_equal original_group['not_found'], data['not_found']
21
+ assert_equal original_group['age_restricted'], data['age_restricted']
22
+ assert_equal original_group['name'], data['name']
23
+ assert_equal original_group['description'], data['description']
24
+ assert_equal original_group['post_email'], data['post_email']
25
+ assert_equal original_group['subscribe_email'], data['subscribe_email']
26
+ assert_equal original_group['owner_email'], data['owner_email']
27
+ assert_equal original_group['unsubscribe_email'], data['unsubscribe_email']
28
+ assert_equal (original_group['founded'].nil? ? nil : original_group['founded'].strftime('%Y-%m-%d')), data['founded']
29
+ assert_equal original_group['language'], data['language']
30
+ assert_equal original_group['num_members'], data['num_members']
31
+ assert_equal original_group['category'], data['category']
32
+ end
33
+ end
34
+
8
35
  def test_initialize_with_invalid_params
9
36
  assert_raise(ArgumentError) { YahooGroupData.new }
10
37
  end
@@ -37,36 +64,25 @@ class YahooGroupDataTest < Test::Unit::TestCase
37
64
  # (see the README on how to download them)
38
65
  # then runs the assertions on each one.
39
66
  def test_data_extraction
40
- groups = YAML.load_file('test/groups.yml')["groups"]
41
- groups.each do |g_data|
67
+ YAML.load_file('test/groups.yml')["groups"].each do |g_data|
42
68
  puts "fetching #{g_data["url"]}"
43
69
  stub_request(:get, g_data["url"]).
44
70
  to_return(:status => 200, :body => File.read("test/yahoo_pages/#{g_data['id']}.html"), :headers => {})
45
71
 
46
72
  group = YahooGroupData.new(g_data["url"])
47
- if g_data["not_found"]
48
- assert_equal g_data["not_found"], group.not_found?
49
- elsif g_data["private"]
50
- assert_equal g_data["not_found"], group.not_found?
51
- assert_equal g_data["private"], group.private?
52
- elsif g_data["age_restricted"]
53
- assert_equal g_data["not_found"], group.not_found?
54
- assert_equal g_data["age_restricted"], group.age_restricted?
55
- else
56
- assert_equal g_data["age_restricted"], group.age_restricted?
57
- assert_equal g_data["private"], group.private?
58
- assert_equal g_data["not_found"], group.not_found?
59
- assert_equal g_data["name"], group.name
60
- assert_equal g_data["description"], group.description
61
- assert_equal g_data["post_email"], group.post_email
62
- assert_equal g_data["subscribe_email"], group.subscribe_email
63
- assert_equal g_data["owner_email"], group.owner_email
64
- assert_equal g_data["unsubscribe_email"], group.unsubscribe_email
65
- assert_equal Date.parse(date_str_to_english(g_data["founded"])), group.founded
66
- assert_equal g_data["language"], group.language
67
- assert_equal g_data["num_members"], group.num_members
68
- assert_equal g_data["category"], group.category
69
- end
73
+ assert_equal g_data["age_restricted"], group.age_restricted?
74
+ assert_equal g_data["private"], group.private?
75
+ assert_equal g_data["not_found"], group.not_found?
76
+ assert_equal g_data["name"], group.name
77
+ assert_equal g_data["description"], group.description
78
+ assert_equal g_data["post_email"], group.post_email
79
+ assert_equal g_data["subscribe_email"], group.subscribe_email
80
+ assert_equal g_data["owner_email"], group.owner_email
81
+ assert_equal g_data["unsubscribe_email"], group.unsubscribe_email
82
+ assert_equal g_data["founded"], group.founded
83
+ assert_equal g_data["language"], group.language
84
+ assert_equal g_data["num_members"], group.num_members
85
+ assert_equal g_data["category"], group.category
70
86
  end
71
87
  end
72
88
  end
@@ -16,6 +16,8 @@ Gem::Specification.new do |gem|
16
16
  gem.version = YahooGroupData::VERSION
17
17
 
18
18
  gem.add_dependency 'nokogiri', '~> 1.5'
19
+ gem.add_dependency 'yajl-ruby', '~> 1.1'
19
20
  gem.add_dependency 'curb', '~> 0.8'
20
21
  gem.add_development_dependency 'webmock'
22
+ gem.add_development_dependency 'simplecov'
21
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yahoo-group-data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-29 00:00:00.000000000 Z
12
+ date: 2012-02-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &70145628826300 !ruby/object:Gem::Requirement
16
+ requirement: &70311668310240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,21 @@ dependencies:
21
21
  version: '1.5'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70145628826300
24
+ version_requirements: *70311668310240
25
+ - !ruby/object:Gem::Dependency
26
+ name: yajl-ruby
27
+ requirement: &70311668309540 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '1.1'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70311668309540
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: curb
27
- requirement: &70145628825740 !ruby/object:Gem::Requirement
38
+ requirement: &70311668308520 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ~>
@@ -32,10 +43,21 @@ dependencies:
32
43
  version: '0.8'
33
44
  type: :runtime
34
45
  prerelease: false
35
- version_requirements: *70145628825740
46
+ version_requirements: *70311668308520
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: webmock
38
- requirement: &70145628825320 !ruby/object:Gem::Requirement
49
+ requirement: &70311668308100 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70311668308100
58
+ - !ruby/object:Gem::Dependency
59
+ name: simplecov
60
+ requirement: &70311668307600 !ruby/object:Gem::Requirement
39
61
  none: false
40
62
  requirements:
41
63
  - - ! '>='
@@ -43,7 +65,7 @@ dependencies:
43
65
  version: '0'
44
66
  type: :development
45
67
  prerelease: false
46
- version_requirements: *70145628825320
68
+ version_requirements: *70311668307600
47
69
  description: A lib to fetch public Yahoo group data
48
70
  email:
49
71
  - will@willj.net