twimage 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -10,14 +10,17 @@ Add twimage to your Gemfile:
10
10
 
11
11
  Instantiate the appropriate service and give it the standard URL returned by that service:
12
12
 
13
- result = Twimage::Twitpic.new('http://twitpic.com/4w30yx')
13
+ result = Twimage.get('http://instagr.am/p/EHqLG/')
14
14
 
15
15
  Twimage will create a Ruby tempfile with the image. To get the tempfile:
16
16
 
17
17
  result.tempfile
18
18
 
19
19
  Save the image to your local system, upload to S3, etc. As soon as there are no more references to the
20
- tempfile in your code it will be unlinked (deleted). Enjoy!
20
+ tempfile in your code it will be unlinked (deleted). There are a couple additional instance variables
21
+ you have access to--try result.inspect to take a look.
22
+
23
+ Enjoy!
21
24
 
22
25
  ## Support
23
26
 
@@ -25,9 +28,11 @@ Twimage currently supports the following services:
25
28
 
26
29
  * twitpic - http://twitpic.com
27
30
  * yfrog - http://yfrog.com
31
+ * instagram - http://instagr.am
28
32
 
29
33
  ## Contributing
30
34
 
31
- To add a parser, fork this repo and then send me a pull request. Your parser should make a reasonable attempt to
32
- retrieve the highest resolution image possible and return errors if the service URL returns a 404 or the proper
33
- image tag couldn't be found (see twitpic.rb for an example).
35
+ To add a parser, fork this repo and then send me a pull request. You should attempt to get the highest resolution
36
+ version of the image possible, which isn't always available at the link posted to Twitter. Check out the `SERVICES`
37
+ constant in `twimage.rb` for examples of `lambda`s used to modify the original `service_url` to get to the full res
38
+ version's URL.
data/lib/twimage.rb CHANGED
@@ -20,7 +20,10 @@ module Twimage
20
20
  { :name => :yfrog,
21
21
  :service_match => /yfrog\.com/,
22
22
  :full_url_modifier => lambda { |url| url.gsub(/\.com/, '.com/z') },
23
- :image_css_match => '#the-image img' }]
23
+ :image_css_match => '#the-image img' },
24
+ { :name => :instagram,
25
+ :service_match => [/instagr\.am/, /instagram\.com/],
26
+ :image_css_match => '.photo'}]
24
27
 
25
28
  def self.get(url)
26
29
  service_url = HTTParty.get(url).request.path.to_s # first point HTTParty at this URL and follow any redirects to get to the final page
@@ -36,7 +39,9 @@ module Twimage
36
39
  # figure out which service this is by matching against regexes
37
40
  def self.find_service(url)
38
41
  return SERVICES.find do |service|
39
- url.match(service[:service_match])
42
+ [service[:service_match]].flatten.find do |regex|
43
+ url.match(regex)
44
+ end
40
45
  end
41
46
  end
42
47
 
@@ -1,3 +1,3 @@
1
1
  module Twimage
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: twimage
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.12
5
+ version: 0.0.13
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rob Cameron