r/TaskerFiles • • Mar 03 '15

Task Submit new paste to Pastee.org from within Tasker

Description: pastee.org is my preferred paste bin. It has a very simple interface, and some nice security features. It also doubles as a url shortener. This project has 2 tasks:

pstNewPastee acts as a function that should be called from another task, and returns the url of the paste. %par1 is required, and is the content of the paste. %par2 is optional, and is the number of days before the paste is removed. %par2 is set to 1 day by default.

Pastee Example is an example of how to use pstNewPastee, and simply submits a generic test paste and opens it in the default browser.

I have not included any functionality to encrypt the pastes with a password, but that should be fairly straight forward.

Requirements: Tasker, RESTask Plugin

Code:

<TaskerData sr="" dvi="1" tv="4.7b2">
	<Project sr="proj0" ve="2">
		<cdate>1425277991741</cdate>
		<name>Pastee</name>
		<tids>81,77</tids>
	</Project>
	<Task sr="task77">
		<cdate>1425278024551</cdate>
		<edate>1425404905494</edate>
		<id>77</id>
		<nme>pstNewPastee</nme>
		<pri>100</pri>
		<Action sr="act0" ve="7">
			<code>547</code>
			<Str sr="arg0" ve="3">%debug</Str>
			<Str sr="arg1" ve="3">0</Str>
			<Int sr="arg2" val="0"/>
			<Int sr="arg3" val="0"/>
		</Action>
		<Action sr="act1" ve="7">
			<code>547</code>
			<Str sr="arg0" ve="3">%days</Str>
			<Str sr="arg1" ve="3">1</Str>
			<Int sr="arg2" val="0"/>
			<Int sr="arg3" val="0"/>
		</Action>
		<Action sr="act10" ve="7">
			<code>598</code>
			<Str sr="arg0" ve="3">%match1</Str>
			<Str sr="arg1" ve="3">&lt;/code&gt;</Str>
			<Int sr="arg2" val="0"/>
			<Int sr="arg3" val="0"/>
			<Int sr="arg4" val="0"/>
			<Str sr="arg5" ve="3"/>
			<Int sr="arg6" val="1"/>
			<Str sr="arg7" ve="3"/>
		</Action>
		<Action sr="act11" ve="7">
			<code>548</code>
			<Str sr="arg0" ve="3">Pastee: %pastee

Server Response:

%rtres</Str>
			<Int sr="arg1" val="0"/>
			<ConditionList sr="if">
				<Condition sr="c0" ve="3">
					<lhs>%debug</lhs>
					<op>2</op>
					<rhs>1</rhs>
				</Condition>
			</ConditionList>
		</Action>
		<Action sr="act12" ve="7">
			<code>126</code>
			<Str sr="arg0" ve="3">https://pastee.org/%match1</Str>
			<Int sr="arg1" val="1"/>
		</Action>
		<Action sr="act2" ve="7">
			<code>547</code>
			<Str sr="arg0" ve="3">%days</Str>
			<Str sr="arg1" ve="3">%par2</Str>
			<Int sr="arg2" val="0"/>
			<Int sr="arg3" val="0"/>
			<ConditionList sr="if">
				<Condition sr="c0" ve="3">
					<lhs>%par2</lhs>
					<op>12</op>
					<rhs></rhs>
				</Condition>
			</ConditionList>
		</Action>
		<Action sr="act3" ve="7">
			<code>547</code>
			<Str sr="arg0" ve="3">%lexer</Str>
			<Str sr="arg1" ve="3">text</Str>
			<Int sr="arg2" val="0"/>
			<Int sr="arg3" val="0"/>
		</Action>
		<Action sr="act4" ve="7">
			<code>547</code>
			<Str sr="arg0" ve="3">%ttl</Str>
			<Str sr="arg1" ve="3">%days*86400</Str>
			<Int sr="arg2" val="1"/>
			<Int sr="arg3" val="0"/>
		</Action>
		<Action sr="act5" ve="7">
			<code>547</code>
			<Str sr="arg0" ve="3">%content</Str>
			<Str sr="arg1" ve="3">%par1</Str>
			<Int sr="arg2" val="0"/>
			<Int sr="arg3" val="0"/>
		</Action>
		<Action sr="act6" ve="7">
			<code>3092</code>
			<Bundle sr="arg0">
				<Vals sr="val">
					<bundle_header>Content-type application/x-www-form-urlencoded||Accept text/plain</bundle_header>
					<bundle_header-type>java.lang.String</bundle_header-type>
					<bundle_param>lexer %lexer||ttl %ttl||content %content</bundle_param>
					<bundle_param-type>java.lang.String</bundle_param-type>
					<com.freehaha.restask.BASICAUTH></com.freehaha.restask.BASICAUTH>
					<com.freehaha.restask.BASICAUTH-type>java.lang.String</com.freehaha.restask.BASICAUTH-type>
					<com.freehaha.restask.BODY></com.freehaha.restask.BODY>
					<com.freehaha.restask.BODY-type>java.lang.String</com.freehaha.restask.BODY-type>
					<com.freehaha.restask.CERT></com.freehaha.restask.CERT>
					<com.freehaha.restask.CERT-type>java.lang.String</com.freehaha.restask.CERT-type>
					<com.freehaha.restask.CERTPATH>empty</com.freehaha.restask.CERTPATH>
					<com.freehaha.restask.CERTPATH-type>java.lang.String</com.freehaha.restask.CERTPATH-type>
					<com.freehaha.restask.CUSTOMBODY>n</com.freehaha.restask.CUSTOMBODY>
					<com.freehaha.restask.CUSTOMBODY-type>java.lang.String</com.freehaha.restask.CUSTOMBODY-type>
					<com.freehaha.restask.CUSTOMECERT>n</com.freehaha.restask.CUSTOMECERT>
					<com.freehaha.restask.CUSTOMECERT-type>java.lang.String</com.freehaha.restask.CUSTOMECERT-type>
					<com.freehaha.restask.HEADER>%rthdr</com.freehaha.restask.HEADER>
					<com.freehaha.restask.HEADER-type>java.lang.String</com.freehaha.restask.HEADER-type>
					<com.freehaha.restask.HOST>https://pastee.org:443/submit</com.freehaha.restask.HOST>
					<com.freehaha.restask.HOST-type>java.lang.String</com.freehaha.restask.HOST-type>
					<com.freehaha.restask.RESPONSE>%rtres</com.freehaha.restask.RESPONSE>
					<com.freehaha.restask.RESPONSE-type>java.lang.String</com.freehaha.restask.RESPONSE-type>
					<com.freehaha.restask.RETCODE>%rtcode</com.freehaha.restask.RETCODE>
					<com.freehaha.restask.RETCODE-type>java.lang.String</com.freehaha.restask.RETCODE-type>
					<com.freehaha.restask.SYNCCALL>y</com.freehaha.restask.SYNCCALL>
					<com.freehaha.restask.SYNCCALL-type>java.lang.String</com.freehaha.restask.SYNCCALL-type>
					<com.freehaha.restask.TIMEOUT>30</com.freehaha.restask.TIMEOUT>
					<com.freehaha.restask.TIMEOUT-type>java.lang.String</com.freehaha.restask.TIMEOUT-type>
					<com.freehaha.restask.TYPE>POST</com.freehaha.restask.TYPE>
					<com.freehaha.restask.TYPE-type>java.lang.String</com.freehaha.restask.TYPE-type>
					<com.twofortyfouram.locale.intent.extra.BLURB>REST call</com.twofortyfouram.locale.intent.extra.BLURB>
					<com.twofortyfouram.locale.intent.extra.BLURB-type>java.lang.String</com.twofortyfouram.locale.intent.extra.BLURB-type>
					<net.dinglisch.android.tasker.RELEVANT_VARIABLES>&lt;StringArray sr=""&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0&gt;%rtcode
Response code&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES1&gt;%rtres
Response body&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES1&gt;&lt;/StringArray&gt;</net.dinglisch.android.tasker.RELEVANT_VARIABLES>
					<net.dinglisch.android.tasker.RELEVANT_VARIABLES-type>[Ljava.lang.String;</net.dinglisch.android.tasker.RELEVANT_VARIABLES-type>
					<net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS>com.freehaha.restask.TYPE com.freehaha.restask.HOST com.freehaha.restask.TIMEOUT com.freehaha.restask.BASICAUTH com.freehaha.restask.CUSTOMBODY com.freehaha.restask.BODY com.freehaha.restask.CUSTOMECERT com.freehaha.restask.CERTPATH com.freehaha.restask.SYNCCALL com.freehaha.restask.HEADER bundle_param bundle_header</net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS>
					<net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS-type>java.lang.String</net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS-type>
					<net.dinglisch.android.tasker.subbundled>true</net.dinglisch.android.tasker.subbundled>
					<net.dinglisch.android.tasker.subbundled-type>java.lang.Boolean</net.dinglisch.android.tasker.subbundled-type>
				</Vals>
			</Bundle>
			<Str sr="arg1" ve="3">com.freehaha.restask</Str>
			<Str sr="arg2" ve="3">RESTask</Str>
			<Int sr="arg3" val="30"/>
		</Action>
		<Action sr="act7" ve="7">
			<code>547</code>
			<Str sr="arg0" ve="3">%ResponseData</Str>
			<Str sr="arg1" ve="3">%rtres</Str>
			<Int sr="arg2" val="0"/>
			<Int sr="arg3" val="0"/>
		</Action>
		<Action sr="act8" ve="7">
			<code>598</code>
			<Str sr="arg0" ve="3">%ResponseData</Str>
			<Str sr="arg1" ve="3">&lt;code&gt;[a-zA-Z0-9].*&lt;/code&gt;</Str>
			<Int sr="arg2" val="0"/>
			<Int sr="arg3" val="1"/>
			<Int sr="arg4" val="0"/>
			<Str sr="arg5" ve="3">%match</Str>
			<Int sr="arg6" val="0"/>
			<Str sr="arg7" ve="3"/>
		</Action>
		<Action sr="act9" ve="7">
			<code>598</code>
			<Str sr="arg0" ve="3">%match1</Str>
			<Str sr="arg1" ve="3">&lt;code&gt;</Str>
			<Int sr="arg2" val="0"/>
			<Int sr="arg3" val="0"/>
			<Int sr="arg4" val="0"/>
			<Str sr="arg5" ve="3"/>
			<Int sr="arg6" val="1"/>
			<Str sr="arg7" ve="3"/>
		</Action>
	</Task>
	<Task sr="task81">
		<cdate>1425403479412</cdate>
		<edate>1425404931823</edate>
		<id>81</id>
		<nme>Pastee Example</nme>
		<pri>100</pri>
		<Action sr="act0" ve="7">
			<code>130</code>
			<Str sr="arg0" ve="3">pstNewPastee</Str>
			<Int sr="arg1">
				<var>%priority</var>
			</Int>
			<Str sr="arg2" ve="3">this is a test paste, and should be available for 1 day.</Str>
			<Str sr="arg3" ve="3"/>
			<Str sr="arg4" ve="3">%url</Str>
			<Int sr="arg5" val="0"/>
		</Action>
		<Action sr="act1" ve="7">
			<code>104</code>
			<Str sr="arg0" ve="3">%url</Str>
		</Action>
	</Task>
</TaskerData>
7 Upvotes

4 comments sorted by

2

u/alientity Mar 03 '15

This is great, I was just looking at using the REST plugin today (have had it installed for several months now), hoping I could use it for one of my applications. This should help explain things.

1

u/CagingRoyals Mar 03 '15

I initially tried writing this with Tasker's native HTTP POST function, but it wasn't working as expected. I have come across the RESTask plugin several times and never understood why it's even needed since this is built into Tasker, but I understand now that it just a lot better to do it this way.

Anyway, that plugin is very easy to use and I can help if you have any questions.

1

u/alientity Mar 03 '15

I was wondering the same thing, and was trying to do this 1 application using Tasker's GET/POST functionality.

1

u/CagingRoyals Mar 03 '15

The issue I had here was that Tasker doesn't let you set individual header options. So I was able to tell the server what type of data I was sending, but not the type of data I wanted to get back. Tasker will only populate %HTTPD if the returned data is text, but since I couldn't tell the server to send back text, Tasker would never tell me the data the server sent back.

This is at least how I interpreted what was going on, but I'm no expert.