enigma_io 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73060a713b2c7c3f6b0ab2fba935b94ae0833113
4
- data.tar.gz: ff631614d254b6443b820f0b5f02306806175b37
3
+ metadata.gz: a747d35d0d4bc97a8590df2eeaba2a21fb5f7566
4
+ data.tar.gz: 0203d3a76ec2c280ca3d7e08f7a045b065748da1
5
5
  SHA512:
6
- metadata.gz: 0a0259dd0b09f59ab179451dbc249e76473596d9a2f0f7f77818ede09edc57ded6ef5f74d7c6d771f0bafeb2043eef3b7a8dd342f99e32a406a41a11273e8ec3
7
- data.tar.gz: 7b21195ff07b82260251cea50f7abdbfa95d33e60e498b87e06aa73cfcb5429c5f54bcb1ba288acda79d7d89bb98a0f2bd1726131f953441a04c530acd2e9430
6
+ metadata.gz: 4494f3b6c8fc8dc4d720e1aec016e3cb3f2ffa31eba3d04729bfca1621a9234d9b4a8509537853eba283760aea102a0343347b11d61e084bbce25ae38131d018
7
+ data.tar.gz: 5346fdefe3243b9a3068b7688d65cac28aad1334ebe9aec7653d2db95fc6f91f79ceb22e4c98744419d2bbe89cc32395e4923c38a9693e3cd9fa2d7182167231
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Ruby client for the enigma api located at https://app.enigma.io/api. Supports ruby >= 1.9.3
4
4
 
5
- Note that you need api key to use their api.
5
+ Note that you need an api key to use their api.
6
6
 
7
7
  [![Build Status](https://travis-ci.org/scpike/enigma.png?branch=master)](https://travis-ci.org/scpike/enigma)
8
8
 
@@ -49,15 +49,30 @@ module Enigma
49
49
  tmp
50
50
  end
51
51
 
52
+ def unzip_zip
53
+ tmp = write_tmp
54
+ Zip::File.open(tmp.path) do |zipfile|
55
+ zipfile.first.get_input_stream.read
56
+ end
57
+ end
58
+
59
+ def unzip_gz
60
+ tmp = write_tmp
61
+ Zlib::GzipReader.open(tmp.path) do |zipfile|
62
+ zipfile.read
63
+ end
64
+ end
65
+
66
+ # Handle either .zip or .gz responses since they've changed the
67
+ # format.
52
68
  def unzip
53
69
  @download_contents ||=
54
70
  begin
55
- tmp = write_tmp
56
- contents = nil
57
- Zip::File.open(tmp.path) do |zipfile|
58
- contents = zipfile.first.get_input_stream.read
71
+ if download_url =~ /\.gz/
72
+ unzip_gz
73
+ else
74
+ unzip_zip
59
75
  end
60
- contents
61
76
  end
62
77
  end
63
78
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Enigma version
4
4
  module Enigma
5
- VERSION = '0.0.3'
5
+ VERSION = '0.0.4'
6
6
  end
data/test/export_test.rb CHANGED
@@ -7,12 +7,13 @@ class ExportTest < Test::Unit::TestCase
7
7
  Enigma::Download.any_instance.stubs(:sleep)
8
8
 
9
9
  # These are identical, just one is zipped
10
- @zipped = File.read 'test/fixtures/download.zip'
10
+ @old_zipped = File.read 'test/fixtures/download.zip'
11
+ @zipped = File.read 'test/fixtures/download.csv.gz'
11
12
  @unzipped = File.read 'test/fixtures/download.csv'
12
13
 
13
14
  # www.example.com is the URL in the response to the export
14
15
  # cassette
15
- stub_request(:get, 'www.example.com').to_return do
16
+ stub_request(:get, 'www.example.com/us.gov.whitehouse.visitor-list.csv.gz').to_return do
16
17
  if @tried
17
18
  { body: @zipped }
18
19
  else
@@ -20,6 +21,17 @@ class ExportTest < Test::Unit::TestCase
20
21
  { status: 404 }
21
22
  end
22
23
  end
24
+
25
+ # www.example.com is the URL in the response to the export
26
+ # cassette
27
+ stub_request(:get, 'www.example.com/us.gov.whitehouse.visitor-list.zip').to_return do
28
+ if @tried
29
+ { body: @old_zipped }
30
+ else
31
+ @tried = true
32
+ { status: 404 }
33
+ end
34
+ end
23
35
  end
24
36
 
25
37
  def test_export_no_dl
@@ -64,4 +76,16 @@ class ExportTest < Test::Unit::TestCase
64
76
  assert_equal 'Steve', parsed.first[:name]
65
77
  end
66
78
  end
79
+
80
+ def test_writing_csv_from_old_format
81
+ VCR.use_cassette('export_old') do
82
+ # www.example.com is the URL in the response to the export
83
+ # cassette
84
+ dl = @client.export('us.gov.whitehouse.visitor-list')
85
+ dl.get
86
+ testIO = StringIO.new
87
+ dl.write_csv(testIO)
88
+ assert_equal @unzipped, testIO.string
89
+ end
90
+ end
67
91
  end
Binary file
@@ -31,7 +31,7 @@ http_interactions:
31
31
  body:
32
32
  encoding: US-ASCII
33
33
  string: ! "{\n \"datapath\": \"us.gov.whitehouse.visitor-list\",\n \"success\":
34
- true,\n \"export_url\": \"www.example.com\"\n}"
34
+ true,\n \"export_url\": \"www.example.com/us.gov.whitehouse.visitor-list.csv.gz\"\n}"
35
35
  http_version:
36
36
  recorded_at: Sun, 26 Jan 2014 22:11:57 GMT
37
37
  recorded_with: VCR 2.8.0
@@ -0,0 +1,37 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.enigma.io/v2/export/test-key/us.gov.whitehouse.visitor-list
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Typhoeus - https://github.com/typhoeus/typhoeus
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Server:
18
+ - nginx/1.2.9
19
+ Date:
20
+ - Sun, 26 Jan 2014 22:10:52 GMT
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ Content-Length:
24
+ - '302'
25
+ Connection:
26
+ - keep-alive
27
+ Vary:
28
+ - Accept-Encoding
29
+ Access-Control-Allow-Origin:
30
+ - ! '*'
31
+ body:
32
+ encoding: US-ASCII
33
+ string: ! "{\n \"datapath\": \"us.gov.whitehouse.visitor-list\",\n \"success\":
34
+ true,\n \"export_url\": \"www.example.com/us.gov.whitehouse.visitor-list.zip\"\n}"
35
+ http_version:
36
+ recorded_at: Sun, 26 Jan 2014 22:11:57 GMT
37
+ recorded_with: VCR 2.8.0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enigma_io
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Pike
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-25 00:00:00.000000000 Z
11
+ date: 2014-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -140,10 +140,12 @@ files:
140
140
  - test/endpoint_test.rb
141
141
  - test/export_test.rb
142
142
  - test/fixtures/download.csv
143
+ - test/fixtures/download.csv.gz
143
144
  - test/fixtures/download.zip
144
145
  - test/fixtures/vcr_cassettes/compound_average.yml
145
146
  - test/fixtures/vcr_cassettes/data_with_error.yml
146
147
  - test/fixtures/vcr_cassettes/export.yml
148
+ - test/fixtures/vcr_cassettes/export_old.yml
147
149
  - test/fixtures/vcr_cassettes/filtered_data.yml
148
150
  - test/fixtures/vcr_cassettes/limit_data.yml
149
151
  - test/fixtures/vcr_cassettes/page_data.yml
@@ -187,10 +189,12 @@ test_files:
187
189
  - test/endpoint_test.rb
188
190
  - test/export_test.rb
189
191
  - test/fixtures/download.csv
192
+ - test/fixtures/download.csv.gz
190
193
  - test/fixtures/download.zip
191
194
  - test/fixtures/vcr_cassettes/compound_average.yml
192
195
  - test/fixtures/vcr_cassettes/data_with_error.yml
193
196
  - test/fixtures/vcr_cassettes/export.yml
197
+ - test/fixtures/vcr_cassettes/export_old.yml
194
198
  - test/fixtures/vcr_cassettes/filtered_data.yml
195
199
  - test/fixtures/vcr_cassettes/limit_data.yml
196
200
  - test/fixtures/vcr_cassettes/page_data.yml