Class: IceJade::Quantum::Client

Inherits:
ClientBase show all
Defined in:
lib/ice_jade/quantum/client.rb

Overview

Quantum IM Webhook API client

Constant Summary collapse

BASE_URL =
'https://imtwo.zdxlz.com/im-external/v1/webhook'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, base_url: BASE_URL) ⇒ Client



15
16
17
18
# File 'lib/ice_jade/quantum/client.rb', line 15

def initialize(key, base_url: BASE_URL)
  @key = key
  @base_url = base_url.to_s.chomp('/')
end

Instance Attribute Details

#base_url ⇒ Object (readonly)

Returns the value of attribute base_url.



11
12
13
# File 'lib/ice_jade/quantum/client.rb', line 11

def base_url
  @base_url
end

#key ⇒ Object (readonly)

Returns the value of attribute key.



11
12
13
# File 'lib/ice_jade/quantum/client.rb', line 11

def key
  @key
end

Instance Method Details

#send_file(file_id) ⇒ Response

Send a file message



47
48
49
50
# File 'lib/ice_jade/quantum/client.rb', line 47

def send_file(file_id)
  payload = Message.file(file_id)
  post_json('/send', payload)
end

#send_image(file_id, height:, width:) ⇒ Response

Send an image message



39
40
41
42
# File 'lib/ice_jade/quantum/client.rb', line 39

def send_image(file_id, height:, width:)
  payload = Message.image(file_id, height: height, width: width)
  post_json('/send', payload)
end

#send_news(title, url, description: nil, pic_url: nil) ⇒ Response

Send a news / link card message



58
59
60
61
# File 'lib/ice_jade/quantum/client.rb', line 58

def send_news(title, url, description: nil, pic_url: nil)
  payload = Message.news(title, url, description: description, pic_url: pic_url)
  post_json('/send', payload)
end

#send_text(content, mention_all: false, mentioned_mobiles: nil) ⇒ Response

Send a text message



29
30
31
32
# File 'lib/ice_jade/quantum/client.rb', line 29

def send_text(content, mention_all: false, mentioned_mobiles: nil)
  payload = Message.text(content, mention_all: mention_all, mentioned_mobiles: mentioned_mobiles)
  post_json('/send', payload)
end

#upload_and_send_file(path) ⇒ Response

Upload then immediately send a file

Raises:



102
103
104
105
106
107
# File 'lib/ice_jade/quantum/client.rb', line 102

def upload_and_send_file(path)
  resp = upload_file(path)
  raise APIError, "Upload failed: #{resp.message}" unless resp.success?

  send_file(resp.data['id'])
end

#upload_and_send_image(path, height:, width:) ⇒ Response

Upload then immediately send an image

Raises:



92
93
94
95
96
97
# File 'lib/ice_jade/quantum/client.rb', line 92

def upload_and_send_image(path, height:, width:)
  resp = upload_image(path)
  raise APIError, "Upload failed: #{resp.message}" unless resp.success?

  send_image(resp.data['id'], height: height, width: width)
end

#upload_file(path, filename: nil) ⇒ Response

Upload a generic file (type=2)



79
80
81
# File 'lib/ice_jade/quantum/client.rb', line 79

def upload_file(path, filename: nil)
  upload_attachment(path, type: 2, filename: filename)
end

#upload_image(path, filename: nil) ⇒ Response

Upload an image file (type=1)



71
72
73
# File 'lib/ice_jade/quantum/client.rb', line 71

def upload_image(path, filename: nil)
  upload_attachment(path, type: 1, filename: filename)
end