From 6d95a482ec3b36a2bbeae8ab51c588a072cc9ccf Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Tue, 30 Aug 2016 23:49:50 -0500 Subject: [PATCH] Ruby library --- .gitignore | 6 +++--- Gemfile | 5 +++++ lib/ruby-holidayapi.rb | 36 ++++++++++++++++++++++++++++++++++++ ruby-holidayapi.gemspec | 13 +++++++++++++ 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 Gemfile create mode 100644 lib/ruby-holidayapi.rb create mode 100644 ruby-holidayapi.gemspec diff --git a/.gitignore b/.gitignore index 5e1422c..1115c98 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..3f1b673 --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gem "addressable" + +gemspec diff --git a/lib/ruby-holidayapi.rb b/lib/ruby-holidayapi.rb new file mode 100644 index 0000000..6c79499 --- /dev/null +++ b/lib/ruby-holidayapi.rb @@ -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 + diff --git a/ruby-holidayapi.gemspec b/ruby-holidayapi.gemspec new file mode 100644 index 0000000..238dbef --- /dev/null +++ b/ruby-holidayapi.gemspec @@ -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 +