swdyh-avaticon 0.0.4 → 0.0.5
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.
- data/Rakefile +1 -2
- data/lib/avaticon.rb +26 -1
- data/test/avaticon_test.rb +1 -1
- metadata +7 -7
data/Rakefile
CHANGED
@@ -17,14 +17,13 @@ DESCRIPTION = "A library for getting web service user icon."
|
|
17
17
|
RUBYFORGE_PROJECT = "avaticon"
|
18
18
|
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
19
19
|
BIN_FILES = %w( )
|
20
|
-
VERS = "0.0.
|
20
|
+
VERS = "0.0.5"
|
21
21
|
|
22
22
|
REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
23
23
|
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
24
24
|
RDOC_OPTS = [
|
25
25
|
'--title', "#{NAME} documentation",
|
26
26
|
"--charset", "utf-8",
|
27
|
-
"--opname", "index.html",
|
28
27
|
"--line-numbers",
|
29
28
|
"--main", "README.rdoc",
|
30
29
|
"--inline-source",
|
data/lib/avaticon.rb
CHANGED
@@ -10,6 +10,8 @@ class Avaticon
|
|
10
10
|
|
11
11
|
def initialize opt = {}
|
12
12
|
@siteinfo = []
|
13
|
+
@tw_id = opt[:tw_id]
|
14
|
+
@tw_pw = opt[:tw_pw]
|
13
15
|
(opt[:siteinfo_path] || DEFAULT_SITEINFO_PATH).each do |i|
|
14
16
|
load_siteinfo i
|
15
17
|
end
|
@@ -39,7 +41,8 @@ class Avaticon
|
|
39
41
|
info = @siteinfo.find { |i| i['service_name'] == service }
|
40
42
|
if info
|
41
43
|
url = info['iconPageUrl'].gsub('{user_id}', user_id)
|
42
|
-
|
44
|
+
html = Avaticon.get_html(url, :tw_id => @tw_id, :tw_pw => @tw_pw)
|
45
|
+
icon = Nokogiri::HTML(html).at(info['iconImageElement'])
|
43
46
|
if icon
|
44
47
|
Avaticon.path2url url, icon['src']
|
45
48
|
end
|
@@ -74,5 +77,27 @@ class Avaticon
|
|
74
77
|
(tmp[0..(tmp.size - 2)] << path).join('/')
|
75
78
|
end
|
76
79
|
end
|
80
|
+
|
81
|
+
def self.get_html url, opt = {}
|
82
|
+
if /twitter.com/ === url
|
83
|
+
Avaticon.get_tw_html url, opt
|
84
|
+
else
|
85
|
+
open(url).read
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.get_tw_html url, opt = {}
|
90
|
+
require 'mechanize'
|
91
|
+
agent = WWW::Mechanize.new
|
92
|
+
agent.user_agent_alias = 'Mac Safari'
|
93
|
+
page = agent.get'http://twitter.com/login'
|
94
|
+
login_form = page.forms.find { |i|
|
95
|
+
i.action == 'https://twitter.com/sessions'
|
96
|
+
}
|
97
|
+
login_form.fields.find { |i| i.name == 'session[username_or_email]'}.value = opt[:tw_id]
|
98
|
+
login_form.fields.find { |i| i.name == 'session[password]'}.value = opt[:tw_pw]
|
99
|
+
login_form.submit
|
100
|
+
agent.get(url).body
|
101
|
+
end
|
77
102
|
end
|
78
103
|
|
data/test/avaticon_test.rb
CHANGED
@@ -11,7 +11,7 @@ class AvaticonTest < Test::Unit::TestCase
|
|
11
11
|
def prepare_stubs service, user_id
|
12
12
|
unless REMOTE_TEST
|
13
13
|
path = File.join(MOCK_HTML_DIR, [service, user_id].join('_'))
|
14
|
-
|
14
|
+
Avaticon.stubs(:get_html).returns(IO.read(path))
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swdyh-avaticon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- swdyh
|
@@ -9,11 +9,12 @@ autorequire: ""
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-09-22 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: hpricot
|
17
|
+
type: :runtime
|
17
18
|
version_requirement:
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
19
20
|
requirements:
|
@@ -47,16 +48,15 @@ files:
|
|
47
48
|
- test/test_helper.rb
|
48
49
|
- lib/avaticon.rb
|
49
50
|
- lib/siteinfo.json
|
50
|
-
has_rdoc:
|
51
|
+
has_rdoc: false
|
51
52
|
homepage: http://avaticon.rubyforge.org
|
53
|
+
licenses:
|
52
54
|
post_install_message:
|
53
55
|
rdoc_options:
|
54
56
|
- --title
|
55
57
|
- avaticon documentation
|
56
58
|
- --charset
|
57
59
|
- utf-8
|
58
|
-
- --opname
|
59
|
-
- index.html
|
60
60
|
- --line-numbers
|
61
61
|
- --main
|
62
62
|
- README.rdoc
|
@@ -80,9 +80,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
80
|
requirements: []
|
81
81
|
|
82
82
|
rubyforge_project: avaticon
|
83
|
-
rubygems_version: 1.
|
83
|
+
rubygems_version: 1.3.5
|
84
84
|
signing_key:
|
85
|
-
specification_version:
|
85
|
+
specification_version: 3
|
86
86
|
summary: A library for getting web service user icon.
|
87
87
|
test_files:
|
88
88
|
- test/test_helper.rb
|