Giter Site home page Giter Site logo

creddit's Introduction

Hi ๐Ÿ‘‹, I'm Conor

Senior Full Stack Developer from Dublin, Ireland ๐Ÿ‡ฎ๐Ÿ‡ช

  • ๐Ÿ’ผ Senior Full Stack Developer at goPeer

  • ๐Ÿ’ป Current tech stack is Vue.js, Node.js, PostgreSQL, AWS

  • ๐Ÿ“š Experience with Clojure, Java, ClojureScript, Elasticsearch, Kafka

  • ๐ŸŒฑ Iโ€™m currently learning React, Typescript and GraphQL

creddit's People

Contributors

0x43eba avatar saejo avatar saurabh-ku avatar sharms avatar sli avatar thatguyhughesy avatar wjlafrance avatar xivh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

creddit's Issues

URL functions instead of hard coded strings

In each of our wrapper functions we are calling the http-get method with a hard coded string for the API URL.

(http-get credentials (str "https://www.reddit.com/.json?limit=" limit "&t=" (name time))

Here are some different approaches that we could take

  1. Custom function for each URL
(http-get credentials (str (url/subreddit "aww") "?limit=" limit "&t=" (name time))
  1. Decorative functions
(-> reddit
      (subreddit "awww')
      (limit 1)
      (time :hour))

The reddit function creates the base url and each function then decorates on top of it
With this approach we might not need to create custom url for each endpoint, instead we just need a small set of decorators.
The con is that it will be difficult to manage invalid URLs, not sure how to handle that.

  1. Create a custom DLS like hiccup
[:reddit
  [:subreddit "aww"]
  [:limit 1]
  [:time :hour]]

Works out same as the decorative model but this allows for easy algorithmic url creation. This is very suitable of the url is to be created at run time. Might be a lot of fun to build as well.

The reason I am suggesting this change is that in all of our wrapper functions the only thing that is different is the URL for the API and creating a custom wrapper function for each endpoint might not be scalable.

With functions that generate url we can change the client to look something like this

(defn reddit-client [cred url]
  (-> (http-get cred (build-url url))
        (process-response))

And the usage would be something like this

(reddit-client 
      cred  
      [:reddit
          [:subreddit "aww"]
          [:limit 1]
          [:time :hour]])
  1. In the decorative model supporting new URL's will be easier and much more reuse-able.
  2. URL's can be stored since they are merely data allowing for more flexibility
  3. Makes the process a little more pure

What are your thoughts on it?

Support User Actions

User actions aren't currently supported, such as submit.

I created #24 as an example with the submit endpoint, but there are a lot more available. There also needs to be a way to refresh the token. I'm not experienced with Clojure so if you could take a look at my code and give me some feedback that would be great, and I can add more endpoints if #21 hasn't been implemented yet.

Simplify parse-response using map

In the function parse-response we are using reduce to get the inner data from the list of posts returned from the API.

(defn- parse-response
  [response]
  (if-let [data (or (get-in response [:data :children])
                    (get-in response [:data :trophies]))]
    (reduce
      (fn [posts post]
        (conj posts (:data post)))
      []
      data)
    (:data response)))

This code can be simplified using map instead of reduce

(defn- parse-response
  [response]
  (if-let [coll (or (get-in response [:data :children])
                    (get-in response [:data :trophies]))]
    (map :data coll)
    (:data response)))

This can make the code a little more readable. Also renaming the variable will make it more obvious that we are dealing with a collection of values. What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.