Skip to content

Instantly share code, notes, and snippets.

@yachi
Created January 26, 2011 10:43
Show Gist options
  • Save yachi/796541 to your computer and use it in GitHub Desktop.
Save yachi/796541 to your computer and use it in GitHub Desktop.
diff --git a/config/initializers/weibo_oauth.rb b/config/initializers/weibo_oauth.rb
index a117f98..1f46768 100644
--- a/config/initializers/weibo_oauth.rb
+++ b/config/initializers/weibo_oauth.rb
@@ -3,9 +3,51 @@ WEIBO_OAUTH.symbolize_keys!
module WeiboOAuth
class Client
- def upload(message, image)
- body, headers = http_multipart_data({:pic => image, :status => message})
- post('/account/upload.json', body, headers)
+ def upload(status, image)
+ PostBodyHack.apply_hack(:status => status) do
+ body, headers = http_multipart_data({:pic => image, :status => status})
+ post("/statuses/upload.json", body, headers)
+ end
end unless defined?(upload)
end
end
+
+# https://github.com/ballantyne/weibo/blob/master/lib/weibo/oauth_hack.rb
+# This hack is used for Weibo upload
+
+unless {}.respond_to?(:stringify_keys)
+ class Hash
+ def stringify_keys
+ inject({}) do |options, (key, value)|
+ options[key.to_s] = value
+ options
+ end
+ end
+ end
+end
+
+module PostBodyHack
+ @@parameters = nil
+ def self.parameters=(val)
+ @@parameters = val
+ end
+
+ def self.parameters
+ @@parameters
+ end
+
+ def self.apply_hack(params={}, &block)
+ self.parameters = params.stringify_keys
+ rv = yield
+ self.parameters = {}
+ rv
+ end
+end
+
+class OAuth::RequestProxy::Base
+ def parameters_for_signature
+ params_for_signature = parameters.reject { |k,v| k == "oauth_signature" ||unsigned_parameters.include?(k) }
+ params_for_signature.merge!(PostBodyHack.parameters || {}) if defined? PostBodyHack
+ # params_for_signature
+ end
+end
diff --git a/vendor/gems/weibo_oauth-1.0.0/lib/weibo_oauth/utils.rb b/vendor/gems/weibo_oauth-1.0.0/lib/weibo_oauth/utils.rb
index 1c64d8a..bb22211 100644
--- a/vendor/gems/weibo_oauth-1.0.0/lib/weibo_oauth/utils.rb
+++ b/vendor/gems/weibo_oauth-1.0.0/lib/weibo_oauth/utils.rb
@@ -23,6 +23,7 @@ module WeiboOAuth
else
body << "Content-Disposition: form-data; name=\"#{esc_key}\"#{CRLF*2}#{value}"
end
+ body << CRLF
end
body << "--#{boundary}--#{CRLF*2}"
@@ -31,4 +32,4 @@ module WeiboOAuth
return [ body, headers ]
end
end
-end
\ No newline at end of file
+end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment