twimage 0.0.1
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/.gitignore +4 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/README.md +24 -0
- data/Rakefile +2 -0
- data/lib/twimage.rb +16 -0
- data/lib/twimage/base.rb +18 -0
- data/lib/twimage/twitpic.rb +21 -0
- data/lib/twimage/version.rb +3 -0
- data/twimage.gemspec +24 -0
- metadata +87 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2@twimage && rvm wrapper 1.9.2@twimage textmate
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Twimage
|
2
|
+
|
3
|
+
Twimage provides an easy way to pull raw images from the various Twitter photo image services (twitpic, yfrog, etc.)
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Add twimage to your Gemfile:
|
8
|
+
|
9
|
+
gem 'twimage'
|
10
|
+
|
11
|
+
Instantiate the appropriate service and give it the standard URL returned by that service:
|
12
|
+
|
13
|
+
result = Twimage::Twitpic.new('http://twitpic.com/4w30yx')
|
14
|
+
|
15
|
+
Twimage will create a Ruby tempfile with the image. To get the tempfile:
|
16
|
+
|
17
|
+
result.image
|
18
|
+
|
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!
|
21
|
+
|
22
|
+
## Contributing
|
23
|
+
|
24
|
+
To add a parser, fork this repo and then send me a pull request, that's it!
|
data/Rakefile
ADDED
data/lib/twimage.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'httparty'
|
4
|
+
require 'tempfile'
|
5
|
+
require_relative './twimage/base'
|
6
|
+
Dir.glob('./twimage/*').each { |f| require_relative f }
|
7
|
+
|
8
|
+
module Twimage
|
9
|
+
|
10
|
+
class ServiceURLInvalid < StandardError; end # thrown if the service_url returns a 404
|
11
|
+
class ImageNotFound < StandardError; end # thrown if the service_url doesn't contain an image
|
12
|
+
class ImageURLInvalid < StandardError; end # thrown if the image_url found in the service_url returns a 404
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
# puts Twimage::Twitpic.new('http://twitpic.com/4w30yx').image.inspect
|
data/lib/twimage/base.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Twimage
|
2
|
+
class Base
|
3
|
+
|
4
|
+
attr_accessor :image, :image_url, :service_url
|
5
|
+
|
6
|
+
def initialize(service_url)
|
7
|
+
response = HTTParty.get(@image_url)
|
8
|
+
puts response.code
|
9
|
+
if response.code == 200
|
10
|
+
@image = Tempfile.new(['twimage','.jpg'])
|
11
|
+
@image << response.body
|
12
|
+
else
|
13
|
+
raise ImageURLInvalid, "The image_url #{@image_url} was not found (returned a 404)"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Twimage
|
2
|
+
class Twitpic < Twimage::Base
|
3
|
+
|
4
|
+
def initialize(service_url)
|
5
|
+
@service_url = service_url
|
6
|
+
begin
|
7
|
+
image_tag = Nokogiri::HTML(open(@service_url)).css('#photo-display').first
|
8
|
+
rescue OpenURI::HTTPError
|
9
|
+
raise ServiceURLInvalid, "The service URL #{@service_url} was not found (returned a 404)"
|
10
|
+
end
|
11
|
+
|
12
|
+
if image_tag
|
13
|
+
@image_url = image_tag['src']
|
14
|
+
super
|
15
|
+
else
|
16
|
+
raise ImageNotFound, "The service URL #{@service_url} did not contain an identifiable image"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/twimage.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "twimage/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "twimage"
|
7
|
+
s.version = Twimage::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Rob Cameron"]
|
10
|
+
s.email = ["cannikinn@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{A gem for pulling images from various Twitter image services}
|
13
|
+
s.description = %q{This gem will programatically grab images from a bunch of the most used Twitter image services}
|
14
|
+
|
15
|
+
s.rubyforge_project = "twimage"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency 'nokogiri'
|
23
|
+
s.add_dependency 'httparty'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twimage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Rob Cameron
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-11 00:00:00 -04:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: nokogiri
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
description: This gem will programatically grab images from a bunch of the most used Twitter image services
|
39
|
+
email:
|
40
|
+
- cannikinn@gmail.com
|
41
|
+
executables: []
|
42
|
+
|
43
|
+
extensions: []
|
44
|
+
|
45
|
+
extra_rdoc_files: []
|
46
|
+
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .rvmrc
|
50
|
+
- Gemfile
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/twimage.rb
|
54
|
+
- lib/twimage/base.rb
|
55
|
+
- lib/twimage/twitpic.rb
|
56
|
+
- lib/twimage/version.rb
|
57
|
+
- twimage.gemspec
|
58
|
+
has_rdoc: true
|
59
|
+
homepage: ""
|
60
|
+
licenses: []
|
61
|
+
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project: twimage
|
82
|
+
rubygems_version: 1.6.2
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: A gem for pulling images from various Twitter image services
|
86
|
+
test_files: []
|
87
|
+
|