Skip to content

Numbers: random numbers facts #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/tlaws.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
module Tlaws
# Your code goes here...
end

require_relative 'tlaws/numbers'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should require them all here. Imagine some of the wrappers depend on other libraries (like nokogiri, or some geo-services, or even SQL databases) — we don't want all of it to be required at once. Typical use case is "I install entire Tlaws (say, 30 wrappers), but use only wrappers X and Y, so I require only them".

60 changes: 60 additions & 0 deletions lib/tlaws/numbers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
require 'tlaw'


module Tlaws
class Numbers < TLAW::API
define do
desc %Q{
Wrapper for [Numbers API](http://numbersapi.com). Facts about numbers.
}

docs 'http://numbersapi.com'

base 'http://numbersapi.com'

namespace :[], '/{numb}' do
desc %Q{
Facts about numbers.
}

param :numb, required: true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it number, as in original docs. Two chars is not that much economy :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix it


endpoint :math, '/math?json' do
desc %Q{
Get an interesting mathematical fact about the number.

NB:
}
end
end

namespace :random do
desc %Q{
Facts about random numbers.
}
endpoint :math, '/math?json' do
desc %Q{
Get an interesting mathematical fact about the random number.
}
end
endpoint :year, '/year?json' do
desc %Q{
Get an interesting fact about the random year.
}
end
endpoint :date, '/date?json' do
desc %Q{
Get an interesting fact about the date number.
}
end
endpoint :trivia, '/trivia?json' do
desc %Q{
Get an interesting fact about the random number.
}
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the same endpoints repeats for one number ([]), and for the random number? Then let's make it DRY somehow (var.1: just do something like %i[random, []].each do |namespace| ..., var.2: try to introduce some solution in TLAW itself, that will allow to describe "shared endpoints" (like "shared examples" in RSpec), and then just include_endpoints "number endpoints" in DSL?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, got it


end

end
end
end
10 changes: 5 additions & 5 deletions tlaws.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ require "tlaws/version"
Gem::Specification.new do |spec|
spec.name = "tlaws"
spec.version = Tlaws::VERSION
spec.authors = ["TODO: Write your name"]
spec.email = ["TODO: Write your email address"]
spec.authors = ["Yuri Valigursky"]
spec.email = ["[email protected]"]

spec.summary = %q{TODO: Write a short summary, because Rubygems requires one.}
spec.description = %q{TODO: Write a longer description or delete this line.}
spec.homepage = "TODO: Put your gem's website or public repo URL here."
spec.summary = %q{A repository for TLAW-based thin API wrappers, for all the world}
spec.description = %q{A repository for TLAW-based thin API wrappers, for all the world}
spec.homepage = "https://github.com/molybdenum-99/tlaws"
spec.license = "MIT"

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
Expand Down