andersonkrs / malheatmap

An extension for tracking your activities on myanimelist.net
https://malheatmap.com
MIT License
99 stars 2 forks source link

Refactor the NetHttp wrapper to have better internals #918

Open andersonkrs opened 7 months ago

andersonkrs commented 7 months ago

The first pass on writing a generic NetHttp wrapper was a good start but it is time to evolve, the code needs some clean up.

The idea is to end with an API like this

class ApiClient < HttpClient::Base
  self.site = "https://jsonplaceholder.typicode.com"
  self.content_type = :json

  def fetch_post(id:)
    get("/posts/#{id}")
  end

  def create_post(title:, body:)
    post("/posts", body: {
      title: title,
      body: body,
      userId: 1
    })
 end

 response = ApiClient.create_post(title: "foo", body: "bar")

 response = ApiClient.fetch_post(id: 1)