Skip to content

Commit

Permalink
URL encode characters
Browse files Browse the repository at this point in the history
- add encoding of special characters
- add CONTRIBUTOR.md
  • Loading branch information
skeletonkey committed Oct 30, 2023
1 parent 004eafc commit bcacf3b
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 11 deletions.
20 changes: 20 additions & 0 deletions CONTRIBUTOR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Joplin Alfred Workflow Contributor Guidelines

## Requirements

- Curl
- Perl 5

### Jundy::AlfredWorkflow

[This repository](https://github.com/skeletonkey/Jundy_AlfredWorkflow) contains all reusable code. You will also want to fork it.

## Contribute

- create (or claim) an [issue](https://github.com/skeletonkey/joplin_alfred_workflow/issues)
- assign it to yourself
- all communication will be done through Github Issues
- submit pull request
- a code owner should review and provide feedback within a week of submittal/response
- the PR author is required to response to all feedback within a month of it being provided
- PRs not responded to within 2 months will be removed
9 changes: 7 additions & 2 deletions Joplin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@ package Joplin;

use JSON;

# https://joplinapp.org/api/references/rest_api/
use Jundy::AlfredWorkflow::HTTP;

# https://joplinapp.org/help/api/references/rest_api#using-the-api

sub get_data {
my $url_parts = shift || [];
my $query_map = shift || {};

$query_map->{token} = $ENV{JOPLIN_TOKEN};
$query_map->{fields} = 'id,title';
$query_map->{limit} = 9;
$query_map->{order_by} = "updated_time";

my $url = join("/", $ENV{JOPLIN_URL}, @$url_parts);
if ($query_map) {
$url .= '?';
$url .= join("&", map { "$_=$query_map->{$_}"} keys %$query_map);
$url .= join("&", map { "$_=" . Jundy::AlfredWorkflow::HTTP::url_encode($query_map->{$_})} keys %$query_map);
}

my $resp = `curl -s -q "$url"`;
Expand Down
38 changes: 38 additions & 0 deletions Jundy/AlfredWorkflow/HTTP.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package Jundy::AlfredWorkflow::HTTP;

my %_url_translation = (
' ' => '%20',
'!' => '%21',
'"' => '%22',
'#' => '%23',
'$' => '%24',
'%' => '%25',
'&' => '%26',
"'" => '%27',
'(' => '%28',
')' => '%29',
'*' => '%2A',
'+' => '%2B',
',' => '%2C',
'/' => '%2F',
':' => '%3A',
';' => '%3B',
'=' => '%3D',
'?' => '%3F',
'@' => '%40',
'[' => '%5B',
']' => '%5D',
);
sub url_encode {
return join("",
map({
if (exists $_url_translation{$_}) {
$_url_translation{$_};
} else {
$_;
}
} split(//, $_[0]))
)
}

1;
10 changes: 5 additions & 5 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<key>script</key>
<string>query=$*
perl search_notes.pl "$query" 2&gt;&amp;1</string>
perl search_notes.pl $query 2&gt;&amp;1</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
Expand Down Expand Up @@ -116,16 +116,16 @@ Report issues here: https://github.com/skeletonkey/joplin_alfred_workflow/issues
<key>note</key>
<string>Please submit issues and feature requests at https://github.com/skeletonkey/joplin_alfred_workflow/issues</string>
<key>xpos</key>
<real>220</real>
<real>370</real>
<key>ypos</key>
<real>180</real>
<real>200</real>
</dict>
<key>7ECD89F0-69D5-4743-AAF9-E0C2751C5A6E</key>
<dict>
<key>xpos</key>
<real>455</real>
<real>655</real>
<key>ypos</key>
<real>180</real>
<real>200</real>
</dict>
</dict>
<key>userconfigurationconfig</key>
Expand Down
7 changes: 3 additions & 4 deletions search_notes.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

use Joplin;

my $find = $ARGV[0];
my %links;

find_link($find);
find_link(@ARGV);

sub find_link {
my $find = join(' ', @ARGV);

my $tmpl = '"title":"%s","subtitle":"%s","arg":"%s"';

my $data = Joplin::get_data(["search"], { "query" => $find });
Expand Down

0 comments on commit bcacf3b

Please sign in to comment.