mirror of
https://github.com/holidayapi/holidayapi-ruby.git
synced 2025-06-20 20:25:06 +00:00
Ruby library
This commit is contained in:
parent
9642005814
commit
6d95a482ec
4 changed files with 57 additions and 3 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -42,9 +42,9 @@ build-iPhoneSimulator/
|
|||
|
||||
# for a library or gem, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# Gemfile.lock
|
||||
# .ruby-version
|
||||
# .ruby-gemset
|
||||
Gemfile.lock
|
||||
.ruby-version
|
||||
.ruby-gemset
|
||||
|
||||
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
||||
.rvmrc
|
||||
|
|
5
Gemfile
Normal file
5
Gemfile
Normal file
|
@ -0,0 +1,5 @@
|
|||
source "https://rubygems.org"
|
||||
|
||||
gem "addressable"
|
||||
|
||||
gemspec
|
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
|
||||
|
13
ruby-holidayapi.gemspec
Normal file
13
ruby-holidayapi.gemspec
Normal file
|
@ -0,0 +1,13 @@
|
|||
Gem::Specification.new do |s|
|
||||
s.name = 'ruby-holidayapi'
|
||||
s.version = '1.0.0'
|
||||
s.date = '2016-08-30'
|
||||
s.summary = 'Official Ruby library for Holiday API'
|
||||
s.description = 'Official Ruby library for Holiday API'
|
||||
s.authors = ['Josh Sherman']
|
||||
s.email = 'hello@holidayapi.com'
|
||||
s.files = ['lib/ruby-holidayapi.rb']
|
||||
s.homepage = 'https://holidayapi.com'
|
||||
s.license = 'MIT'
|
||||
end
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue