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 +10 -5
- data/lib/twimage.rb +7 -2
- data/lib/twimage/version.rb +1 -1
- metadata +1 -1
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
|
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).
|
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.
|
32
|
-
|
33
|
-
|
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
|
-
|
42
|
+
[service[:service_match]].flatten.find do |regex|
|
43
|
+
url.match(regex)
|
44
|
+
end
|
40
45
|
end
|
41
46
|
end
|
42
47
|
|
data/lib/twimage/version.rb
CHANGED