enigma_io 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/.gitignore +17 -0
  2. data/.rubocop.yml +14 -0
  3. data/.travis.yml +14 -0
  4. data/Gemfile +11 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +64 -0
  7. data/Rakefile +28 -0
  8. data/enigma_io.gemspec +30 -0
  9. data/examples/data.md +94 -0
  10. data/examples/export.md +35 -0
  11. data/lib/enigma/client.rb +26 -0
  12. data/lib/enigma/download.rb +81 -0
  13. data/lib/enigma/endpoint.rb +108 -0
  14. data/lib/enigma/endpoints/data.rb +5 -0
  15. data/lib/enigma/endpoints/export.rb +22 -0
  16. data/lib/enigma/endpoints/meta.rb +5 -0
  17. data/lib/enigma/endpoints/stats.rb +5 -0
  18. data/lib/enigma/response.rb +17 -0
  19. data/lib/enigma/version.rb +6 -0
  20. data/lib/enigma.rb +49 -0
  21. data/test/client_test.rb +32 -0
  22. data/test/data_test.rb +81 -0
  23. data/test/endpoint_test.rb +55 -0
  24. data/test/export_test.rb +67 -0
  25. data/test/fixtures/download.csv +4 -0
  26. data/test/fixtures/download.zip +0 -0
  27. data/test/fixtures/vcr_cassettes/compound_average.yml +121 -0
  28. data/test/fixtures/vcr_cassettes/data_with_error.yml +38 -0
  29. data/test/fixtures/vcr_cassettes/export.yml +37 -0
  30. data/test/fixtures/vcr_cassettes/filtered_data.yml +6727 -0
  31. data/test/fixtures/vcr_cassettes/limit_data.yml +54 -0
  32. data/test/fixtures/vcr_cassettes/page_data.yml +53 -0
  33. data/test/fixtures/vcr_cassettes/selected_data.yml +541 -0
  34. data/test/fixtures/vcr_cassettes/simple_data.yml +6762 -0
  35. data/test/fixtures/vcr_cassettes/simple_metadata.yml +75 -0
  36. data/test/fixtures/vcr_cassettes/simple_stats.yml +48 -0
  37. data/test/fixtures/vcr_cassettes/sorted_data.yml +6690 -0
  38. data/test/fixtures/vcr_cassettes/sorted_data_descending.yml +6690 -0
  39. data/test/meta_test.rb +26 -0
  40. data/test/response_test.rb +13 -0
  41. data/test/stats_test.rb +27 -0
  42. data/test/test_helper.rb +37 -0
  43. metadata +223 -0
data/test/meta_test.rb ADDED
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test_helper'
4
+
5
+ class MetaTest < Test::Unit::TestCase
6
+ def setup
7
+ @client = Enigma::Client.new(key: TEST_KEY)
8
+ end
9
+
10
+ def test_simple_metadata
11
+ VCR.use_cassette('simple_metadata') do
12
+ response = @client.meta('us.gov.whitehouse.salaries')
13
+ assert_equal 'us.gov.whitehouse.salaries', response.datapath
14
+ end
15
+ end
16
+
17
+ def test_adds_limit_filter
18
+ stub_request(:get, /.*meta.*limit=100.*/).to_return(body: '{}')
19
+ @client.meta('us.gov.whitehouse.salaries', limit: 100)
20
+ end
21
+
22
+ def test_adds_two_filters
23
+ stub_request(:get, /.*meta.*limit=100.*page=1.*/).to_return(body: '{}')
24
+ @client.meta('us.gov.whitehouse.salaries', limit: 100, page: 1)
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test_helper'
4
+
5
+ class EnigmaTest < Test::Unit::TestCase
6
+ def test_response
7
+ res = OpenStruct.new
8
+ res.body = "{\"datapath\": \"us.gov.whitehouse.salaries\"}"
9
+ r = Enigma::Response.parse res
10
+ assert_equal res, r.raw
11
+ assert_equal 'us.gov.whitehouse.salaries', r.datapath
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test_helper'
4
+
5
+ class StatsTest < Test::Unit::TestCase
6
+ def setup
7
+ @client = Enigma::Client.new(key: TEST_KEY)
8
+ end
9
+
10
+ def test_simple_data_request
11
+ VCR.use_cassette('simple_stats') do
12
+ response = @client.stats('us.gov.whitehouse.visitor-list',
13
+ select: 'type_of_access')
14
+ assert_equal 'type_of_access', response.info.column.id
15
+ end
16
+ end
17
+
18
+ def test_compound_average
19
+ VCR.use_cassette('compound_average') do
20
+ response = @client.stats('us.gov.whitehouse.visitor-list',
21
+ select: 'release_date',
22
+ by: :avg,
23
+ of: :total_people)
24
+ assert_equal(734, response.result.compound_avg.first.avg.to_i)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ $VERBOSE = nil
3
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
+
5
+ require 'simplecov'
6
+ require 'rubygems'
7
+
8
+ SimpleCov.start do
9
+ add_filter '/test/'
10
+ end
11
+
12
+ require 'test/unit'
13
+ require 'mocha/setup'
14
+ require 'webmock/test_unit'
15
+ require 'vcr'
16
+ require 'enigma'
17
+
18
+ Enigma.logger.level = Logger::WARN
19
+
20
+ VCR.configure do |c|
21
+ c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
22
+ c.hook_into :webmock
23
+ end
24
+
25
+ # If you want to add tests that involve actual requests to the API:
26
+ #
27
+ # 1. Switch this to your api key
28
+ #
29
+ # 2. Write the tests wrapped in VCR blocks (see test/data_test.rb)
30
+ # for some examples
31
+ #
32
+ # 3. Go into the generated cassette yml files and replace your key
33
+ # with test-key
34
+ #
35
+ # 4. Switch thid back
36
+ #
37
+ TEST_KEY = 'test-key'
metadata ADDED
@@ -0,0 +1,223 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enigma_io
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Stephen Pike
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-01-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rubocop
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: yard
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: typhoeus
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: hashie
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rubyzip
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 1.0.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: 1.0.0
126
+ description: Ruby client for the Enigma API
127
+ email:
128
+ - steve@scpike.net
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - .rubocop.yml
135
+ - .travis.yml
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - enigma_io.gemspec
141
+ - examples/data.md
142
+ - examples/export.md
143
+ - lib/enigma.rb
144
+ - lib/enigma/client.rb
145
+ - lib/enigma/download.rb
146
+ - lib/enigma/endpoint.rb
147
+ - lib/enigma/endpoints/data.rb
148
+ - lib/enigma/endpoints/export.rb
149
+ - lib/enigma/endpoints/meta.rb
150
+ - lib/enigma/endpoints/stats.rb
151
+ - lib/enigma/response.rb
152
+ - lib/enigma/version.rb
153
+ - test/client_test.rb
154
+ - test/data_test.rb
155
+ - test/endpoint_test.rb
156
+ - test/export_test.rb
157
+ - test/fixtures/download.csv
158
+ - test/fixtures/download.zip
159
+ - test/fixtures/vcr_cassettes/compound_average.yml
160
+ - test/fixtures/vcr_cassettes/data_with_error.yml
161
+ - test/fixtures/vcr_cassettes/export.yml
162
+ - test/fixtures/vcr_cassettes/filtered_data.yml
163
+ - test/fixtures/vcr_cassettes/limit_data.yml
164
+ - test/fixtures/vcr_cassettes/page_data.yml
165
+ - test/fixtures/vcr_cassettes/selected_data.yml
166
+ - test/fixtures/vcr_cassettes/simple_data.yml
167
+ - test/fixtures/vcr_cassettes/simple_metadata.yml
168
+ - test/fixtures/vcr_cassettes/simple_stats.yml
169
+ - test/fixtures/vcr_cassettes/sorted_data.yml
170
+ - test/fixtures/vcr_cassettes/sorted_data_descending.yml
171
+ - test/meta_test.rb
172
+ - test/response_test.rb
173
+ - test/stats_test.rb
174
+ - test/test_helper.rb
175
+ homepage: https://github.com/scpike/enigma
176
+ licenses:
177
+ - MIT
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ none: false
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: 1.9.3
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ none: false
190
+ requirements:
191
+ - - ! '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubyforge_project:
196
+ rubygems_version: 1.8.23
197
+ signing_key:
198
+ specification_version: 3
199
+ summary: Ruby client for the Enigma API
200
+ test_files:
201
+ - test/export_test.rb
202
+ - test/endpoint_test.rb
203
+ - test/stats_test.rb
204
+ - test/response_test.rb
205
+ - test/test_helper.rb
206
+ - test/meta_test.rb
207
+ - test/data_test.rb
208
+ - test/client_test.rb
209
+ - test/fixtures/download.zip
210
+ - test/fixtures/download.csv
211
+ - test/fixtures/vcr_cassettes/selected_data.yml
212
+ - test/fixtures/vcr_cassettes/page_data.yml
213
+ - test/fixtures/vcr_cassettes/simple_stats.yml
214
+ - test/fixtures/vcr_cassettes/sorted_data.yml
215
+ - test/fixtures/vcr_cassettes/filtered_data.yml
216
+ - test/fixtures/vcr_cassettes/sorted_data_descending.yml
217
+ - test/fixtures/vcr_cassettes/compound_average.yml
218
+ - test/fixtures/vcr_cassettes/data_with_error.yml
219
+ - test/fixtures/vcr_cassettes/simple_data.yml
220
+ - test/fixtures/vcr_cassettes/limit_data.yml
221
+ - test/fixtures/vcr_cassettes/export.yml
222
+ - test/fixtures/vcr_cassettes/simple_metadata.yml
223
+ has_rdoc: