Class: YahooGroupData

Inherits:
Object
  • Object
show all
Defined in:
lib/yahoo-group-data.rb,
lib/yahoo-group-data/version.rb

Constant Summary collapse

VERSION =
"1.4.1"

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ YahooGroupData

Returns a new instance of YahooGroupData.



10
11
12
13
14
15
16
17
18
# File 'lib/yahoo-group-data.rb', line 10

def initialize(url)
	raise ArgumentError "A URL must be passed" unless url
	
	curb = Curl::Easy.new(url)
	curb.follow_location = true
	curb.http_get
	@html = curb.body_str.force_encoding('iso-8859-1').encode("UTF-8")
	@response_code = curb.response_code
end

Instance Method Details

#[](thing) ⇒ Object



24
25
26
27
# File 'lib/yahoo-group-data.rb', line 24

def [](thing)
	return unless respond_to? thing
	send(thing)
end

#age_restricted?Boolean

Returns:

  • (Boolean)


78
79
80
81
# File 'lib/yahoo-group-data.rb', line 78

def age_restricted?
	return nil if not_found? or matches_private?
	matches_age_restricted?
end

#categoryObject



95
96
97
98
# File 'lib/yahoo-group-data.rb', line 95

def category
	return unless has_category?
	@category ||= no_data? ? nil : doc.xpath('//*[@id="yginfo"]/ul/li[2]/a').inner_html
end

#descriptionObject



37
38
39
40
41
42
# File 'lib/yahoo-group-data.rb', line 37

def description
	element = doc.css('span.ygrp-grdescr')
	if element.size > 0
		doc.css('span.ygrp-grdescr').first.content.gsub(/\A[ยท\s]*/, "")
	end
end

#foundedObject



83
84
85
# File 'lib/yahoo-group-data.rb', line 83

def founded
	@founded ||= no_data? ? nil : Date.parse(date_str_to_english(doc.xpath("//ul[@class=\"ygrp-ul ygrp-info\"]//li[#{has_category? ? 3 : 2}]").inner_html.split(':')[1].strip))
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/yahoo-group-data.rb', line 20

def has_key?(key)
	respond_to? key
end

#languageObject



87
88
89
# File 'lib/yahoo-group-data.rb', line 87

def language
	@language ||= no_data? ? nil : doc.xpath("//ul[@class=\"ygrp-ul ygrp-info\"]//li[#{has_category? ? 4 : 3}]").inner_html.split(':')[1].strip
end

#nameObject



29
30
31
32
33
34
35
# File 'lib/yahoo-group-data.rb', line 29

def name
	@name ||= if not_found? || age_restricted?
			nil
		else
			doc.css('span.ygrp-pname').first.content
		end
end

#no_data?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/yahoo-group-data.rb', line 123

def no_data?
	private? or age_restricted? or not_found?
end

#not_found?Boolean

Returns:

  • (Boolean)


65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/yahoo-group-data.rb', line 65

def not_found?
	@not_found ||= (response_was_404? ||
		(
			(
				doc.xpath('/html/body/div[3]/div/div/div/h3').size > 0 and doc.xpath('/html/body/div[3]/div/div/div/h3').first.content.strip.match(/Group Not Found|Group nicht gefunden/i)
			) ||
			(
				doc.xpath('//*[@id="bodyID"]/div[4]/div/div/div/h3').inner_html.strip.match(/Group Not Found|Group nicht gefunden/i)
			)
		) ? true : false
	)
end

#num_membersObject



91
92
93
# File 'lib/yahoo-group-data.rb', line 91

def num_members
	@num_members ||= no_data? ? nil : Integer(doc.xpath('//ul[@class="ygrp-ul ygrp-info"]//li[1]').inner_html.split(':')[1])
end

#owner_emailObject



52
53
54
# File 'lib/yahoo-group-data.rb', line 52

def owner_email
	@owner_email ||= no_data? ? nil : doc.css('div#ygrp-links div.ygrp-contentblock').first.content.match(/(\S*-owner@[a-z]*yahoo[a-z]*\.[a-z\.]+)/)[1]
end

#post_emailObject



44
45
46
# File 'lib/yahoo-group-data.rb', line 44

def post_email
	@post_email ||= no_data? ? nil : subscribe_email.gsub("-subscribe@", "@")
end

#private?Boolean

Returns:

  • (Boolean)


60
61
62
63
# File 'lib/yahoo-group-data.rb', line 60

def private?
	return nil if not_found? || matches_age_restricted?
	matches_private?
end

#subscribe_emailObject



48
49
50
# File 'lib/yahoo-group-data.rb', line 48

def subscribe_email
	@subscribe_email ||= no_data? ? nil : doc.css('div#ygrp-links div.ygrp-contentblock').first.content.match(/(\S*-subscribe@[a-z]*yahoo[a-z]*\.[a-z\.]+)/)[1]
end

#to_jsonObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/yahoo-group-data.rb', line 100

def to_json

	data_methods = %w{
		private?
		not_found?
		age_restricted?
		name
		description
		post_email
		subscribe_email
		owner_email
		unsubscribe_email
		language
		num_members
		category
		founded
	}

	data_hash = {}
	data_methods.map {|dm| data_hash[dm.tr('?', '')] = send(dm)}
	Yajl::Encoder.encode(data_hash)
end

#unsubscribe_emailObject



56
57
58
# File 'lib/yahoo-group-data.rb', line 56

def unsubscribe_email
	@unsubscribe_email ||= no_data? ? nil : doc.css('div#ygrp-links div.ygrp-contentblock').first.content.match(/(\S*-unsubscribe@[a-z]*yahoo[a-z]*\.[a-z\.]+)/)[1]
end