simsicon / weibo_2

A ruby gem for sina weibo oauth2 api, with examples, and it actually works.
MIT License
194 stars 86 forks source link

The weibo options passed to the statuses.upload is ignored. #11

Closed toctan closed 11 years ago

toctan commented 11 years ago

I can specific the weibo option in an optional hash when I update the text status:

client.statuses.update("Hey!", :visible => 2)  # only visible to close friends

But it does not work when I try to do the same thing when I try to post a weibo with image via upload:

client.statuse,upload("Hey!", File.open("whatever.jpg"), :visible => 2)

I studied the source code and the example you have given. The option hash in upload is considered a file option, isn't it? I think it's consistent the two options do the same thing, maybe the upload function should be implemented like this:

def upload(status, pic, opt={}, file_opt={})
    multipart = build_multipart_bodies({"status" => status, "pic" => pic}.merge(opt), file_opt)
    hashie post("statuses/upload.json", :headers => multipart[:headers], :body => multipart[:body])
end
simsicon commented 11 years ago

Hi, Try

client.statuse,upload("Hey!", "whatever.jpg", :visible => 2)

the second argument pic is pathname for the pic, you dont need to pass the file into this method. maybe I should rename it to avoid this confusion anymore. Thanks for mention this.

toctan commented 11 years ago

@simsicon

client.statuses.upload('Test', '/home/toctan/1.jpg', :visible => 2)
# => {"error":"does multipart has image?","error_code":20007,"request":"/2/statuses/upload.json"}

# I do not think the second option is the pathname.
client.statuses.upload('Test', File.open('/home/toctan/1.jpg'), :visible => 2) # => success

It's really strange the same code works today. Fuck Sina.

liubin commented 10 years ago

Yes, you can pass the second parameter as a stream that respond to :read method, even open remote resources(using open-uri)