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
- #audio(blog_name, options = {}) ⇒ Object
- #chat(blog_name, options = {}) ⇒ Object
- #delete(blog_name, id) ⇒ Object
- #edit(blog_name, options = {}) ⇒ Object
- #link(blog_name, options = {}) ⇒ Object
- #photo(blog_name, options = {}) ⇒ Object
- #quote(blog_name, options = {}) ⇒ Object
-
#reblog(blog_name, options = {}) ⇒ Object
Don’t be lazy and create a nice interface.
- #text(blog_name, options = {}) ⇒ Object
- #video(blog_name, options = {}) ⇒ Object
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, ={}) valid_opts = @@standard_post_options + [:data, :caption, :external_url] if (valid_opts, ) [:type] = "audio" if (.has_key?(:data) && .has_key?(:external_url)) raise Exception, "You can only use one parameter, either data or external url." end if(.has_key?(:data)) [:data] = File.open([:data],'rb').read() end post("v2/blog/#{blog_name}/post", ) 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, ={}) valid_opts = @@standard_post_options + [:title, :conversation] if (valid_opts, ) [:type] = "chat" post("v2/blog/#{blog_name}/post", ) 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, ={}) post("v2/blog/#{blog_name}/post/edit", ) end |
#link(blog_name, options = {}) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/tumblr/post.rb', line 68 def link(blog_name, ={}) valid_opts = @@standard_post_options + [:title, :url, :description] if (valid_opts, ) [:type] = "link" post("v2/blog/#{blog_name}/post", ) 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, ={}) valid_opts = @@standard_post_options + [:caption, :link, :data, :source, :photoset_layout] if (valid_opts, ) [:type] = "photo" if (.has_key?(:data) && .has_key?(:source)) raise Exception, "You can only use one parameter, either source or data." end if .has_key?(:source) && [:source].kind_of?(Array) count = 0 [:source].each do |src| ["source[#{count}]"] = src count += 1 end .delete(:source) end if .has_key?(:data) #Probably can be refactored if [:data].kind_of?(Array) count = 0 [:data].each do |filepath| ["data[#{count}]"] = File.open(filepath, 'rb').read() count += 1 end .delete(:data) else [:data] = File.open([:data],'rb').read() end end post("v2/blog/#{blog_name}/post", ) 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, ={}) valid_opts = @@standard_post_options + [:quote, :source] if (valid_opts, ) [:type] = "quote" post("v2/blog/#{blog_name}/post", ) 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, ={}) post("v2/blog/#{blog_name}/post/reblog", ) end |
#text(blog_name, options = {}) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/tumblr/post.rb', line 60 def text(blog_name, ={}) valid_opts = @@standard_post_options + [:title, :body] if (valid_opts, ) [:type] = "text" post("v2/blog/#{blog_name}/post", ) 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, ={}) valid_opts = @@standard_post_options + [:data, :embed, :caption] if (valid_opts, ) [:type] = "video" if (.has_key?(:data) && .has_key?(:embed)) raise Exception, "You can only use one parameter, either data or embed." end if(.has_key?(:data)) [:data] = File.open([:data],'rb').read() end post("v2/blog/#{blog_name}/post", ) end end |