Class: Rtlog::TwitPic

Inherits:
Object
  • Object
show all
Defined in:
lib/rtlog/archives.rb

Constant Summary collapse

TWIT_REGEXP =
/http\:\/\/twitpic\.com\/([0-9a-zA-Z]+)/

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configObject (readonly)

Returns the value of attribute config.



32
33
34
# File 'lib/rtlog/archives.rb', line 32

def config
  @config
end

#idObject (readonly)

Returns the value of attribute id.



31
32
33
# File 'lib/rtlog/archives.rb', line 31

def id
  @id
end

#urlObject (readonly)

Returns the value of attribute url.



33
34
35
# File 'lib/rtlog/archives.rb', line 33

def url
  @url
end

Instance Method Details

#downloadObject



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.expand_path( 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_urlObject



45
46
47
# File 'lib/rtlog/archives.rb', line 45

def local_url
  "#{config['url_prefix']}#{path}"
end

#original_thumbnail_urlObject



41
42
43
# File 'lib/rtlog/archives.rb', line 41

def original_thumbnail_url
  "http://twitpic.com/show/thumb/#{id}"
end