Skip to content

Conversation

@TheMinefighter
Copy link
Contributor

This pr allows for configurable request headers, when getting the original ical. I wrote this because Microsoft owa now does some User-Agent Filtering. Please note that this is my first ever ruby Pull Request.

Copy link
Owner

@darkphnx darkphnx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a few minor suggestions for your implementation. Pretty good for a first Ruby PR!

I think the one thing that's missing is some tests in spec/calendar_spec.rb to demonstrate that the headers are being passed to the URI#open method. Let me know if you'd like some help in writing that test.

attr_accessor :ical_url, :api_key, :timezone, :filter_rules, :clear_existing_alarms, :alarm_triggers, :request_headers

def initialize(ical_url, api_key, timezone = 'UTC')
def initialize(ical_url, api_key, timezone = 'UTC', request_headers={})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def initialize(ical_url, api_key, timezone = 'UTC', request_headers={})
def initialize(ical_url, api_key, timezone = 'UTC', request_headers = {})

self.ical_url = ical_url
self.api_key = api_key
self.timezone = timezone
self.request_headers=request_headers
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.request_headers=request_headers
self.request_headers = request_headers


def raw_original_ical
URI.open(ical_url).read
URI.open(ical_url, request_headers&.reduce({}, :merge) || {}).read
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too sure what you're trying to do with the reduce here.

Since request headers is already a hash you shouldn't need to reconstruct it, instead you should be able to pass it directly such as:

URI.open(ical_url, request_headers || {}).read

@TheMinefighter
Copy link
Contributor Author

Hi, I do not know exactly How I'd write a test to check that URI#open receives the request_headers correctly. My intuition would be to mock the method but that seems a bit to complicated for such a small thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants