Class: Tumblr::CommandLineInterface
- Inherits:
-
Thor
- Object
- Thor
- Tumblr::CommandLineInterface
- Includes:
- Thor::Actions
- Defined in:
- lib/tumblr/command_line_interface.rb
Instance Method Summary collapse
- #authorize(*soak) ⇒ Object
- #delete(id) ⇒ Object
- #edit(id) ⇒ Object
- #fetch(id) ⇒ Object
- #pipe ⇒ Object
- #post(arg) ⇒ Object
- #version ⇒ Object
Instance Method Details
#authorize(*soak) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/tumblr/command_line_interface.rb', line 148 def (*soak) require 'tumblr/authentication' = { :port => [:port], :bind => [:bind], :credential_path => [:credentials] } Tumblr::Authentication.run!() do |server| `open http://#{[:bind]}:#{[:port]}/` end if has_credentials? ui_success "Success! Your Tumblr OAuth credentials were written to #{credentials.path}" else ui_abort "Something went wrong in authorization, and credentials were not correctly written to #{credentials.path}" end end |
#delete(id) ⇒ Object
122 123 124 125 126 127 |
# File 'lib/tumblr/command_line_interface.rb', line 122 def delete(id) client = get_client response = client.delete(:id => id).perform tumblr_error(response) unless response.success? ui_success "Post #{id} successfully deleted." end |
#edit(id) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/tumblr/command_line_interface.rb', line 90 def edit(id) client = get_client response = client.posts(:id => id, :filter => :raw).perform tumblr_error(response) unless response.success? post = Tumblr::Post.create(response.parse["response"]["posts"].first) require 'tempfile' tmp_file = Tempfile.new("post_#{id}") tmp_file.write(post.serialize) tmp_file.rewind ui_abort "Something went wrong editing the post." unless system "#{editor} #{tmp_file.path}" edited_post = Tumblr::Post.load_from_path tmp_file.path edited_response = edited_post.edit(client).perform tumblr_error(edited_response) unless edited_response.success? ui_success "Post #{id} successfully edited." ensure if tmp_file tmp_file.close tmp_file.unlink end end |
#fetch(id) ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/tumblr/command_line_interface.rb', line 112 def fetch(id) client = get_client response = client.posts(:id => id, :filter => :raw).perform tumblr_error(response) unless response.success? post = Tumblr::Post.create(response.parse["response"]["posts"].first) puts post.serialize post end |
#pipe ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/tumblr/command_line_interface.rb', line 36 def pipe if !$stdin.tty? puts post($stdin).serialize else invoke :help end end |
#post(arg) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/tumblr/command_line_interface.rb', line 64 def post(arg) client = get_client post = if arg.respond_to? :read Tumblr::Post.load arg.read elsif File.file?(file_path = File.(arg)) Tumblr::Post.load_from_path file_path else Tumblr::Post.load arg.to_s end post.publish! if [:publish] post.queue! if [:queue] post.draft! if [:draft] response = post.post(client).perform tumblr_error(response) unless response.success? ui_success %Q(Post was successfully created! Post ID: #{response.parse["response"]["id"]}) if $stdin.tty? post end |