twinkit 0.0.1 → 0.0.2
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/lib/twinkit.rb +21 -11
- metadata +7 -7
data/lib/twinkit.rb
CHANGED
@@ -4,6 +4,9 @@ require "open-uri"
|
|
4
4
|
require "nokogiri"
|
5
5
|
|
6
6
|
module Twinkit
|
7
|
+
|
8
|
+
# create a Struct called Twink
|
9
|
+
Twink = Struct.new(:url, :title, :redir_url)
|
7
10
|
|
8
11
|
def self.get_links(name)
|
9
12
|
tweets = Twitter.user_timeline(name)
|
@@ -16,22 +19,29 @@ module Twinkit
|
|
16
19
|
|
17
20
|
# parse links from tweets
|
18
21
|
twink = /((http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w!:.?+=&%@!\-\/]))?)/
|
19
|
-
|
20
22
|
link = tweet_text.scan(twink)
|
21
|
-
|
22
23
|
link_array = []
|
23
24
|
|
24
25
|
link.each do |l|
|
25
|
-
|
26
|
-
link_and_title = [] << l[0]
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
begin
|
28
|
+
s = Twink.new(l[0])
|
29
|
+
# link_and_title = [] << l[0]
|
30
|
+
URI.parse(l[0]).open do |f|
|
31
|
+
body = f.read
|
32
|
+
doc = Nokogiri::HTML.parse(body)
|
33
|
+
s.title = doc.title
|
34
|
+
# link_and_title << doc.title
|
35
|
+
end
|
36
|
+
s.redir_url = Net::HTTP.get_response(URI.parse(l[0]))['location']
|
37
|
+
# link_and_title << Net::HTTP.get_response(URI.parse(l[0]))['location']
|
38
|
+
link_array << s
|
39
|
+
rescue => e
|
40
|
+
case e
|
41
|
+
when URI::InvalidURIError
|
42
|
+
p "invalid URL #{l[0]}"
|
43
|
+
end
|
44
|
+
end
|
35
45
|
end
|
36
46
|
|
37
47
|
return link_array
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twinkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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: 2011-12-
|
12
|
+
date: 2011-12-10 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: twitter
|
16
|
-
requirement: &
|
16
|
+
requirement: &70294069193760 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70294069193760
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: nokogiri
|
27
|
-
requirement: &
|
27
|
+
requirement: &70294069193200 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70294069193200
|
36
36
|
description: parses all links and titles of the links from any twitter user
|
37
37
|
email: karlgusner@gmail.com
|
38
38
|
executables: []
|
@@ -40,7 +40,7 @@ extensions: []
|
|
40
40
|
extra_rdoc_files: []
|
41
41
|
files:
|
42
42
|
- lib/twinkit.rb
|
43
|
-
homepage:
|
43
|
+
homepage: https://github.com/ramz15/twinkit
|
44
44
|
licenses: []
|
45
45
|
post_install_message:
|
46
46
|
rdoc_options: []
|