-
Notifications
You must be signed in to change notification settings - Fork 10
Freebusy support #11
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
base: main
Are you sure you want to change the base?
Freebusy support #11
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| name: Rubocop | ||
|
|
||
| on: [push, pull_request] | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v2 | ||
|
|
||
| - name: Set up Ruby | ||
| uses: ruby/setup-ruby@v1 | ||
| with: | ||
| ruby-version: 3.1 | ||
| bundler-cache: true | ||
|
|
||
| - name: Rubocop | ||
| run: bundle exec rubocop |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative "../properties/freebusy" | ||
|
|
||
| module Calendav | ||
| module Components | ||
| class Freebusy | ||
| attr_reader :dtend, :dtstart, :dtstamp, :freebusy, :ical_name, :name, | ||
| :parent, :uid | ||
|
|
||
| def self.from_http_response(response) | ||
| ical_freebusy = Icalendar::Freebusy.parse(response).first | ||
|
|
||
| attributes = attributes_from_ical_freebusy(ical_freebusy) | ||
| new(attributes) | ||
| end | ||
|
|
||
| def initialize(attributes) | ||
| @dtend = attributes[:dtend].to_time | ||
| @dtstart = attributes[:dtstart].to_time | ||
| @dtstamp = attributes[:dtstamp].to_time | ||
| @freebusy = attributes[:freebusy].map do |fb| | ||
| Properties::Freebusy.from_ical_period(fb) | ||
| end | ||
| @ical_name = attributes[:ical_name] | ||
| @name = attributes[:name] | ||
| @uid = attributes[:uid] | ||
| end | ||
|
|
||
| def to_h | ||
| { | ||
| dtend: dtend, | ||
| dtstart: dtstart, | ||
| dtstamp: dtstamp, | ||
| freebusy: freebusy, | ||
| ical_name: ical_name, | ||
| name: name, | ||
| parent: parent, | ||
| uid: uid | ||
| } | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def attributes_from_ical_freebusy(ical_freebusy) | ||
| { | ||
| dtend: ical_freebusy.dtend, | ||
| dtstamp: ical_freebusy.dtstamp, | ||
| dtstart: ical_freebusy.dtstart, | ||
| freebusy: ical_freebusy.freebusy, | ||
| ical_name: ical_freebusy.ical_name, | ||
| name: ical_freebusy.name, | ||
| uid: ical_freebusy.uid | ||
| } | ||
| end | ||
| end | ||
| end | ||
| end |
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rubocop lint fix |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Calendav | ||
| module Properties | ||
| class Freebusy | ||
| attr_reader :start_time, :end_time | ||
|
|
||
| def self.from_ical_period(period) | ||
| new(start_time: period.first.to_time, end_time: period.last.to_time) | ||
| end | ||
|
|
||
| def initialize(start_time:, end_time:) | ||
| validate_arguments(start_time, end_time) | ||
|
|
||
| @start_time = start_time | ||
| @end_time = end_time | ||
| end | ||
|
|
||
| def to_h | ||
| { | ||
| start_time: start_time, | ||
| end_time: end_time | ||
| } | ||
| end | ||
|
|
||
| def to_range | ||
| Range.new(start_time, end_time) | ||
| end | ||
|
|
||
| def duration | ||
| end_time - start_time | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def validate_arguments(start_time, end_time) | ||
| return if start_time.instance_of?(Time) && end_time.instance_of?(Time) | ||
|
|
||
| raise ArgumentError, "arguments must be instances of Time" | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "nokogiri" | ||
|
|
||
| module Calendav | ||
| module Requests | ||
| class FreeBusyQuery | ||
| def self.call(...) | ||
| new(...).call | ||
| end | ||
|
|
||
| # @param from [Time, String YYYYMMDDTHHMMSSZ (ISO8601 w/o dashes/colons)] | ||
| # @param to [Time, String YYYYMMDDTHHMMSSZ (ISO8601 w/o dashes/colons)] | ||
| def initialize(from:, to:) | ||
| @from = from.instance_of?(Time) ? from.utc.iso8601.delete(":-") : from | ||
| @to = to.instance_of?(Time) ? to.utc.iso8601.delete(":-") : to | ||
| end | ||
|
|
||
| def call | ||
| Nokogiri::XML::Builder.new do |xml| | ||
| xml["c"].public_send(:"free-busy-query", | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe use: ?? xml["caldav"].public_send(:"free-busy-query", NAMESPACES) do |
||
| "xmlns:c" => "urn:ietf:params:xml:ns:caldav") do | ||
| xml["c"].public_send(:"time-range", start: @from, end: @to) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mistake... switch back to add_runtime_dependency