DEV Community

Cover image for 3 minimal features for my dev.to api wrapper
Dave Parr
Dave Parr

Posted on • Edited on • Originally published at daveparr.info

1 1

3 minimal features for my dev.to api wrapper

I’ve made 3 very small features for my open source R package wrapping
the dev.to API
.

create_new_article

Now that the main requirements for the file to post are stabilising,
I’ve written a quick and dirty function to make a boilerplate article:

create_new_article <-
  function(title,
           series = 'series',
           tags = '["tag1", "tag2"]',
           file = "") {
    boilerplate_frontmatter <-
      glue::glue(
        '---\ntitle: "{title}"\noutput: github_document\nseries: "{series}"\ntags: {tags}\n---'
      )

    cat(boilerplate_frontmatter, file = file)
  }
Enter fullscreen mode Exit fullscreen mode

This will use the glue package to put
the strings in the function argument into the right place in the
boilerplate YAML front matter. If then uses cat to either print that
to screen, or to create a new file with it, if a file path is supplied.

main_image

If there is a main_image parameter in the YAML front matter that is
a url of an image, that image will be set as the cover image of the
post. I got this one from a photo by Julian
Dufort

on
Unsplash.
I believe that if you put an unsplash URL into this field that goes
directly to the image it is within their
license, though if anyone knows
something to the contrary please let me know. It’s the first time I have
used this service, despite hearing about it for years.

Collapse spaces tags

I recently fooled myself for a good ten minutes into thinking that there
was a problem with my API code yesterday when I kept getting a 422
response to putting a new article up, when in fact it was that I had a
space character in one of my tags. Now the post_new_article function
collapses any spaces it encounters in tags. Achieving this was a breeze
with purrr and
stringr:

purrr::map(file_frontmatter$tags, stringr::str_remove_all, " ")
Enter fullscreen mode Exit fullscreen mode

This little nugget takes the list of tags, and then maps the function
str_remove_all across all the spaces. This isn’t at all exposed to the
user, as it’s non-negotiable from the API side anyway :)

ACI image

ACI.dev: Best Open-Source Composio Alternative (AI Agent Tooling)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Star our GitHub!

Top comments (0)

ACI image

ACI.dev: Fully Open-source AI Agent Tool-Use Infra (Composio Alternative)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Check out our GitHub!

Join the Runner H "AI Agent Prompting" Challenge: $10,000 in Prizes for 20 Winners!

Runner H is the AI agent you can delegate all your boring and repetitive tasks to - an autonomous agent that can use any tools you give it and complete full tasks from a single prompt.

Check out the challenge

DEV is bringing live events to the community. Dismiss if you're not interested. ❤️