ilink 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd065e745067f368a031d7a216c5f715d231c548c0b4356e75a0ca2b7710ffc4
4
- data.tar.gz: '058fe14875bf554fc646b3ac7667fcddf4ed9dc4a880070831b40ae60105c483'
3
+ metadata.gz: fe6b67ecb39bbb9da2cb397751809a29f751383a03a6d3dc093fbf58e8e5c331
4
+ data.tar.gz: 951690d2c4a09ed83665e71d017284caf2ab981a73421ceae147ebaa0fc01b55
5
5
  SHA512:
6
- metadata.gz: 7d4a785e699003b84088b0ddaf7df3ff854895a4a460f7c8b6e8fe00c22372fdbb09372b47a33472bbe58a2403de1fd6b8df2c4d6ef1d99da13367272daaeb3f
7
- data.tar.gz: c90d8af0c339262ad2c8e61b2e12ccc229a6e3c512718e710b2fdf559f94eeca01e255940f92278a46774d07833850a49cd66101224d53e6d22f7563c393ee28
6
+ metadata.gz: 67f1002aaf4aac53ac8011201020658f8a5f6c2c526891cf92f38c1488933bb00d4cbadd7578812f7119eaf0d0935b7882ee461e58f5f12b1859336b50693669
7
+ data.tar.gz: cd74028d81ac59acf895c5d47370da489966969f9c07e6dd7d53d667e2570fad7bf0d089411d707ff4677757343ef14d238129bcd3b535d331e17fcfa46a2472
data/README.md CHANGED
@@ -56,12 +56,12 @@ bot = ILink::Bot.new(
56
56
  bot = ILink::Bot.new
57
57
 
58
58
  # Step 1: Get a QR code
59
- qr = bot.qrcode
59
+ qr = bot.get_qrcode
60
60
  puts qr[:qrcode_img_content] # QR code image URL — show to user
61
61
 
62
62
  # Step 2: Poll scan status (long-poll, blocks until scanned or timeout)
63
63
  loop do
64
- status = bot.qrcode_status(qrcode: qr[:qrcode])
64
+ status = bot.get_qrcode_status(qrcode: qr[:qrcode])
65
65
  case status[:status]
66
66
  when "confirmed"
67
67
  puts "Login success!"
@@ -133,7 +133,7 @@ bot.send_message({
133
133
  ### Media Upload
134
134
 
135
135
  ```ruby
136
- resp = bot.upload_url(
136
+ resp = bot.get_upload_url(
137
137
  media_type: ILink::UploadMediaType::IMAGE,
138
138
  to_user_id: "user_id",
139
139
  rawsize: File.size("photo.jpg"),
data/lib/ilink/bot.rb CHANGED
@@ -6,7 +6,7 @@ module ILink
6
6
  # bot = ILink::Bot.new(token: "your_bot_token")
7
7
  # bot.get_updates
8
8
  # bot.send_text(to: "user_id", text: "Hello!")
9
- # bot.upload_url(media_type: 1, to_user_id: "user_id", ...)
9
+ # bot.get_upload_url(media_type: 1, to_user_id: "user_id", ...)
10
10
  # bot.send_typing(user_id: "...", ticket: "...")
11
11
  # bot.get_config(user_id: "...")
12
12
  # bot.create_qr_code
@@ -36,14 +36,6 @@ module ILink
36
36
  { ret: 0, msgs: [], get_updates_buf: buf }
37
37
  end
38
38
 
39
- # Send a message.
40
- #
41
- # @param message [Hash] a WeixinMessage hash with keys like :to_user_id, :item_list, etc.
42
- # @return [Hash] parsed response
43
- def send_message(message)
44
- connection.post("/ilink/bot/sendmessage", { msg: message })
45
- end
46
-
47
39
  # Convenience: send a text message to a user.
48
40
  #
49
41
  # @param to [String] target user ID
@@ -63,12 +55,20 @@ module ILink
63
55
  send_message(message)
64
56
  end
65
57
 
58
+ # Send a message.
59
+ #
60
+ # @param message [Hash] a WeixinMessage hash with keys like :to_user_id, :item_list, etc.
61
+ # @return [Hash] parsed response
62
+ def send_message(message)
63
+ connection.post("/ilink/bot/sendmessage", { msg: message })
64
+ end
65
+
66
66
  # Get a pre-signed CDN upload URL.
67
67
  #
68
68
  # @param params [Hash] :filekey, :media_type, :to_user_id, :rawsize, :rawfilemd5,
69
69
  # :filesize, :aeskey, :thumb_rawsize, :thumb_rawfilemd5, :thumb_filesize, :no_need_thumb
70
70
  # @return [Hash] { upload_param:, thumb_upload_param:, upload_full_url: }
71
- def upload_url(**params)
71
+ def get_upload_url(**params)
72
72
  connection.post("/ilink/bot/getuploadurl", params)
73
73
  end
74
74
 
@@ -78,7 +78,7 @@ module ILink
78
78
  # @param ticket [String] typing ticket (from get_config)
79
79
  # @return [Hash]
80
80
  def send_typing(user_id:, ticket:)
81
- set_typing(user_id: user_id, ticket: ticket, status: TypingStatus::TYPING)
81
+ toggle_typing(user_id: user_id, ticket: ticket, status: TypingStatus::TYPING)
82
82
  end
83
83
 
84
84
  # Cancel a typing indicator.
@@ -87,10 +87,16 @@ module ILink
87
87
  # @param ticket [String] typing ticket
88
88
  # @return [Hash]
89
89
  def cancel_typing(user_id:, ticket:)
90
- set_typing(user_id: user_id, ticket: ticket, status: TypingStatus::CANCEL)
90
+ toggle_typing(user_id: user_id, ticket: ticket, status: TypingStatus::CANCEL)
91
91
  end
92
92
 
93
- def set_typing(user_id:, ticket:, status:)
93
+ # Toggle a typing indicator.
94
+ #
95
+ # @param user_id [String] ilink user ID
96
+ # @param ticket [String] typing ticket
97
+ # @param status [Integer] typing status (TypingStatus::TYPING or TypingStatus::CANCEL)
98
+ # @return [Hash]
99
+ def toggle_typing(user_id:, ticket:, status:)
94
100
  connection.post("/ilink/bot/sendtyping", {
95
101
  ilink_user_id: user_id,
96
102
  typing_ticket: ticket,
@@ -112,7 +118,7 @@ module ILink
112
118
  #
113
119
  # @param bot_type [String] bot type identifier (default "3")
114
120
  # @return [Hash] { qrcode:, qrcode_img_content: }
115
- def qrcode(bot_type: "3")
121
+ def get_qrcode(bot_type: "3")
116
122
  connection.get("/ilink/bot/get_bot_qrcode?bot_type=#{URI.encode_www_form_component(bot_type)}", timeout: 5)
117
123
  end
118
124
 
@@ -120,7 +126,7 @@ module ILink
120
126
  #
121
127
  # @param qrcode [String] qrcode value from #create_qr_code
122
128
  # @return [Hash] { status:, bot_token:, ilink_bot_id:, baseurl:, ilink_user_id:, redirect_host: }
123
- def qrcode_status(qrcode:)
129
+ def get_qrcode_status(qrcode:)
124
130
  connection.get("/ilink/bot/get_qrcode_status?qrcode=#{URI.encode_www_form_component(qrcode)}",
125
131
  timeout: @configuration.long_poll_timeout)
126
132
  rescue Net::ReadTimeout, Net::OpenTimeout
data/lib/ilink/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ILink
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ilink
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Songji Zeng
@@ -39,7 +39,6 @@ files:
39
39
  - lib/ilink/connection.rb
40
40
  - lib/ilink/constants.rb
41
41
  - lib/ilink/errors.rb
42
- - lib/ilink/resources/messages.rb
43
42
  - lib/ilink/version.rb
44
43
  homepage: https://github.com/songjiz/ilink-ruby
45
44
  licenses:
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ILink
4
- module Resources
5
- # RESTful resource for message operations.
6
- #
7
- # bot.messages.get_updates - long-poll for new messages (getUpdates)
8
- # bot.messages.send(msg) - send a message to a user
9
- class Messages < Base
10
- # Long-poll for new messages.
11
- #
12
- # @param get_updates_buf [String] opaque cursor from previous poll ("" on first call)
13
- # @return [Hash] parsed response with :ret, :msgs, :get_updates_buf, etc.
14
- def poll(get_updates_buf: "")
15
- post("/ilink/bot/getupdates",
16
- { get_updates_buf: get_updates_buf },
17
- timeout: connection.config.long_poll_timeout)
18
- rescue Net::ReadTimeout, Net::OpenTimeout
19
- # Long-poll timeout is normal; return empty response so caller can retry
20
- { ret: 0, msgs: [], get_updates_buf: get_updates_buf }
21
- end
22
-
23
- # Send a message.
24
- #
25
- # @param message [Hash] a WeixinMessage hash with keys like :to_user_id, :item_list, etc.
26
- # @return [Hash] parsed response
27
- def send(message)
28
- post("/ilink/bot/sendmessage", { msg: message })
29
- end
30
-
31
- # Convenience: send a text message to a user.
32
- #
33
- # @param to [String] target user ID
34
- # @param text [String] message text
35
- # @param session_id [String, nil] optional session ID
36
- # @return [Hash]
37
- def send_text(to:, text:, session_id: nil)
38
- message = {
39
- to_user_id: to,
40
- message_type: MessageType::BOT,
41
- message_state: MessageState::FINISH,
42
- item_list: [
43
- {
44
- type: MessageItemType::TEXT,
45
- text_item: { text: text }
46
- }
47
- ]
48
- }
49
- message[:session_id] = session_id if session_id
50
- send(message)
51
- end
52
- end
53
- end
54
- end