プロジェクト

全般

プロフィール

機能 #786 » media_upload.diff

ふぇのまー 葱野, 2015-10-25 13:04

差分を表示:

core/lib/mikutwitter/api_shortcuts.rb
118 118
    text = message[:message]
119 119
    replyto = message[:replyto]
120 120
    receiver = message[:receiver]
121
    iolist = message[:mediaiolist]
121 122
    data = {:status => text }
122 123
    data[:in_reply_to_user_id] = User.generate(receiver)[:id].to_s if receiver
123 124
    data[:in_reply_to_status_id] = Message.generate(replyto)[:id].to_s if replyto
125
    data[:media_ids] = iolist.collect{ |io| upload_media(io) }.join(",") if iolist
124 126
    (self/'statuses/update').message(data) end
125 127
  alias post update
126 128

  
......
239 241
        else
240 242
          users end } } end
241 243

  
244
  # upload.twitter.comに画像等をアップロードし、
245
  # アップロードしたファイルのmedia_idを返す。
246
  # ==== Args
247
  # [io] アップロードする画像ファイルのIO
248
  # ==== Return
249
  # media_id(Integer) or nil
250
  def upload_media(io)
251
    JSON.parse(self.query!('media/upload',
252
                           { host: 'upload.twitter.com/1.1',
253
                             media: Base64.encode64(io.read) }).body)['media_id'] end
242 254
end
243 255

  
244 256
class MikuTwitter; include MikuTwitter::APIShortcuts end
core/lib/mikutwitter/query.rb
62 62
      raise MikuTwitter::RateLimitError.new("Rate limit #{resource.endpoint}", nil) end
63 63
    method = get_api_property(api, options, method_of_api) || :get
64 64
    url = if options[:host]
65
            "http://#{options[:host]}/#{api}.json"
65
            "https://#{options[:host]}/#{api}.json"
66 66
          else
67 67
            "#{@base_path}/#{api}.json" end
68 68
    res = _query!(api, options, method, url)
......
187 187
        'destroy' => aster_post },
188 188
      'geo' => {
189 189
        'place' => :post },
190
      'media' => {
191
        'upload' => :post },
190 192
      'blocks' => create_destroy_post,
191 193
      'report_spam' => :post,
192 194
      'oauth' => {
    (1-1/1)