Module: Typetalk::Api::Message
- Included in:
- Typetalk::Api
- Defined in:
- lib/typetalk/api/message.rb
Instance Method Summary collapse
- #get_message(topic_id, post_id, options = {}) ⇒ Object
- #like_message(topic_id, post_id, options = {}) ⇒ Object
- #post_message(topic_id, message, options = {}) ⇒ Object
- #read_message(topic_id, post_id = nil, options = {}) ⇒ Object
- #remove_message(topic_id, post_id, options = {}) ⇒ Object
- #unlike_message(topic_id, post_id, options = {}) ⇒ Object
- #upload_attachment(topic_id, file, options = {}) ⇒ Object
Instance Method Details
#get_message(topic_id, post_id, options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/typetalk/api/message.rb', line 39 def (topic_id, post_id, ={}) = {token:nil}.merge() response = connection.get do |req| req.url "#{endpoint}/topics/#{topic_id}/posts/#{post_id}" req.params[:access_token] = [:token] || access_token end parse_response(response) end |
#like_message(topic_id, post_id, options = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/typetalk/api/message.rb', line 62 def (topic_id, post_id, ={}) = {token:nil}.merge() response = connection.post do |req| req.url "#{endpoint}/topics/#{topic_id}/posts/#{post_id}/like" req.params[:access_token] = [:token] || access_token end parse_response(response) end |
#post_message(topic_id, message, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/typetalk/api/message.rb', line 8 def (topic_id, , ={}) = {token:nil, reply_to:nil, file_keys:nil, talk_ids:nil}.merge() response = connection.post do |req| req.url "#{endpoint}/topics/#{topic_id}" req.params[:access_token] = [:token] || access_token body = {} body[:message] = body[:replyTo] = [:reply_to] unless [:reply_to].nil? body.merge! to_request_params(:fileKeys, [:file_keys]) body.merge! to_request_params(:talkIds, [:talk_ids]) req.body = body end parse_response(response) end |
#read_message(topic_id, post_id = nil, options = {}) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/typetalk/api/message.rb', line 84 def (topic_id, post_id=nil, ={}) = {token:nil}.merge() response = connection.post do |req| req.url "#{endpoint}/bookmark/save" req.params[:access_token] = [:token] || access_token body = {} body[:topicId] = topic_id body[:postId] = post_id unless post_id.nil? req.body = body end parse_response(response) end |
#remove_message(topic_id, post_id, options = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/typetalk/api/message.rb', line 50 def (topic_id, post_id, ={}) = {token:nil}.merge() response = connection.delete do |req| req.url "#{endpoint}/topics/#{topic_id}/posts/#{post_id}" req.params[:access_token] = [:token] || access_token end parse_response(response) response.status == 200 end |
#unlike_message(topic_id, post_id, options = {}) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/typetalk/api/message.rb', line 73 def (topic_id, post_id, ={}) = {token:nil}.merge() response = connection.delete do |req| req.url "#{endpoint}/topics/#{topic_id}/posts/#{post_id}/like" req.params[:access_token] = [:token] || access_token end parse_response(response) end |
#upload_attachment(topic_id, file, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/typetalk/api/message.rb', line 25 def (topic_id, file, ={}) = {token:nil}.merge() raise InvalidFileSize if File.size(file) > 10485760 # > 10MB response = connection(multipart:true).post do |req| req.url "#{endpoint}/topics/#{topic_id}/attachments" req.params[:access_token] = [:token] || access_token req.body = { file: Faraday::UploadIO.new(file, MIME::Types.type_for(file).first.to_s) } end parse_response(response) end |