Module: Tumblr::Client::Post

Included in:
Tumblr::Client
Defined in:
lib/tumblr/post.rb

Constant Summary collapse

@@standard_post_options =
[:state, :tags, :tweet, :date, :markdown, :slug]

Instance Method Summary collapse

Instance Method Details

#audio(blog_name, options = {}) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/tumblr/post.rb', line 84

def audio(blog_name, options={})
  valid_opts = @@standard_post_options + [:data, :caption, :external_url]
  if valid_options(valid_opts, options)
    options[:type] = "audio"
    if (options.has_key?(:data) && options.has_key?(:external_url))
      raise Exception, "You can only use one parameter, either data or external url."
    end
    if(options.has_key?(:data))
      options[:data] = File.open(options[:data],'rb').read()
    end
    post("v2/blog/#{blog_name}/post", options)
  end
end

#chat(blog_name, options = {}) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/tumblr/post.rb', line 76

def chat(blog_name, options={})
  valid_opts = @@standard_post_options + [:title, :conversation]
  if valid_options(valid_opts, options)
    options[:type] = "chat"
    post("v2/blog/#{blog_name}/post", options)
  end
end

#delete(blog_name, id) ⇒ Object



16
17
18
# File 'lib/tumblr/post.rb', line 16

def delete(blog_name, id)
  post("v2/blog/#{blog_name}/post/delete", {:id => id})  
end

#edit(blog_name, options = {}) ⇒ Object



7
8
9
# File 'lib/tumblr/post.rb', line 7

def edit(blog_name, options={})
  post("v2/blog/#{blog_name}/post/edit", options)  
end


68
69
70
71
72
73
74
# File 'lib/tumblr/post.rb', line 68

def link(blog_name, options={})
  valid_opts = @@standard_post_options + [:title, :url, :description]
  if valid_options(valid_opts, options)
    options[:type] = "link"
    post("v2/blog/#{blog_name}/post", options)
  end
end

#photo(blog_name, options = {}) ⇒ Object



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
47
48
49
50
# File 'lib/tumblr/post.rb', line 20

def photo(blog_name, options={})
  valid_opts = @@standard_post_options + [:caption, :link, :data, :source, :photoset_layout]
  if valid_options(valid_opts, options)
    options[:type] = "photo"
    if (options.has_key?(:data) && options.has_key?(:source))
      raise Exception, "You can only use one parameter, either source or data."
    end
    if options.has_key?(:source) && options[:source].kind_of?(Array)
      count = 0
      options[:source].each do |src|
        options["source[#{count}]"] = src
        count += 1
      end
      options.delete(:source)
    end
    if options.has_key?(:data)
      #Probably can be refactored
      if options[:data].kind_of?(Array)
        count = 0
        options[:data].each do |filepath|
          options["data[#{count}]"] = File.open(filepath, 'rb').read()
          count += 1
        end
        options.delete(:data)
      else
        options[:data] = File.open(options[:data],'rb').read()
      end
    end
    post("v2/blog/#{blog_name}/post", options)  
  end
end

#quote(blog_name, options = {}) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/tumblr/post.rb', line 52

def quote(blog_name, options={})
  valid_opts = @@standard_post_options + [:quote, :source]
  if valid_options(valid_opts, options)
    options[:type] = "quote"
    post("v2/blog/#{blog_name}/post", options)
  end
end

#reblog(blog_name, options = {}) ⇒ Object

Don’t be lazy and create a nice interface



12
13
14
# File 'lib/tumblr/post.rb', line 12

def reblog(blog_name, options={})
  post("v2/blog/#{blog_name}/post/reblog", options)  
end

#text(blog_name, options = {}) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/tumblr/post.rb', line 60

def text(blog_name, options={})
  valid_opts = @@standard_post_options + [:title, :body]
  if valid_options(valid_opts, options)
    options[:type] = "text"
    post("v2/blog/#{blog_name}/post", options)
  end
end

#video(blog_name, options = {}) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/tumblr/post.rb', line 98

def video(blog_name, options={})
  valid_opts = @@standard_post_options + [:data, :embed, :caption]
  if valid_options(valid_opts, options)
    options[:type] = "video"
    if (options.has_key?(:data) && options.has_key?(:embed))
      raise Exception, "You can only use one parameter, either data or embed."
    end
    if(options.has_key?(:data))
      options[:data] = File.open(options[:data],'rb').read()
    end
    post("v2/blog/#{blog_name}/post", options)
  end
end