Skip to content
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

Davidslv/add stream for mixpanel response #45

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--color
31 changes: 28 additions & 3 deletions lib/mixpanel/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,34 @@ def self.encode(params)
end

def self.get(uri)
::URI.parse(uri).read
rescue OpenURI::HTTPError => error
raise HTTPError, JSON.parse(error.io.read)['error']
uri = URI(uri)
use_ssl = uri.scheme == 'https'
tempfile = Tempfile.new('mixpanel_export')

begin
Net::HTTP.start(uri.host, uri.port, use_ssl: use_ssl) do |http|
request = Net::HTTP::Get.new uri

http.request(request) do |response|
open tempfile, 'w' do |io|
response.read_body do |chunk|
io.write chunk
end
end
end
end
rescue Net::HTTPError => error
raise HTTPError, JSON.parse(error.io.read)['error']
end

string = String.new
open(tempfile) do |file|
while chunk = file.read(512)
string << chunk
end
end

string
end
end
end
3 changes: 2 additions & 1 deletion lib/mixpanel_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
# Libraries.
require 'cgi'
require 'digest/md5'
require 'open-uri'
require 'uri'
require 'net/http'
require 'json' unless defined?(JSON)

# Mixpanel::Client libraries.
Expand Down