twitter-photos 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +3 -0
  2. data/VERSION +1 -1
  3. data/lib/twitter-photos.rb +92 -2
  4. metadata +26 -2
data/Rakefile CHANGED
@@ -11,8 +11,11 @@ begin
11
11
  gem.homepage = "http://github.com/bookis/twitter-photos"
12
12
  gem.authors = ["bookis"]
13
13
  gem.add_development_dependency "thoughtbot-shoulda"
14
+ gem.add_dependency 'nokogiri'
15
+ gem.add_dependency 'typhoeus'
14
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
17
  end
18
+ Jeweler::GemcutterTasks.new
16
19
  rescue LoadError
17
20
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
21
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -1,5 +1,95 @@
1
1
  module TwitterPhotos
2
- def self.get_photos_by()
3
- puts 'hello world'
2
+ require 'typhoeus'
3
+ require 'nokogiri'
4
+ def self.get_photos_by(username)
5
+ @pix = []
6
+ hydra = Typhoeus::Hydra.new
7
+
8
+ third_request = Typhoeus::Request.new("http://twitpic.com/photos/#{username}", :timeout => 5000)
9
+ third_request.on_complete do |response|
10
+ twitpics = Nokogiri.parse(response.body)
11
+ twitpics.xpath("//div[@class='profile-photo-img']/a").each do |row|
12
+ url = row[:href]
13
+ twitpic_request = Typhoeus::Request.new("http://twitpic.com#{url}", :timeout => 5000)
14
+ twitpic_request.on_complete do |twitpic|
15
+ begin
16
+ twitpic = Nokogiri.parse(twitpic.body)
17
+ pic = []
18
+ pic << "http://twitpic.com/show/thumb#{url}.jpg"
19
+ pic << twitpic.xpath("//div/div[@id='view-photo-caption']").text
20
+ pic << twitpic.xpath("//div/div[@id='photo-info']").text
21
+ pic << twitpic.at_xpath("//img[@class='photo']")[:src]
22
+ @pix << pic
23
+ rescue
24
+ end
25
+ end
26
+ hydra.queue twitpic_request
27
+ end
28
+ end
29
+
30
+ first_request = Typhoeus::Request.new("http://yfrog.com/froggy.php", :params => {:username => username}, :timeout => 5000)
31
+ first_request.on_complete do |response|
32
+ yfrogs = Nokogiri.parse(response.body)
33
+ yfrogs.xpath("//div[@class='timeline_entry']").each do |row|
34
+ url = row.at_xpath("div/div[@class='thumbtweet' ]/a")[:href]
35
+ yfrog_request = Typhoeus::Request.new(url, :timeout => 5000)
36
+ yfrog_request.on_complete do |yfrog|
37
+ begin
38
+ yfrog = Nokogiri.parse(yfrog.body)
39
+ pic = []
40
+ pic << yfrog.at_xpath("//meta[@property='og:title']").attributes['content'].to_s + '.th.jpg'
41
+ pic << yfrog.at_xpath("///div[@class='twittertweet']/div/div/div").text rescue pic << ''
42
+ pic << yfrog.at_xpath("///div[@class='twittertweet']/div/div/div/div").text rescue pic << ''
43
+ pic << yfrog.at_xpath("//img[@id='main_image']")[:src]
44
+ @pix << pic
45
+ rescue
46
+ end
47
+ end
48
+ hydra.queue yfrog_request
49
+ end
50
+ end
51
+
52
+ second_request = Typhoeus::Request.new("http://tweetphotoapi.com/api/tpapi.svc/json/users/#{username}", :timeout => 5000)
53
+ second_request.on_complete do |response|
54
+ if response.code == 200
55
+ tweetphoto_id = JSON.parse(response.body)["Id"]
56
+ tweetphoto_user_request = Typhoeus::Request.new("http://tweetphotoapi.com/api/tpapi.svc/json/users/#{tweetphoto_id}/photos", :timeout => 5000)
57
+ tweetphoto_user_request.on_complete do |tweetphoto_user|
58
+ tweetphotodata = JSON.parse(tweetphoto_user.body)
59
+ tweetphotodata['List'].each do |tweetphoto|
60
+ pic = []
61
+ pic << tweetphoto['ThumbnailUrl']
62
+ pic << tweetphoto['Message']
63
+ pic << tweetphoto['UploadDateString']
64
+ pic << tweetphoto['MediumImageUrl']
65
+ @pix << pic
66
+ end
67
+ end
68
+ hydra.queue tweetphoto_user_request
69
+ end
70
+ end
71
+
72
+ forth_request = Typhoeus::Request.new("http://twitgoo.com/api/user/timeline/#{username}", :params => {:format => 'json'}, :timeout => 5000)
73
+ forth_request.on_complete do |response|
74
+ if response.code == 200
75
+ twitgoo = JSON.parse(response.body)
76
+ twitgoo['media'].each do |twit|
77
+ pic = []
78
+ pic << twit['thumburl']
79
+ pic << twit['text']
80
+ pic << twit['created_at']
81
+ pic << twit['imageurl']
82
+ @pix << pic
83
+ end
84
+ end
85
+ end
86
+
87
+ hydra.queue first_request
88
+ hydra.queue second_request
89
+ hydra.queue third_request
90
+ hydra.queue forth_request
91
+ hydra.run
92
+
93
+ return @pix
4
94
  end
5
95
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 0
8
7
  - 1
9
- version: 0.0.1
8
+ - 0
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - bookis
@@ -29,6 +29,30 @@ dependencies:
29
29
  version: "0"
30
30
  type: :development
31
31
  version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: nokogiri
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ name: typhoeus
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ type: :runtime
55
+ version_requirements: *id003
32
56
  description: This gem allows you to use any twitter username to return an array of photo urls, with corresponding tweets, dates and thumbnails
33
57
  email: vegan.bookis@gmail.com
34
58
  executables: []