-
-
Notifications
You must be signed in to change notification settings - Fork 60
Add quote streaming #108
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?
Add quote streaming #108
Changes from all 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 |
|---|---|---|
| @@ -1,10 +1,29 @@ | ||
| module IEX | ||
| module Cloud | ||
| module Request | ||
| STREAM_EVENT_DELIMITER = "\r\n\r\n".freeze | ||
|
|
||
| def get(path, options = {}) | ||
| request(:get, path, options) | ||
| end | ||
|
|
||
| def get_stream(path, options = {}) | ||
| buffer = '' | ||
|
Owner
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. use |
||
| event_parser = proc do |chunk| | ||
| events = (buffer + chunk).lines(STREAM_EVENT_DELIMITER) | ||
| buffer = events.last.end_with?(STREAM_EVENT_DELIMITER) ? '' : events.delete_at(-1) | ||
| events.each do |event| | ||
| yield JSON.parse(event.gsub(/\Adata: /, '')) | ||
| end | ||
| end | ||
|
|
||
| options = { | ||
| endpoint: endpoint.gsub('://cloud.', '://cloud-sse.'), | ||
|
Owner
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. remove this |
||
| request: { on_data: event_parser } | ||
| }.merge(options) | ||
| request(:get, path, options) | ||
| end | ||
|
|
||
| def post(path, options = {}) | ||
| request(:post, path, options) | ||
| end | ||
|
|
@@ -20,16 +39,17 @@ def delete(path, options = {}) | |
| private | ||
|
|
||
| def request(method, path, options) | ||
| path = [endpoint, path].join('/') | ||
| options = options.dup | ||
| path = [options.delete(:endpoint) || endpoint, path].join('/') | ||
bguban marked this conversation as resolved.
Show resolved
Hide resolved
bguban marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| response = connection.send(method) do |request| | ||
| request.options.merge!(options.delete(:request)) if options.key?(:request) | ||
bguban marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| case method | ||
| when :get, :delete | ||
| request.url(path, options) | ||
| when :post, :put | ||
| request.path = path | ||
| request.body = options.to_json unless options.empty? | ||
| end | ||
| request.options.merge!(options.delete(:request)) if options.key?(:request) | ||
| end | ||
| response.body | ||
| end | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
The
interval... so it's a complete sentence.Possible values are ... and quote each value. End with a period.