-
-
Save tadzik/37a905d09db571ac02493814a986472f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# $, for "input attributes" becuase I have no better idea right now :) | |
use Woof; # rather than "use Moo? ;)" | |
class Webservice::Access::Thingy { | |
gets $,api-key is required; # has to be passed in to default construtor | |
gets $,timeout = 180; # has a default value | |
# Let's say we'd like to keep an endpoint as a hypothetical HTTP::Path, but we want to be able | |
# to be settable with a regular Str. | |
# With the current "meta" of writing classes, you'd probably make it to attributes: | |
# one of them required and one of them set in BUILD | |
has $.endpoint -> (Str $arg = 'web.servi.ce/v1/') { | |
HTTP::Path.new($arg); | |
} | |
# The block describes how http-client should be built. | |
# The assumption is that all the `gets` input attributes are already received, validated and set, | |
# so can be freely used here: which is not the case at least in Moo(se?)'s "default" blocks | |
has $!http-client -> { | |
LWP::UserAgent.new(:$,timeout); | |
} | |
has $!access-token -> { | |
# $,api-key remains available throughout the object's lifetime, but always means | |
# "that value that the object was configured with, nothing else" | |
$!http-client.get($.endpoint.child('access_token'), :key($,api-key)); | |
} | |
# To be continued...? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Syntax ideas: