Skip to content

Commit

Permalink
Merge pull request #2 from samudary/0.2.0
Browse files Browse the repository at this point in the history
Update dependencies, general cleanup & bump to version 0.2.0
  • Loading branch information
samudary authored Jul 12, 2021
2 parents 08f6e24 + c5e464c commit 2903305
Show file tree
Hide file tree
Showing 22 changed files with 347 additions and 151 deletions.
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.7.4
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in demio_ruby.gemspec
gemspec
100 changes: 50 additions & 50 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
PATH
remote: .
specs:
demio-ruby (0.1.0)
demio-ruby (0.2.0)

GEM
remote: https://rubygems.org/
specs:
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ast (2.4.0)
coderay (1.1.2)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.3)
hashdiff (0.3.7)
jaro_winkler (1.5.1)
method_source (0.8.2)
parallel (1.12.1)
parser (2.5.1.0)
ast (~> 2.4.0)
powerpack (0.1.2)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
public_suffix (3.0.2)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.2)
coderay (1.1.3)
crack (0.4.5)
rexml
diff-lcs (1.4.4)
hashdiff (1.0.1)
method_source (1.0.0)
parallel (1.20.1)
parser (3.0.2.0)
ast (~> 2.4.1)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (4.0.6)
rainbow (3.0.0)
rake (10.5.0)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.0)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
rake (13.0.6)
regexp_parser (2.1.1)
rexml (3.2.5)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.0)
rubocop (0.57.2)
jaro_winkler (~> 1.5.1)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rubocop (1.18.3)
parallel (~> 1.10)
parser (>= 2.5)
powerpack (~> 0.1)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.7.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
safe_yaml (1.0.4)
slop (3.6.0)
unicode-display_width (1.4.0)
webmock (3.4.2)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.7.0)
parser (>= 3.0.1.1)
ruby-progressbar (1.11.0)
unicode-display_width (2.0.0)
webmock (3.13.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
hashdiff (>= 0.4.0, < 2.0.0)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.16)
bundler (~> 2.2.23)
demio-ruby!
pry (~> 0.10.3)
rake (~> 10.0)
rspec (~> 3.0)
rubocop (~> 0.57.1)
webmock (~> 3.4)
pry (~> 0.14.1)
rake (~> 13.0.6)
rspec (~> 3.10.0)
rubocop (~> 1.18.3)
webmock (~> 3.13.0)

BUNDLED WITH
1.16.1
2.2.23
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Demio Ruby Client

[![Build Status](https://travis-ci.org/samudary/demio-ruby.svg?branch=master)](https://travis-ci.org/samudary/demio-ruby)
![example workflow](https://github.com/samudary/demio-ruby/actions/workflows/ruby.yml/badge.svg)


A Ruby gem for interacting with the [Demio API](https://publicdemioapi.docs.apiary.io/).

Expand Down Expand Up @@ -37,7 +38,8 @@ client = Demio::Client.new(
| :------------------------- | :--------------------------------------------------- |
| List events | `#events` |
| Fetch an event | `#event(event_id)` |
| Fetch event date info | `#event_date(event_id, date_id)` |
| Fetch event date info | `#event_date(event_id, event_date_id)` |
| Fetch participants list | `#participants(event_date_id)` |
| Register a registrant | `#register(payload = {})` |
| Ping | `#ping` |

Expand Down
1 change: 1 addition & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "demio"
Expand Down
12 changes: 6 additions & 6 deletions demio-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = '>= 2.1'

spec.add_development_dependency "bundler", "~> 1.16"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rubocop", "~> 0.57.1"
spec.add_development_dependency "pry", "~> 0.10.3"
spec.add_development_dependency "webmock", "~> 3.4"
spec.add_development_dependency "bundler", "~> 2.2.23"
spec.add_development_dependency "rake", "~> 13.0.6"
spec.add_development_dependency "rspec", "~> 3.10.0"
spec.add_development_dependency "rubocop", "~> 1.18.3"
spec.add_development_dependency "pry", "~> 0.14.1"
spec.add_development_dependency "webmock", "~> 3.13.0"
end
51 changes: 32 additions & 19 deletions lib/demio/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "demio/event"
require "demio/event_date"
require "demio/events"
require "demio/participants"
require "demio/register"
require "json"
require "net/http"
Expand All @@ -14,10 +15,13 @@ class Client
include Event
include EventDate
include Events
include Participants
include Register

attr_reader :api_key, :api_secret

REQUEST_REDIRECT_FOLLOW_LIMIT = 10

def initialize(options = {})
@api_key = options[:api_key]
@api_secret = options[:api_secret]
Expand All @@ -40,28 +44,33 @@ def ping

private

def make_request(verb_klass, uri, payload = {}, limit = 10)
raise TooManyRedirectsError, "too many HTTP redirects" if limit.zero?
def make_request(verb_klass, uri, payload = {}, request_limit = REQUEST_REDIRECT_FOLLOW_LIMIT)
raise TooManyRedirectsError, "too many HTTP redirects" if request_limit.zero?

uri = format_uri(uri)
uri = redirected_request?(request_limit) ? URI(uri) : format_uri(uri)

Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
request = verb_klass.new uri
request = create_headers(request)

request.body = payload.to_json if verb_klass == Net::HTTP::Put

response = http.request request

case response
when Net::HTTPSuccess then
response
when Net::HTTPRedirection then
location = response["location"]
make_request(verb_klass, location, payload, limit - 1)
else
response.value
end
response = http.request(create_request(verb_klass, uri, payload))
handle_response(response, verb_klass, payload, request_limit)
end
end

def create_request(verb_klass, uri, payload)
request = verb_klass.new(uri)
request = create_headers(request)
request.body = payload.to_json if verb_klass == Net::HTTP::Put
request
end

def handle_response(response, verb_klass, payload, request_limit)
case response
when Net::HTTPSuccess
response
when Net::HTTPRedirection
location = response["Location"]
make_request(verb_klass, location, payload, request_limit - 1)
else
response.value
end
end

Expand All @@ -73,6 +82,10 @@ def create_headers(request)
request
end

def redirected_request?(request_limit)
request_limit < REQUEST_REDIRECT_FOLLOW_LIMIT
end

def format_uri(path)
URI(base_uri + path)
end
Expand Down
8 changes: 5 additions & 3 deletions lib/demio/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ module Event
# Fetches a single event from Demio
#
# @param id [String]
# @return [Net::HTTPCreated]
def event(id)
get "event/#{id}"
# @param active [Boolean]
# @return [Net::HTTPOk]
def event(id, active = nil)
active_param = active ? "?active=#{active}" : nil
get "event/#{id}#{active_param}"
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/demio/event_date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class Client
module EventDate
# Fetches info about a specific date from Demio
#
# @param id [String]
# @param date_id [String]
# @return [Net::HTTPCreated]
def event_date(id, date_id)
get "event/#{id}/#{date_id}"
# @param event_id [String]
# @param event_date_id [String]
# @return [Net::HTTPOk]
def event_date(event_id, event_date_id)
get "event/#{event_id}/date/#{event_date_id}"
end
end
end
Expand Down
8 changes: 5 additions & 3 deletions lib/demio/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ class Client
module Events
# Fetches all events from Demio
#
# @return [Net::HTTPCreated]
def events
get "events"
# @param type [String]
# @return [Net::HTTPOk]
def events(type = nil)
type_param = type ? "?type=#{type}" : nil
get "events#{type_param}"
end
end
end
Expand Down
17 changes: 17 additions & 0 deletions lib/demio/participants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Demio
class Client
module Participants
# Returns Event Date participants list
#
# @param event_date_id [String]
# @params status [String]
# @return [Net::HTTPOk]
def participants(event_date_id, status = nil)
status_param = status ? "?status=#{status}" : nil
get "report/#{event_date_id}/participants#{status_param}"
end
end
end
end
1 change: 1 addition & 0 deletions lib/demio/register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Demio
class Client
module Register
# Adds a registrant to an event in Demio
# Docs: https://publicdemioapi.docs.apiary.io/#reference/events/register/register
#
# @param payload [Hash]
# @return [Net::HTTPCreated]
Expand Down
4 changes: 3 additions & 1 deletion lib/demio/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Demio
VERSION = "0.1.0".freeze
VERSION = "0.2.0"
end
Loading

0 comments on commit 2903305

Please sign in to comment.