lib/ayadn/post.rb in ayadn-1.3.2 vs lib/ayadn/post.rb in ayadn-1.4.0

- old
+ new

@@ -19,10 +19,106 @@ readline # end # post end + def send_embedded text, files + send_embedded_pictures({'text' => text, 'data' => FileOps.upload_files(files)}) + end + + def send_reply_embedded text, reply_to, files + send_reply_embedded_pictures({'text' => text, 'reply_to' => reply_to, 'data' => FileOps.upload_files(files)}) + end + + def send_pm_embedded username, text, files + send_pm_embedded_pictures({'text' => text, 'username' => username, 'data' => FileOps.upload_files(files)}) + end + + def send_embedded_pictures dic + send_content(Endpoints.new.posts_url, payload_embedded(dic)) + end + + def send_reply_embedded_pictures dic + send_content(Endpoints.new.posts_url, payload_reply_embedded(dic)) + end + + def send_pm_embedded_pictures dic + url = Endpoints.new.pm_url + url << "?include_annotations=1&access_token=#{Ayadn::Settings.user_token}" + send_content(url, payload_pm_embedded(dic)) + end + + def send_nowplaying dic + send_content(Endpoints.new.posts_url, payload_nowplaying(dic)) + end + + def payload_nowplaying dic + ann = annotations() + if dic['visible'] == true + ann << { + "type" => "net.app.core.oembed", + "value" => { + "version" => "1.0", + "type" => "photo", + "width" => dic['width'], + "height" => dic['height'], + "title" => dic['title'], + "url" => dic['artwork'], + "embeddable_url" => dic['artwork'] + } + } + end + { + "text" => dic['text'], + "entities" => entities, + "annotations" => ann + } + end + + def payload_embedded dic + { + "text" => dic['text'], + "entities" => entities, + "annotations" => annotations_embedded(dic) + } + end + + def payload_reply_embedded dic + { + "text" => dic['text'], + "reply_to" => dic['reply_to'], + "entities" => entities, + "annotations" => annotations_embedded(dic) + } + end + + def payload_pm_embedded dic + { + "text" => dic['text'], + "entities" => entities, + "destinations" => dic['username'], + "annotations" => annotations_embedded(dic) + } + end + + def annotations_embedded dic + base = annotations() + dic['data'].each do |obj| + base << { + "type" => "net.app.core.oembed", + "value" => { + "+net.app.core.file" => { + "file_id" => obj['data']['id'], + "file_token" => obj['data']['file_token'], + "format" => "oembed" + } + } + } + end + return base + end + # def auto_classic # loop do # begin # print "#{Settings.config[:identity][:handle]} >> ".color(:red) # t = STDIN.gets.chomp @@ -80,33 +176,28 @@ end reply end def send_pm(username, text) - url = Endpoints.new.pm_url - url << "?include_annotations=1&access_token=#{Ayadn::Settings.user_token}" - send_content(url, payload_pm(username, text)) + send_content(Endpoints.new.pm_url, payload_pm(username, text)) end def send_message(channel_id, text) - url = Endpoints.new.messages(channel_id, {}) - send_content(url, payload_basic(text)) + send_content(Endpoints.new.messages(channel_id, {}), payload_basic(text)) end # def send_log(data) # url = Endpoints.new.ayadnlog # send_content(url, payload_log(data)) # end def send_post(text) - url = Endpoints.new.posts_url - send_content(url, payload_basic(text)) + send_content(Endpoints.new.posts_url, payload_basic(text)) end def send_reply(text, post_id) - url = Endpoints.new.posts_url - send_content(url, payload_reply(text, post_id)) + send_content(Endpoints.new.posts_url, payload_reply(text, post_id)) end def send_content(url, payload) url << "?include_annotations=1&access_token=#{Ayadn::Settings.user_token}" JSON.parse(CNX.post(url, payload)) @@ -182,9 +273,11 @@ { "parse_markdown_links" => true, "parse_links" => true } end + + def payload_basic(text) { "text" => text, "entities" => entities,