This repository contains shared tools and libraries to help development of crystal libraries easier.
-
Add the dependency to your
shard.yml
:dependencies: spoved: github: spoved/spoved.cr
-
Run
shards install
You can use this exactly like the base class ::Logger
:
require "spoved/logger"
logger = Spoved::Logger.new(STDOUT)
logger.level = Logger::DEBUG
logger.debug("this is an debug msg")
logger.info("this is an info msg")
logger.warn("this is an warn msg")
logger.error("this is an error msg")
logger.fatal("this is an fatal msg")
logger.unknown("this is an unknown msg")
Or you can use the spoved_logger
to automatically add the logger methods to any class:
require "spoved/logger"
class TestObj
spoved_logger
end
obj = TestObj.new
obj.logger.debug("I can log a debug now")
This also adds a class/module level logger:
require "spoved/logger"
class TestObj
spoved_logger
end
TestObj.logger.debug("I can log a debug now")
The Spoved::Api::Client
also provides an abstraction wrapper for Halite to make creation of basic api clients easier.
require "spoved/api/client"
client = Spoved::Api::Client.new("jsonplaceholder.typicode.com", scheme: "https", api_path: "")
client.should_not be_nil
resp = client.get("todos/1")
resp["title"] # => "delectus aut autem"
You can also extend it to simplify creation of api clients:
require "spoved/api/client"
class TodoClient < Spoved::Api::Client
def initialize
@host = "jsonplaceholder.typicode.com"
end
def todo(id)
client.get("todos/#{id}")
end
end
client = TodoClient.new
client.todo(1)["title"] # => "delectus aut autem"
- Fork it (https://github.com/spoved/spoved.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Holden Omans - creator and maintainer