null+****@clear*****
null+****@clear*****
Thu Jun 7 12:09:24 JST 2012
yuta yamada 2012-06-07 12:09:24 +0900 (Thu, 07 Jun 2012) New Revision: 1e82afc7fa758721051fc2a0111b1d5f1c675b9b Log: Use API for upload Modified files: Rakefile Modified: Rakefile (+36 -0) =================================================================== --- Rakefile 2012-06-07 11:01:01 +0900 (6e2aed7) +++ Rakefile 2012-06-07 12:09:24 +0900 (1bb5998) @@ -15,6 +15,10 @@ DESCRIPTION = "Front-end of logaling-command for Ruby gem" DEPENDENCIES = [["popwin", "0.4"], ["popup", "0.4"]] #--rakefile-- + +require "net/http" +require "json" + task :default => :package desc "Package #{PACKAGE_NAME}" @@ -46,3 +50,35 @@ task :init => "Rakefile" do (define-package "#{PACKAGE_NAME}" "#{PACKAGE_VERSION}" "#{DESCRIPTION}" #{dependencies}) ELISP end + +def read_password + print("Password: ") + system("stty -echo") + input = $stdin.gets.chomp + system("stty echo") + puts + input +end + +desc "Uploads package" +task :upload => :package do + print("User name: ") + user = $stdin.gets.chomp + password = read_password + + marmalade_api_base_url = "http://marmalade-repo.org" + login_url = URI.parse("#{marmalade_api_base_url}/v1/users/login") + response = Net::HTTP.post_form(login_url, + {"name" => user, "password" => password}) + if response.status != 200 + raise "failed to login (#{user}): #{response.body}" + end + login_info = JSON.parse(response.body) + token = login_info["token"] + + sh("curl", + "-F", "name=#{PACKAGE_NAME}", + "-F", "token=#{token}", + "-F", "file=@#{MARMALADE_PACKAGE_NAME}.tar", + "#{marmalade_api_base_url}/v1/packages") +end