Module: Tumblr::Post

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

Constant Summary collapse

STANDARD_POST_OPTIONS =
[:state, :tags, :tweet, :date, :markdown, :slug, :format]
DATA_POST_TYPES =
[:audio, :video, :photo]
VALID_POST_TYPES =
DATA_POST_TYPES + [:quote, :text, :link, :chat]

Instance Method Summary collapse

Instance Method Details

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



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

def audio(blog_name, options = {})
  valid_opts = STANDARD_POST_OPTIONS + [:data, :caption, :external_url]
  validate_options(valid_opts, options)
  validate_no_collision options, [:data, :external_url]

  options[:type] = 'audio'
  extract_data!(options)
  post(post_path(blog_name), options)
end

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



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

def chat(blog_name, options = {})
  valid_opts = STANDARD_POST_OPTIONS + [:title, :conversation]
  validate_options(valid_opts, options)

  options[:type] = 'chat'
  post(post_path(blog_name), options)
end

#create_post(type, blog_name, options = {}) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/tumblr/post.rb', line 88

def create_post(type, blog_name, options = {})
  if VALID_POST_TYPES.include?(type)
    send(type, blog_name, options)
  else
    raise ArgumentError.new "\"#{type}\" is not a valid post type"
  end
end

#delete(blog_name, id) ⇒ Object



21
22
23
# File 'lib/tumblr/post.rb', line 21

def delete(blog_name, id)
  post(blog_path(blog_name, 'post/delete'), :id => id)
end

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



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

def edit(blog_name, options = {})
  convert_source_array :source, options
  extract_data!(options) if DATA_POST_TYPES.include?(options[:type])

  post(blog_path(blog_name, 'post/edit'), options)
end


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

def link(blog_name, options = {})
  valid_opts = STANDARD_POST_OPTIONS + [:title, :url, :description]
  validate_options(valid_opts, options)

  options[:type] = 'link'
  post(post_path(blog_name), options)
end

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



25
26
27
28
29
30
31
32
33
34
# File 'lib/tumblr/post.rb', line 25

def photo(blog_name, options = {})
  valid_opts = STANDARD_POST_OPTIONS + [:caption, :link, :data, :source, :photoset_layout]
  validate_options(valid_opts, options)
  validate_no_collision options, [:data, :source]
  convert_source_array :source, options

  options[:type] = 'photo'
  extract_data!(options)
  post(post_path(blog_name), options)
end

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



36
37
38
39
40
41
42
# File 'lib/tumblr/post.rb', line 36

def quote(blog_name, options = {})
  valid_opts = STANDARD_POST_OPTIONS + [:quote, :source]
  validate_options(valid_opts, options)

  options[:type] = 'quote'
  post(post_path(blog_name), options)
end

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



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

def reblog(blog_name, options = {})
  post(blog_path(blog_name, 'post/reblog'), options)
end

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



44
45
46
47
48
49
50
# File 'lib/tumblr/post.rb', line 44

def text(blog_name, options = {})
  valid_opts = STANDARD_POST_OPTIONS + [:title, :body]
  validate_options(valid_opts, options)

  options[:type] = 'text'
  post(post_path(blog_name), options)
end

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



78
79
80
81
82
83
84
85
86
# File 'lib/tumblr/post.rb', line 78

def video(blog_name, options = {})
  valid_opts = STANDARD_POST_OPTIONS + [:data, :embed, :caption]
  validate_options(valid_opts, options)
  validate_no_collision options, [:data, :embed]

  options[:type] = 'video'
  extract_data!(options)
  post(post_path(blog_name), options)
end