Mary Dickson Diaz

Code, Life, Learning

Tag: API

how to use the wordpress rest api in rails

Folks, if you’re reading this over at www.marydickson.info, my Rails portfolio site, things are about to get real meta. Several weeks ago I RSVPed for a WordPress Developer’s meetup called Introduction to the REST API. I’ve used APIs with Rails, Angular, and in Twitterbots– an API (application program interface) is simply a way to transfer information from a server to a client, often using a format called JSON (JavaScript object notation). APIs are key to mobile apps that access the same database as a web based site. “REST” (representational state transfer) means that a system understands a set of standard verbs used to communicate over HTML, including: GET, POST, PUT, DELETE, etc. You can use an AJAX (asynchronous JavaScript and xml) call to transmit data via the REST verbs and either fetch data, post new data, update existing data, or delete a record, and the information will be persisted in a database somewhere behind the scenes.

That’s a lot of acronyms. Here have a picture:

how APIs work, sort of

Super! MARY, BUT WHY SHOULD WE CARE?

Long story short: I’ve had this WordPress blog since I started coding, and since then I’ve coded other web sites “from scratch,” including a professional portfolio site, that are much easier for me to customize and that add legitimacy to my claim of web developer. So that is what I want to share with potential employers but I also want them to see my awesome technical blog posts so they will think “She sounds cool and writes good. Let’s pay her money in exchange for her time!” UNTIL NOW the way to do that was to direct people to this site, marydickson.com, and hope that they will also go check out marydickson.info, or vice versa. Awkward.

The WordPress API allows me to import blog posts from marydickson.com and render them as a tab on marydickson.info. If you have any sort of non-WordPress site and you’d like to link to or display your blog posts, you can do that with the WordPress REST API. I’ll walk you through what I did to get this working in a Rails app:

Continue reading

build something with socrata’s api — check

weed violations screenshotTop of my to-do list has been to build something using data from the City of Seattle data portal (data.seattle.gov), powered by Socrata. This one is not particularly useful, but I’ll share with you anyway!

One of the things I like least about homeownership is the need to keep up a yard. Thankfully I’ve never received nastygrams about yard care, but I’ve heard some horror stories. One couple in Texas was in the process of removing a dead tree from their yard — they had just cut it down and into transportable sized pieces, and piled and covered the logs up with a tarp, and THE NEXT DAY they got a note demanding they remove “tree debris” from their yard within three days or pay a penalty.

Anyway, in that frame of mind I giggled through the “weed and vegetation code citations” available via public record. Since Washington legalized marijuana last year, I had an idea in my mind to track code citations like these:

  • Large overgrown blackberries and vegetation encroaching sidewalk
  • Hazardous vegetation encroaching on sidewalk forcing pedestrians into street
  • OBSERVED LARGE TREE ON PROPERTY NO SIGNS OF RODENTS AND NO BEES WERE PRESENT DURING A SUNNY DAY

…and present them as our city’s most pressing weed violations.

Clever? Maybe. Half-baked? Definitely. My first idea was to tweet out the description of the citation, with a google maps street-view image of the address in question. That might be visually interesting but seemed like a huge invasion of privacy, so I quickly shelved it. I have no interest in actually shaming the property owners.

So instead I started with the easiest path, tweet the generic descriptions, to see where that led me. Here are the “get-started” steps:

  1. Register for a developer key with Socrata
  2. Identify the data set you want at data.seattle.gov (for me: code violations)
  3. Use developer key to access the API (I used a Ruby gem from Socrata) to fetch that data set
  4. Filter (for code group: “weed and vegetation”) and collect results in an array
  5. Set up a Twitter API client to talk to twitter, via a new twitter account if needed (I recycled an existing bot!)

Continue reading

© 2019 Mary Dickson Diaz

Theme by Anders NorenUp ↑