Skip to content

Commit

Permalink
CI test in preparation for a Raku Community release
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Dec 27, 2024
1 parent cc0ab2f commit a557896
Show file tree
Hide file tree
Showing 15 changed files with 350 additions and 118 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Linux

on:
push:
branches:
- '*'
tags-ignore:
- '*'
pull_request:

jobs:
raku:
strategy:
matrix:
os:
- ubuntu-latest
raku-version:
- 'latest'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: Raku/setup-raku@v1
with:
raku-version: ${{ matrix.raku-version }}
- name: Install Dependencies
run: zef install --/test --test-depends --deps-only .
- name: Run Special Tests
run: raku run-tests -i
32 changes: 32 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: MacOS

on:
push:
branches:
- '*'
tags-ignore:
- '*'
pull_request:

jobs:
raku:
strategy:
matrix:
os:
- macos-latest
raku-version:
- 'latest'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: Raku/setup-raku@v1
with:
raku-version: ${{ matrix.raku-version }}
- name: Install NotmuchMail
run: brew install notmuch
- name: Make NotMuchMailD reachable
run: raku -e 'symlink "/opt/homebrew/lib/libnotmuch.5.dylib".IO, $*EXECUTABLE.parent.sibling("lib/libnotmuch.5.dylib")'
- name: Install Dependencies
run: zef install --/test --test-depends --deps-only .
- name: Run Special Tests
run: raku run-tests -i
28 changes: 28 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Windows

on:
push:
branches:
- '*'
tags-ignore:
- '*'
pull_request:

jobs:
raku:
strategy:
matrix:
os:
- windows-latest
raku-version:
- 'latest'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: Raku/setup-raku@v1
with:
raku-version: ${{ matrix.raku-version }}
- name: Install Dependencies
run: zef install --/test --test-depends --deps-only .
- name: Run Special Tests
run: raku run-tests -i
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Revision history for WWW::DuckDuckGo

{{$NEXT}}
- Initial version as a Raku Community module
47 changes: 31 additions & 16 deletions META6.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
{
"perl": "6.*",
"name" : "WWW::DuckDuckGo",
"license" : "Artistic-2.0",
"tags": ["Web", "API"],
"version" : "0.1.0",
"auth" : "zef:Altai-man",
"description" : "Bindings to DuckDuckGo search API",
"depends" : [ "URI", "HTTP::UserAgent", "JSON::Fast" ],
"provides" : {
"WWW::DuckDuckGo::Icon" : "lib/WWW/DuckDuckGo/Icon.pm6",
"WWW::DuckDuckGo::Link" : "lib/WWW/DuckDuckGo/Link.pm6",
"WWW::DuckDuckGo::ZeroClickInfo" : "lib/WWW/DuckDuckGo/ZeroClickInfo.pm6",
"WWW::DuckDuckGo" : "lib/WWW/DuckDuckGo.pm6"
},
"resources": [],
"source-url" : "git://github.com/Altai-man/p6-WWW-DuckDuckGo.git"
"auth": "zef:raku-communiy-modules",
"author": "Alexander Kiryuhin",
"build-depends": [
],
"depends": [
"URI",
"HTTP::UserAgent",
"JSON::Fast"
],
"description": "Bindings to DuckDuckGo search API",
"license": "Artistic-2.0",
"name": "WWW::DuckDuckGo",
"perl": "6.*",
"provides": {
"WWW::DuckDuckGo": "lib/WWW/DuckDuckGo.rakumod",
"WWW::DuckDuckGo::Icon": "lib/WWW/DuckDuckGo/Icon.rakumod",
"WWW::DuckDuckGo::Link": "lib/WWW/DuckDuckGo/Link.rakumod",
"WWW::DuckDuckGo::ZeroClickInfo": "lib/WWW/DuckDuckGo/ZeroClickInfo.rakumod"
},
"resources": [
],
"source-url": "https://github.com/raku-community-modules/WWW-DuckDuckGo.git",
"tags": [
"Web",
"API",
"DUCKDUCKGO",
"SEARCH"
],
"test-depends": [
],
"version": "0.1.0"
}
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
[![Actions Status](https://github.com/raku-community-modules/WWW-DuckDuckGo/actions/workflows/linux.yml/badge.svg)](https://github.com/raku-community-modules/WWW-DuckDuckGo/actions) [![Actions Status](https://github.com/raku-community-modules/WWW-DuckDuckGo/actions/workflows/macos.yml/badge.svg)](https://github.com/raku-community-modules/WWW-DuckDuckGo/actions) [![Actions Status](https://github.com/raku-community-modules/WWW-DuckDuckGo/actions/workflows/windows.yml/badge.svg)](https://github.com/raku-community-modules/WWW-DuckDuckGo/actions)

NAME
====

WWW::DuckDuckGo - API bindings for DuckDuckGo search engine.
WWW::DuckDuckGo - Bindings to DuckDuckGo search API

SYNOPSIS
========

```perl6
use WWW::DuckDuckGo;
my $duck = WWW::DuckDuckGo.new;
my $zeroclickinfo1 = $duck.zci('duck duck go');
my $zeroclickinfo2 = $duck.zci('one', 'another');
```raku
use WWW::DuckDuckGo;

my $duck = WWW::DuckDuckGo.new;
my $zeroclickinfo1 = $duck.zci('duck duck go');
my $zeroclickinfo2 = $duck.zci('one', 'another');
```

DESCRIPTION
===========

This class provides a way to get data from DuckDuckGo search service. The basic idea is to create a class instance that represents JSON answer from the server for every query.

This is a functional port of the Perl 5 module of the same name by Torsten Raudssus and Michael Smith, see [WWW::DuckDuckGo](https://metacpan.org/pod/WWW::DuckDuckGo), all bugs with this port must be reported here, not to the original module bugzilla.
This is a functional port of the Perl module of the same name, see [`WWW::DuckDuckGo`](https://metacpan.org/pod/WWW::DuckDuckGo).

AUTHOR
======

Alexander Kiryuhin

COPYRIGHT AND LICENSE
=====================

Copyright 2016 - 2021 Alexander Kiryuhin

Copyright 2024 Raku Community

COPYRIGHT
=========
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.

This library is free software; you can redistribute it and/or modify it under the terms of the [Artistic License 2.0](http://www.perlfoundation.org/artistic_license_2_0)
11 changes: 11 additions & 0 deletions dist.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name = WWW::DuckDuckGo

[ReadmeFromPod]
filename = lib/WWW/DuckDuckGo.rakumod

[UploadToZef]

[Badges]
provider = github-actions/linux.yml
provider = github-actions/macos.yml
provider = github-actions/windows.yml
73 changes: 58 additions & 15 deletions lib/WWW/DuckDuckGo.pm6 → lib/WWW/DuckDuckGo.rakumod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use v6;

unit class WWW::DuckDuckGo;

use JSON::Fast;
Expand Down Expand Up @@ -38,9 +36,9 @@ method zeroclickinfo_request_base($for_uri, @query_fields) {
$uri ~= "&no_redirect=1";
$!html ?? ($uri ~= "&no_html=0") !! ($uri ~= "&no_html=1");
for %params.keys {
$uri ~= "&$_=%params{$_}";
$uri ~= "&$_=%params{$_}";
};
$uri;
$uri
}

method zeroclickinfo_request_secure(@query_fields) {
Expand All @@ -58,23 +56,68 @@ method zeroclickinfo(@query_fields) {
my $res;

try {
my $url = self.zeroclickinfo_request_secure(@query_fields);
$res = $!http-agent.get($url);
my $url = self.zeroclickinfo_request_secure(@query_fields);
$res = $!http-agent.get($url);
}
if (!$!forcesecure && (!$res || !$res.is-success)) {
warn("HTTP request failed " ~ $res.status-line ~ "\n") if ($res && !$res.is-success);
warn("Can't access " ~ $!duckduckgo_api_url_secure ~ " failing back to: " ~ $!duckduckgo_api_url);
my $url = self.zeroclickinfo_request(@query_fields);
$res = $!http-agent.get($url);
if !$!forcesecure && (!$res || !$res.is-success) {
warn("HTTP request failed " ~ $res.status-line ~ "\n")
if ($res && !$res.is-success);
warn("Can't access $!duckduckgo_api_url_secure failing back to: $!duckduckgo_api_url");
my $url = self.zeroclickinfo_request(@query_fields);
$res = $!http-agent.get($url);
}
return self.zeroclickinfo_by_response($res);
self.zeroclickinfo_by_response($res);
}

method zeroclickinfo_by_response($res) {
if $res.is-success {
my $result = from-json($res.content);
return $!zeroclickinfo.new($result);
} else {
die 'HTTP request failed: ' ~ $res.status-line ~ "\n";
return $!zeroclickinfo.new($result);
}
else {
die 'HTTP request failed: ' ~ $res.status-line ~ "\n";
}
}

=begin pod
=head1 NAME
WWW::DuckDuckGo - Bindings to DuckDuckGo search API
=head1 SYNOPSIS
=begin code :lang<raku>
use WWW::DuckDuckGo;
my $duck = WWW::DuckDuckGo.new;
my $zeroclickinfo1 = $duck.zci('duck duck go');
my $zeroclickinfo2 = $duck.zci('one', 'another');
=end code
=head1 DESCRIPTION
This class provides a way to get data from DuckDuckGo search service.
The basic idea is to create a class instance that represents JSON answer
from the server for every query.
This is a functional port of the Perl module of the same name, see
L<C<WWW::DuckDuckGo>|https://metacpan.org/pod/WWW::DuckDuckGo>.
=head1 AUTHOR
Alexander Kiryuhin
=head1 COPYRIGHT AND LICENSE
Copyright 2016 - 2021 Alexander Kiryuhin
Copyright 2024 Raku Community
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.
=end pod

# vim: expandtab shiftwidth=4
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use v6;

unit class WWW::DuckDuckGo::Icon;

use URI;
Expand All @@ -14,3 +12,5 @@ method new($icon_result) {
my $width = $icon_result<width> if $icon_result<Width>;
self.bless(:$url, :$width, :$height);
}

# vim: expandtab shiftwidth=4
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use v6;

unit class WWW::DuckDuckGo::Link;

use WWW::DuckDuckGo::Icon;
Expand All @@ -21,3 +19,5 @@ method new($link_result) {
my $text = $link_result<Text>;
self.bless(:$result, :$first_url, :$icon, :$text);
}

# vim: expandtab shiftwidth=4
Loading

0 comments on commit a557896

Please sign in to comment.