-
-
Notifications
You must be signed in to change notification settings - Fork 22
allow specifying request headers #54
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: master
Are you sure you want to change the base?
allow specifying request headers #54
Conversation
darkphnx
left a comment
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.
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.
lib/ical_filter_proxy/calendar.rb
Outdated
| 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={}) |
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.
| def initialize(ical_url, api_key, timezone = 'UTC', request_headers={}) | |
| def initialize(ical_url, api_key, timezone = 'UTC', request_headers = {}) |
lib/ical_filter_proxy/calendar.rb
Outdated
| self.ical_url = ical_url | ||
| self.api_key = api_key | ||
| self.timezone = timezone | ||
| self.request_headers=request_headers |
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.
| self.request_headers=request_headers | |
| self.request_headers = request_headers |
lib/ical_filter_proxy/calendar.rb
Outdated
|
|
||
| def raw_original_ical | ||
| URI.open(ical_url).read | ||
| URI.open(ical_url, request_headers&.reduce({}, :merge) || {}).read |
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.
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|
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. |
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.