namara 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/namara.rb +38 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 146175ae40a21c8fe6b675cb4cfdc3a96b6f2424
4
+ data.tar.gz: 449235d89df390ba774709670a20a2d0861936c2
5
+ SHA512:
6
+ metadata.gz: 8255ca1cd52ed2c2b6a192980a8568b55d60b043b31e1372dee0b9b70facdd99d5b87585b7d089049345983c34f5cb28552750740c12b8e809f305c5c360a5e9
7
+ data.tar.gz: 16fc30ba04f6584b1075a3d672e4f3b620bf72bd2dbe73e8cd0bb69356653c89e15f01715931356cb43544b487cda464a0b5262b54e079bff0c654ea458459da
data/lib/namara.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+
4
+ class Namara
5
+ def initialize(api_key, debug=false, host='api.namara.io', api_version='v0')
6
+ @api_key = api_key
7
+ @debug = debug
8
+ @host = host
9
+ @api_version = api_version
10
+ @headers = {'Content-Type' => 'application/json', 'X-API-Key' => api_key}
11
+ end
12
+
13
+ def get(dataset, version, options={})
14
+ puts "REQUEST: #{path(dataset, version, options)}" if @debug
15
+
16
+ uri = URI.parse(path(dataset, version, options))
17
+ JSON.parse(uri.open(@headers).read)
18
+ end
19
+
20
+ def path(dataset, version, options={})
21
+ encoded_options = URI.encode_www_form(options)
22
+ if is_aggregation?(options)
23
+ "#{base_path(dataset, version)}/aggregation?api_key=#{@api_key}&#{encoded_options}"
24
+ else
25
+ "#{base_path(dataset, version)}?api_key=#{@api_key}&#{encoded_options}"
26
+ end
27
+ end
28
+
29
+ def base_path(dataset, version)
30
+ "https://#{@host}/#{@api_version}/data_sets/#{dataset}/data/#{version}"
31
+ end
32
+
33
+ private
34
+
35
+ def is_aggregation?(options)
36
+ options.include?('operation')
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: namara
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - ThinkData Works
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: The official Ruby client for Namara open data service
14
+ email: info@namara.io
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/namara.rb
20
+ homepage: https://github.com/namara-io/namara-ruby
21
+ licenses:
22
+ - Apache-2.0
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.2.5
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: namara.io API wrapper
44
+ test_files: []