Module: MixinBot::API::Attachment
- Included in:
- MixinBot::API
- Defined in:
- lib/mixin_bot/api/attachment.rb
Instance Method Summary collapse
-
#create_attachment ⇒ Object
developers.mixin.one/api/beta-mixin-message/create-attachment/ Sample Response { “data”:{ “type”:“attachment”, “attachment_id”:“7a54e394-1626-4cd4-b967-543932c2a032”, “upload_url”:“moments-shou-tv.s3.amazonaws.com/mixin/attachments/xxx”, “view_url”:“moments.shou.tv/mixin/attachments/1526305123xxxx” } } Once get the upload_url, use it to upload the your file via PUT request.
- #read_attachment(attachment_id) ⇒ Object
- #upload_attachment(file) ⇒ Object
Instance Method Details
#create_attachment ⇒ Object
developers.mixin.one/api/beta-mixin-message/create-attachment/ Sample Response {
"data":{
"type":"attachment",
"attachment_id":"7a54e394-1626-4cd4-b967-543932c2a032",
"upload_url":"https://moments-shou-tv.s3.amazonaws.com/mixin/attachments/xxx",
"view_url":"https://moments.shou.tv/mixin/attachments/1526305123xxxx"
}
} Once get the upload_url, use it to upload the your file via PUT request
17 18 19 20 21 22 |
# File 'lib/mixin_bot/api/attachment.rb', line 17 def path = '/attachments' access_token ||= access_token('POST', path, {}.to_json) = format('Bearer %<access_token>s', access_token: access_token) client.post(path, headers: { 'Authorization': }, json: {}) end |
#read_attachment(attachment_id) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/mixin_bot/api/attachment.rb', line 44 def () path = format('/attachments/%<id>s', id: ) access_token ||= access_token('GET', path, '') = format('Bearer %<access_token>s', access_token: access_token) client.get(path, headers: { 'Authorization': }) end |
#upload_attachment(file) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mixin_bot/api/attachment.rb', line 24 def (file) = ['data'] HTTP .timeout(connect: 5, write: 5, read: 5) .request( :put, .delete('upload_url'), { body: file, headers: { 'x-amz-acl': 'public-read', 'Content-Type': 'application/octet-stream' } } ) end |