Class: Hiya::AttachBase

Inherits:
Base
  • Object
show all
Defined in:
lib/hiya/attach_base.rb

Direct Known Subclasses

Audio, Image, Video

Instance Attribute Summary

Attributes inherited from Base

#api_url, #bearer_token, #response, #source

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Hiya::Base

Instance Method Details

#create(files, opts = {}) ⇒ Object

files: Array: [‘/path/to/file1’, ‘/path/to/file2’, …] opts: Hash: {

attach: Hash: {
  password: String: '1234'
  password_note: String: 'today'
  expired_num: Integer: 3600
  view_count_limit: Integer: 100
}
post: Hash: {
  content: String: 'This is post content'
}

}



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/hiya/attach_base.rb', line 19

def create(files, opts = {})
  return unless files.is_a?(Array)

  @files = files
  @opts = opts

  @response = multipart_conn.post(url) do |req|
    req.body = create_params
  end
  Oj.load(response.body, symbol_keys: true)
rescue StandardError => _e
  {}
end