quata 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 580ff598467d94e05a1ab31b7c6a07907fcb618a
4
- data.tar.gz: 2acff7751ca88d39a4f57ea0b7aa1b31c09234be
3
+ metadata.gz: bea40dfd8ef5efedbf07a77c86c87c6bfed9ecea
4
+ data.tar.gz: f4cf1fada28faca37b9182d764600a46d38215ab
5
5
  SHA512:
6
- metadata.gz: 8edcf7a6387ccb52603351c03685f68b5c2d4c35d806a1a7693cd019f2b8af2df7285832642a16a8decae6c2e726a875db0a3cd877d286fb63827c3d4b28ff54
7
- data.tar.gz: 45aa82466c670de3b0935c510f00c4ba6ef4113a94fb14608fbc7a0e7ee30a4fe56b2c42ae752a21e9f959c69f56ab7dc58e8bb1e3ec9e839af3bb364b370184
6
+ metadata.gz: 2a75b9169a54d446a29262a56cc77e9c32033c1013db752bca777dd0a93666d4c6d818e58d9647bfe7c07ddf3a35f387e62dfbff8c8356ebfa57715db27c03ec
7
+ data.tar.gz: 376ba5b8b932047a37fbd35e7d57aa37768a04e926162c0d58977e3ca3dbad3408224b5d38ef16c4252ec18a9777591b81c3245417e389f829ca7d159e5d2c50
data/README.md CHANGED
@@ -1,98 +1,128 @@
1
- Quata - Quandl API Library and Command Line
2
- ==================================================
3
-
4
- ---
5
-
6
- Quata is a lightweight ruby library for accessing Quandl with a command
7
- line interface.
8
-
9
- ---
10
-
11
- Features
12
- --------------------------------------------------
13
-
14
- * Access any Quandl endpoint directly.
15
- * Display output in various formats.
16
- * Save output to a file, including bulk downloads.
17
-
18
- Example
19
- --------------------------------------------------
20
-
21
- First, require and initialize Quata with your API key
22
-
23
- ```ruby
24
- require 'quata'
25
- quandl = Quandl.new 'Your API Key'
26
- ```
27
-
28
- Now, you can access any Quandl endpoint with any optional parameter, like
29
- this:
30
-
31
- ```ruby
32
- result = quandl.get "datasets/WIKI/AAPL", rows: 3 # => Hash
33
- ```
34
-
35
- In addition, for convenience, you can use the first part of the endpoint as
36
- a method name, like this:
37
-
38
- ```ruby
39
- result = quandl.datasets "WIKI/AAPL", rows: 3
40
- ```
41
-
42
- By default, you will get a ruby hash in return. If you wish to get the raw
43
- output, you can use the `get!` method:
44
-
45
- ```ruby
46
- result = quandl.get! "datasets/WIKI/AAPL", rows: 3 # => JSON string
47
- result = quandl.get! "datasets/WIKI/AAPL.json", rows: 3 # => JSON string
48
- result = quandl.get! "datasets/WIKI/AAPL.csv", rows: 3 # => CSV string
49
- ```
50
-
51
- To save the output directly to a file, use the `save` method:
52
-
53
- ```ruby
54
- result = quandl.save "aapl.csv", "datasets/WIKI/AAPL.csv", rows: 3
55
- ```
56
-
57
- Command Line
58
- --------------------------------------------------
59
-
60
- The command line utility `quata` acts similarly. It provides these commands:
61
-
62
- `$ quata get PATH [PARAMS...]` - print the output.
63
- `$ quata pretty PATH [PARAMS...]` - print a pretty JSON.
64
- `$ quata see PATH [PARAMS...]` - print a colored output.
65
- `$ quata url PATH [PARAMS...]` - show the constructed URL.
66
- `$ quata save FILE PATH [PARAMS...]` - save the output to a file.
67
-
68
- Run `quata --help` for more information.
69
-
70
- Examples:
71
- ```bash
72
- # Shows the first two databases
73
- quata see databases per_page:2
74
-
75
- # Or more compactly, as CSV
76
- quata get databases per_page:2
77
-
78
- # Prints CSV to screen (CSV is the default in the command line)
79
- $ quata get datasets/WIKI/AAPL
80
-
81
- # Prints JSON instead
82
- $ quata get datasets/WIKI/AAPL.json
83
-
84
- # Pass arguments using the same syntax - key:value
85
- $ quata get datasets/WIKI/AAPL rows:5
86
-
87
- # Pass arguments that require spaces
88
- $ quata get datasets.json "query:qqq index"
89
-
90
- # Prints a colored output
91
- $ quata see datasets/WIKI/AAPL rows:5
92
-
93
- # Saves a file
94
- $ quata save output.csv datasets/WIKI/AAPL rows:5
95
-
96
- # Shows the URL that Quata has constructed, good for debugging
97
- $ quata url datasets/WIKI/AAPL rows:5
98
- ```
1
+ Quata - Quandl API Library and Command Line
2
+ ==================================================
3
+
4
+ [![Gem](https://img.shields.io/gem/v/quata.svg?style=flat-square)](https://rubygems.org/gems/quata)
5
+ [![Travis](https://img.shields.io/travis/DannyBen/quata.svg?style=flat-square)](https://travis-ci.org/DannyBen/quata)
6
+ [![Code Climate](https://img.shields.io/codeclimate/github/DannyBen/quata.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/quata)
7
+ [![Gemnasium](https://img.shields.io/gemnasium/DannyBen/quata.svg?style=flat-square)](https://gemnasium.com/DannyBen/quata)
8
+
9
+ ---
10
+
11
+ Quata is a lightweight ruby library for accessing Quandl, and includes
12
+ a command line interface.
13
+
14
+ It provides direct access to all of the [Quandl API][1] endpoints.
15
+
16
+ ---
17
+
18
+ Features
19
+ --------------------------------------------------
20
+
21
+ * Easy to use interface.
22
+ * Use as a library or through the command line.
23
+ * Access any Quandl endpoint directly.
24
+ * Display output in various formats.
25
+ * Save output to a file, including bulk downloads.
26
+
27
+ Example
28
+ --------------------------------------------------
29
+
30
+ First, require and initialize with your API key
31
+
32
+ ```ruby
33
+ require 'quata'
34
+ quandl = Quandl.new 'Your API Key'
35
+ ```
36
+
37
+ Now, you can access any Quandl endpoint with any optional parameter, like
38
+ this:
39
+
40
+ ```ruby
41
+ result = quandl.get "datasets/WIKI/AAPL", rows: 3 # => Hash
42
+ ```
43
+
44
+ In addition, for convenience, you can use the first part of the endpoint as
45
+ a method name, like this:
46
+
47
+ ```ruby
48
+ result = quandl.datasets "WIKI/AAPL", rows: 3
49
+ ```
50
+
51
+ By default, you will get a ruby hash in return. If you wish to get the raw
52
+ output, you can use the `get!` method:
53
+
54
+ ```ruby
55
+ result = quandl.get! "datasets/WIKI/AAPL", rows: 3 # => JSON string
56
+ result = quandl.get! "datasets/WIKI/AAPL.json", rows: 3 # => JSON string
57
+ result = quandl.get! "datasets/WIKI/AAPL.csv", rows: 3 # => CSV string
58
+ ```
59
+
60
+ To save the output directly to a file, use the `save` method:
61
+
62
+ ```ruby
63
+ result = quandl.save "aapl.csv", "datasets/WIKI/AAPL.csv", rows: 3
64
+ ```
65
+
66
+ Debugging your request and adding "sticky" query parameters that stay with
67
+ you for the following requests is also easy:
68
+
69
+ ```ruby
70
+ quandl.debug true
71
+ quandl.param :rows, 10
72
+ quandl.param :order, 'asc'
73
+ puts quandl.get 'WIKI/AAPL'
74
+ => https://www.quandl.com/api/v3/WIKI/AAPL.json?auth_token=key&rows=10&order=asc
75
+ ```
76
+
77
+ Command Line
78
+ --------------------------------------------------
79
+
80
+ The command line utility `quata` acts in a similar way. To use your Quandl
81
+ API key, simply set it in the environment variables `QUANDL_KEY`:
82
+
83
+ `$ export QUANDL_KEY=your_key`
84
+
85
+ These commands are available:
86
+
87
+ `$ quata get PATH [PARAMS...]` - print the output.
88
+ `$ quata pretty PATH [PARAMS...]` - print a pretty JSON.
89
+ `$ quata see PATH [PARAMS...]` - print a colored output.
90
+ `$ quata url PATH [PARAMS...]` - show the constructed URL.
91
+ `$ quata save FILE PATH [PARAMS...]` - save the output to a file.
92
+
93
+ Run `quata --help` for more information, or view the [full usage help][2].
94
+
95
+ Examples:
96
+
97
+ ```bash
98
+ # Shows the first two databases
99
+ $ quata see databases per_page:2
100
+
101
+ # Or more compactly, as CSV
102
+ $ quata get databases per_page:2
103
+
104
+ # Prints CSV to screen (CSV is the default in the command line)
105
+ $ quata get datasets/WIKI/AAPL
106
+
107
+ # Prints JSON instead
108
+ $ quata get datasets/WIKI/AAPL.json
109
+
110
+ # Pass arguments using the same syntax - key:value
111
+ $ quata get datasets/WIKI/AAPL rows:5
112
+
113
+ # Pass arguments that require spaces
114
+ $ quata get datasets.json "query:qqq index"
115
+
116
+ # Prints a colored output
117
+ $ quata see datasets/WIKI/AAPL rows:5
118
+
119
+ # Saves a file
120
+ $ quata save output.csv datasets/WIKI/AAPL rows:5
121
+
122
+ # Shows the URL that Quata has constructed, good for debugging
123
+ $ quata url datasets/WIKI/AAPL rows:5
124
+ # => https://www.quandl.com/api/v3/datasets/WIKI/AAPL.csv?auth_token=YOUR_KEY&rows=5
125
+ ```
126
+
127
+ [1]: https://www.quandl.com/blog/getting-started-with-the-quandl-api
128
+ [2]: https://github.com/DannyBen/quata/blob/master/lib/quata/docopt.txt
@@ -5,6 +5,7 @@ require 'awesome_print'
5
5
 
6
6
  module Quata
7
7
 
8
+ # Handles the command line interface
8
9
  class CommandLine
9
10
  include Singleton
10
11
 
@@ -15,6 +16,8 @@ module Quata
15
16
  @quandl.format :csv
16
17
  end
17
18
 
19
+ # Gets an array of arguments (e.g. ARGV), executes the command if valid
20
+ # and shows usage patterns / help otherwise.
18
21
  def execute(argv=[])
19
22
  doc = File.read File.dirname(__FILE__) + '/docopt.txt'
20
23
  begin
@@ -27,6 +30,8 @@ module Quata
27
30
 
28
31
  private
29
32
 
33
+ # Called when the arguments match one of the usage patterns. Will
34
+ # delegate action to other, more specialized methods.
30
35
  def handle(args)
31
36
  path = args['PATH']
32
37
  params = args['PARAMS']
@@ -65,6 +70,8 @@ module Quata
65
70
  quandl.debug false
66
71
  end
67
72
 
73
+ # Convert a params array like [key:value, key:value] to a hash like
74
+ # {key: value, key: value}
68
75
  def translate_params(params)
69
76
  return nil if params.empty?
70
77
  result = {}
@@ -0,0 +1,52 @@
1
+ Quata
2
+
3
+ Usage:
4
+ quata get PATH [PARAMS...]
5
+ quata pretty PATH [PARAMS...]
6
+ quata see PATH [PARAMS...]
7
+ quata url PATH [PARAMS...]
8
+ quata save FILE PATH [PARAMS...]
9
+ quata (-h|--help|--version)
10
+
11
+ Commands:
12
+ get
13
+ Downloads data and prints it to screen as it.
14
+
15
+ pretty
16
+ Downloads data and prints it as a prettified JSON output.
17
+
18
+ see
19
+ Downloads data and prints it with a colored output.
20
+
21
+ url
22
+ Shows the URL constructed from the request.
23
+
24
+ save
25
+ Downloads data and saves it to a file.
26
+
27
+ Parameters:
28
+ PATH:
29
+ This is the Quandl API path, for example: datasets/WIKI/AAPL.
30
+ Format is defaulted to CSV in most cases, but you can override it like
31
+ you normally would by appending it at the end, like
32
+ datasets/WIKI/AAPL.json
33
+
34
+ PARAMS:
35
+ An optional list of query string parameters, separated by a space, to
36
+ send with the request. Each parameter should be in the format of
37
+ key:value, for example: page:2 per_page:10
38
+
39
+ FILE:
40
+ Path to the output file.
41
+
42
+ Examples:
43
+ quata get databases per_page:2
44
+ quata get datasets/WIKI/AAPL
45
+ quata get datasets/WIKI/AAPL rows:5
46
+ quata get datasets source_code:WIKI query:*
47
+ quata get datasets query:oil
48
+ quata get datasets.json "query:qqq index"
49
+ quata see datasets/WIKI/AAPL rows:5
50
+ quata url datasets/WIKI/AAPL rows:5
51
+ quata save output.csv datasets/WIKI/AAPL rows:5
52
+ quata pretty datasets.json query:qqq
data/lib/quata/quandl.rb CHANGED
@@ -1,6 +1,6 @@
1
- # Quandl
2
1
  require 'json'
3
2
 
3
+ # Provides access to all the Quandl API endpoints
4
4
  class Quandl < Quata::WebAPI
5
5
  attr_reader :api_key
6
6
 
@@ -15,7 +15,7 @@ class Quandl < Quata::WebAPI
15
15
  after_request do |response|
16
16
  begin
17
17
  JSON.parse response, symbolize_names: true
18
- rescue JSON::ParserError => e
18
+ rescue JSON::ParserError
19
19
  response
20
20
  end
21
21
  end
data/lib/quata/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Quata
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/quata/web_api.rb CHANGED
@@ -3,6 +3,8 @@ require 'open-uri'
3
3
 
4
4
  module Quata
5
5
 
6
+ # A general purpose HTTP wrapper. This is poor man's HTTParty with
7
+ # dynamic methods.
6
8
  class WebAPI
7
9
  attr_reader :base_url, :after_request_block, :debug_mode
8
10
 
@@ -46,7 +48,7 @@ module Quata
46
48
  @after_request_block = block
47
49
  end
48
50
 
49
- # Return the response from teh API.
51
+ # Return the response from the API.
50
52
  def get(path, extra=nil, params={})
51
53
  response = get! path, extra, params
52
54
  response = after_request_block.call(response) if after_request_block
@@ -94,7 +96,11 @@ module Quata
94
96
  private
95
97
 
96
98
  def http_get(url)
97
- open(url).read
99
+ begin
100
+ open(url).read
101
+ rescue OpenURI::HTTPError => e
102
+ e.message
103
+ end
98
104
  end
99
105
  end
100
106
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0.11'
139
+ - !ruby/object:Gem::Dependency
140
+ name: yard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.8'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.8'
139
153
  description: Easy to use API for Quandl data service with a command line interface
140
154
  email: db@dannyben.com
141
155
  executables:
@@ -147,6 +161,7 @@ files:
147
161
  - bin/quata
148
162
  - lib/quata.rb
149
163
  - lib/quata/command_line.rb
164
+ - lib/quata/docopt.txt
150
165
  - lib/quata/quandl.rb
151
166
  - lib/quata/version.rb
152
167
  - lib/quata/web_api.rb
@@ -175,3 +190,4 @@ signing_key:
175
190
  specification_version: 4
176
191
  summary: Quandl API Library and Command Line
177
192
  test_files: []
193
+ has_rdoc: