media_spec.rb
2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require "spec_helper"
describe QyWechatApi::Api::Media do
let(:image_jpg_path) do
"#{File.dirname(__FILE__)}/medias/ruby-logo.jpg"
end
let(:image_ico_path) do
"#{File.dirname(__FILE__)}/medias/favicon.ico"
end
let(:image_jpg_file) do
File.new(image_jpg_path)
end
let(:image_ico_file) do
File.new(image_ico_path)
end
let(:remote_png_path) do
"https://ruby-china-files.b0.upaiyun.com/user/big_avatar/273.jpg"
end
let(:remote_jpg_path) do
"http://g.hiphotos.baidu.com/baike/c0%3Dbaike80%2C5%2C5%2C80%2C26/sign=ce55457e4334970a537e187df4a3baad/03087bf40ad162d99455ef4d13dfa9ec8b13632762d0ed14.jpg"
end
it "can upload a jpg File image" do
response = $client.media.upload(image_jpg_file, "image")
expect(response.code).to eq(QyWechatApi::OK_CODE)
expect(response.result.keys).to eq(["type", "media_id", "created_at"])
end
it "can upload a ico File image" do
response = $client.media.upload(image_ico_file, "image")
expect(response.code).to eq(QyWechatApi::OK_CODE)
expect(response.result.keys).to eq(["type", "media_id", "created_at"])
end
it "can upload a local image" do
response = $client.media.upload(image_jpg_path, "image")
expect(response.code).to eq(QyWechatApi::OK_CODE)
expect(response.result.keys).to eq(["type", "media_id", "created_at"])
end
it "can upload a local ico image" do
response = $client.media.upload(image_ico_path, "image")
expect(response.code).to eq(QyWechatApi::OK_CODE)
expect(response.result.keys).to eq(["type", "media_id", "created_at"])
end
it "can upload a remote png image" do
response = $client.media.upload(remote_png_path, "image")
expect(response.code).to eq(QyWechatApi::OK_CODE)
expect(response.result.keys).to eq(["type", "media_id", "created_at"])
end
it "can upload a remote jpg image" do
response = $client.media.upload(remote_jpg_path, "image")
expect(response.code).to eq(QyWechatApi::OK_CODE)
expect(response.result.keys).to eq(["type", "media_id", "created_at"])
end
# it "#download_media_url return a String url" do
# image = $client.media.upload(image_ico_path, "image")
# media_id = image.result["media_id"]
# image_url = $client.download_media_url(media_id)
# expect(image_url.class).to eq(String)
# end
end