Class: Rtlog::TwitPic
- Inherits:
-
Object
- Object
- Rtlog::TwitPic
- Defined in:
- lib/rtlog/archives.rb
Constant Summary collapse
- TWIT_REGEXP =
/http\:\/\/twitpic\.com\/([0-9a-zA-Z]+)/
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #download ⇒ Object
-
#initialize(config, url) ⇒ TwitPic
constructor
A new instance of TwitPic.
- #local_url ⇒ Object
- #original_thumbnail_url ⇒ Object
Constructor Details
#initialize(config, url) ⇒ TwitPic
Returns a new instance of TwitPic.
35 36 37 38 39 |
# File 'lib/rtlog/archives.rb', line 35 def initialize config, url @config = config @url = url @id = TWIT_REGEXP.match(url)[1] end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
32 33 34 |
# File 'lib/rtlog/archives.rb', line 32 def config @config end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
31 32 33 |
# File 'lib/rtlog/archives.rb', line 31 def id @id end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
33 34 35 |
# File 'lib/rtlog/archives.rb', line 33 def url @url end |
Instance Method Details
#download ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rtlog/archives.rb', line 49 def download file_path = File.( File.join(config['target_dir'], path) ) folder_path = File.dirname(file_path) FileUtils.mkdir_p(folder_path) unless File.exist?(folder_path) open(original_thumbnail_url) do |f| extname = File.extname( f.base_uri.path ) file_path = file_path + extname open(file_path, 'w') do |io| io.write f.read end end sleep 1 end |
#local_url ⇒ Object
45 46 47 |
# File 'lib/rtlog/archives.rb', line 45 def local_url "#{config['url_prefix']}#{path}" end |
#original_thumbnail_url ⇒ Object
41 42 43 |
# File 'lib/rtlog/archives.rb', line 41 def original_thumbnail_url "http://twitpic.com/show/thumb/#{id}" end |