Class: Wechat::Media

Inherits:
DataObject show all
Defined in:
lib/wechat/data_objects/media.rb

Overview

Class Method Summary collapse

Methods inherited from DataObject

get, parameterize_params, post, #request

Class Method Details

.download(media_id) ⇒ String

Returns path to downloaded file.

Parameters:

  • media_id (String)

    the media_id of the file to be downloaded

Returns:

  • (String)

    path to downloaded file



41
42
43
44
# File 'lib/wechat/data_objects/media.rb', line 41

def download(media_id) 
  get "media/get", {media_id: media_id}

end

.upload(type, path) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wechat/data_objects/media.rb', line 19

def upload(type, path)

  if path.include?'http'
        # We create a local representation of the remote resource
    # local_resource = LocalResource.new URI.parse(path)
     local_resource = LocalResource.new(URI.parse(path))
    # We have a copy of the remote file for processing
    local_copy_of_remote_file = local_resource.file


    path = local_copy_of_remote_file.path
  end

  file = File.new(path,'rb')
  post "media/upload", {media: file, type: type}
end