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

Returns a new instance of Client.

Parameters:

  • key (String)

    webhook key from robot detail page

  • base_url (String) (defaults to: BASE_URL)

    override base URL if needed



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_urlObject (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

#keyObject (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

Parameters:

  • file_id (String)

Returns:



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

Parameters:

  • file_id (String)
  • height (Integer)
  • width (Integer)

Returns:



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

Parameters:

  • title (String)
  • url (String)
  • description (String, nil) (defaults to: nil)
  • pic_url (String, nil) (defaults to: nil)

Returns:



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

Parameters:

  • content (String)
  • mention_all (Boolean) (defaults to: false)
  • mentioned_mobiles (Array<String>) (defaults to: nil)

Returns:



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

Parameters:

  • path (String)

    local file path

Returns:

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

Parameters:

  • path (String)

    local image path

  • height (Integer)
  • width (Integer)

Returns:

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)

Parameters:

  • path (String)

    local file path

  • filename (String, nil) (defaults to: nil)

    override filename in multipart

Returns:

  • (Response)

    response.data contains name, type, size



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)

Parameters:

  • path (String)

    local file path

  • filename (String, nil) (defaults to: nil)

    override filename in multipart

Returns:

  • (Response)

    response.data contains name, type, size



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