Skip to content

Instantly share code, notes, and snippets.

@yyyyyyuanfei
Created June 20, 2012 04:40
Show Gist options
  • Select an option

  • Save yyyyyyuanfei/2958150 to your computer and use it in GitHub Desktop.

Select an option

Save yyyyyyuanfei/2958150 to your computer and use it in GitHub Desktop.
qiniu demo in ruby
client_id: example
client_secret: example
username: example
password: example
source :rubygems
gem 'rest-client'
gem 'multi_json'
require 'rest_client'
require 'multi_json'
require 'pp'
require 'yaml'
file_path = "./accounts.yml"
username, password = "", ""
client_id, client_secret = "", ""
YAML::load_documents(File.open file_path) do |account|
client_id = account['client_id']
client_secret = account['client_secret']
username = account['username']
password = account['password']
end
token_endpoint = "https://acc.qbox.me/oauth2/token"
response = {}
RestClient.post(token_endpoint, grant_type: "password", username: username, password: password, client_id: client_id) do |r|
response = MultiJson.decode r
pp response, "\n"
end
access_token = response['access_token']
# RestClient.post(token_endpoint, grant_type: "refresh_token", client_id: client_id, refresh_token: response['refresh_token']) do |r|
# pp MultiJson.decode r
# end
RestClient.post("http://io.qbox.me/put-auth/#{response['expires_in']}", {}, { :Authorization => "Bearer #{access_token}" }) do |r|
response = MultiJson.decode r
pp response
end
upload_url = response['url']
# RestClient.post(upload_url,{:action => "/rs/YWJjMjMz",
# :file => File.new("/Users/stranbird/dev/cPresent/cPresent/general-background.png", "rb"),
# :params => {} }) do |r|
# pp r.code
# end
# EncodedEntryURI = "YWJjMjMz"
# RestClient.post "http://rs.qbox.me:10100/stat/#{EncodedEntryURI}", {}, { :Authorization => "Bearer #{access_token}" } do |r|
# pp r
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment