Module: Processors::Tumblr

Includes:
LogAware
Defined in:
lib/processors/tumblr.rb

Overview

utilities for handling tumblr

Constant Summary collapse

GENERATOR =
%{tweetlr - http://tweetlr.5v3n.com}
API_ENDPOINT_TUMBLR =
'http://www.tumblr.com'

Class Method Summary collapse

Methods included from LogAware

log=

Class Method Details

.logObject



9
10
11
# File 'lib/processors/tumblr.rb', line 9

def self.log
  LogAware.log #TODO why doesn't the include make the log method accessible?
end

.post(options = {}) ⇒ Object

post a tumblr photo entry.

required arguments are :email, :password, :type, :date, :source, :caption, :state, :source

optional arguments: :api_endpoint_tumblr, :tags, :group



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/processors/tumblr.rb', line 18

def self.post(options={})
  tries = 3
  tags = options[:tags] || ''
  group = options[:group] || ''
  begin
    response = Curl::Easy.http_post("#{options[:api_endpoint_tumblr] || API_ENDPOINT_TUMBLR}/api/write", 
    Curl::PostField.content('generator', GENERATOR),
    Curl::PostField.content('email', options[:email]), 
    Curl::PostField.content('password', options[:password]),
    Curl::PostField.content('type', options[:type]),
    Curl::PostField.content('date', options[:date]),
    Curl::PostField.content('source', options[:source]),
    Curl::PostField.content('caption', options[:caption]),
    Curl::PostField.content('state', options[:state]),
    Curl::PostField.content('tags', tags),
    Curl::PostField.content('group', group)
    )
  rescue Curl::Err::CurlError => err
    log.error "Failure in Curl call: #{err}"
    tries -= 1
    sleep 3
    if tries > 0
        retry
    else
        response = nil
    end
  end
  response
end