mirror of
https://github.com/holidayapi/holidayapi-ruby.git
synced 2025-06-21 12:36:34 +00:00
Ruby library
This commit is contained in:
parent
9642005814
commit
6d95a482ec
4 changed files with 57 additions and 3 deletions
36
lib/ruby-holidayapi.rb
Normal file
36
lib/ruby-holidayapi.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
require 'addressable/uri'
|
||||
require 'json'
|
||||
require 'net/http'
|
||||
require 'openssl'
|
||||
|
||||
module HolidayAPI
|
||||
class V1
|
||||
def initialize(key = false)
|
||||
@key = key
|
||||
end
|
||||
|
||||
def holidays(params = Hash.new)
|
||||
if !params.has_key?('key')
|
||||
params['key'] = @key
|
||||
end
|
||||
|
||||
uri = Addressable::URI.new
|
||||
uri.query_values = params
|
||||
|
||||
uri = URI("https://holidayapi.com/v1/holidays?#{uri.query}")
|
||||
|
||||
Net::HTTP.start(
|
||||
uri.host,
|
||||
uri.port,
|
||||
:use_ssl => true,
|
||||
:verify_mode => OpenSSL::SSL::VERIFY_NONE
|
||||
) do |http|
|
||||
request = Net::HTTP::Get.new uri
|
||||
|
||||
response = http.request request
|
||||
return JSON.parse(response.body)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue