twimage 0.1.0 → 0.1.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.
Files changed (4) hide show
  1. data/README.md +2 -1
  2. data/lib/twimage.rb +28 -9
  3. data/lib/twimage/version.rb +1 -1
  4. metadata +16 -8
data/README.md CHANGED
@@ -32,11 +32,12 @@ Enjoy!
32
32
 
33
33
  ## Support
34
34
 
35
- Twimage currently supports the following services:
35
+ Twimage currently supports the following photo services:
36
36
 
37
37
  * twitpic - http://twitpic.com
38
38
  * yfrog - http://yfrog.com
39
39
  * instagram - http://instagr.am
40
+ * twitter - http://twitter.com
40
41
 
41
42
  ## Contributing
42
43
 
@@ -17,14 +17,18 @@ module Twimage
17
17
  SERVICES = [{ :name => :twitpic,
18
18
  :service_match => /twitpic\.com/,
19
19
  :full_url_modifier => lambda { |url| url + '/full' },
20
- :image_css_match => 'body > img' },
20
+ :image_css_match => '#media-full img' },
21
21
  { :name => :yfrog,
22
22
  :service_match => /yfrog\.com/,
23
23
  :full_url_modifier => lambda { |url| url.gsub(/\.com/, '.com/z') },
24
24
  :image_css_match => '#the-image img' },
25
25
  { :name => :instagram,
26
26
  :service_match => [/instagr\.am/, /instagram\.com/],
27
- :image_css_match => '.photo'}]
27
+ :image_css_match => '.photo' },
28
+ { :name => :twitter,
29
+ #:full_url_modifier => lambda { |url| url + '/large' },
30
+ :service_match => /twitter\.com/,
31
+ :image_regex_match => /"media_url_https":"(.*?)"/}]
28
32
 
29
33
  def self.get(url)
30
34
  service_url = HTTParty.get(url, :headers => { 'User-Agent' => USER_AGENT }).request.path.to_s # first point HTTParty at this URL and follow any redirects to get to the final page
@@ -41,6 +45,8 @@ module Twimage
41
45
  def self.find_service(url)
42
46
  return SERVICES.find do |service|
43
47
  [service[:service_match]].flatten.find do |regex|
48
+ puts url
49
+ puts regex
44
50
  url.match(regex)
45
51
  end
46
52
  end
@@ -49,16 +55,27 @@ module Twimage
49
55
 
50
56
  # tear apart the HTML on the returned service page and find the source of the image
51
57
  def self.get_image_url(service, url)
58
+ image_url = nil
52
59
  # get the content of the image page
53
- begin
54
- image_tag = Nokogiri::HTML(open(url, 'User-Agent' => USER_AGENT)).css(service[:image_css_match]).first
55
- rescue OpenURI::HTTPError
56
- raise ServiceURLInvalid, "The service URL #{url} was not found (returned a 404)"
60
+ if service[:image_css_match]
61
+ begin
62
+ image_tag = Nokogiri::HTML(open(url, 'User-Agent' => USER_AGENT)).css(service[:image_css_match]).first
63
+ image_url = image_tag['src']
64
+ rescue OpenURI::HTTPError
65
+ raise ServiceURLInvalid, "The service URL #{url} was not found (returned a 404)"
66
+ end
67
+ # get the URL to the actual image file
68
+
69
+ elsif service[:image_regex_match]
70
+ begin
71
+ image_url = HTTParty.get(url, :headers => {'User-Agent' => USER_AGENT}).body.match(service[:image_regex_match])[1]
72
+ rescue OpenURI::HTTPError
73
+ raise ServiceURLInvalid, "The service URL #{url} was not found (returned a 404)"
74
+ end
57
75
  end
58
76
 
59
- # get the URL to the actual image file
60
- if image_tag
61
- return image_tag['src']
77
+ if image_url
78
+ return image_url
62
79
  else
63
80
  raise ImageNotFound, "The service URL #{url} did not contain an identifiable image"
64
81
  end
@@ -77,3 +94,5 @@ module Twimage
77
94
  end
78
95
 
79
96
  end
97
+
98
+ puts Twimage.get 'http://pic.twitter.com/GQk2RNI'
@@ -1,3 +1,3 @@
1
1
  module Twimage
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,8 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twimage
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 2
9
+ version: 0.1.2
6
10
  platform: ruby
7
11
  authors:
8
12
  - Rob Cameron
@@ -10,17 +14,18 @@ autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
16
 
13
- date: 2011-05-28 00:00:00 -07:00
17
+ date: 2012-02-08 00:00:00 -08:00
14
18
  default_executable:
15
19
  dependencies:
16
20
  - !ruby/object:Gem::Dependency
17
21
  name: nokogiri
18
22
  prerelease: false
19
23
  requirement: &id001 !ruby/object:Gem::Requirement
20
- none: false
21
24
  requirements:
22
25
  - - ">="
23
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
24
29
  version: "0"
25
30
  type: :runtime
26
31
  version_requirements: *id001
@@ -28,10 +33,11 @@ dependencies:
28
33
  name: httparty
29
34
  prerelease: false
30
35
  requirement: &id002 !ruby/object:Gem::Requirement
31
- none: false
32
36
  requirements:
33
37
  - - ">="
34
38
  - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
35
41
  version: "0"
36
42
  type: :runtime
37
43
  version_requirements: *id002
@@ -63,21 +69,23 @@ rdoc_options: []
63
69
  require_paths:
64
70
  - lib
65
71
  required_ruby_version: !ruby/object:Gem::Requirement
66
- none: false
67
72
  requirements:
68
73
  - - ">="
69
74
  - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
70
77
  version: "0"
71
78
  required_rubygems_version: !ruby/object:Gem::Requirement
72
- none: false
73
79
  requirements:
74
80
  - - ">="
75
81
  - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
76
84
  version: "0"
77
85
  requirements: []
78
86
 
79
87
  rubyforge_project: twimage
80
- rubygems_version: 1.6.2
88
+ rubygems_version: 1.3.6
81
89
  signing_key:
82
90
  specification_version: 3
83
91
  summary: A gem for pulling images from various Twitter image services