intrinio 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +41 -3
- data/lib/intrinio.rb +1 -0
- data/lib/intrinio/api.rb +28 -0
- data/lib/intrinio/command_line.rb +13 -3
- data/lib/intrinio/docopt.txt +28 -2
- data/lib/intrinio/exceptions.rb +4 -0
- data/lib/intrinio/version.rb +1 -1
- data/lib/intrinio/web_api.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d0685eb48926073584dcdce2b696f9ff9e16cff
|
4
|
+
data.tar.gz: 92d8f5b8c2dd0cddea07f789c82e09933287876f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5940954864a1e0fd987dbc6c119a8804023d5a3b0cac93f75ee3f752c2b3bb65d138bd070a1249b97801cf71c4e236c5e22c3c63c0efd65b4e7a7aa422ab116e
|
7
|
+
data.tar.gz: 74e9ee1c8d6a5f16ff78495f89c063d2b503fd04acfaa5dbd5c38245fa2602df5bc24822b7af33dd54d231e4670b08f687a0a5ef9cb714329c56bf260e419de1
|
data/README.md
CHANGED
@@ -13,6 +13,7 @@ This gem provides both a Ruby library and a command line interface for the
|
|
13
13
|
|
14
14
|
---
|
15
15
|
|
16
|
+
|
16
17
|
Install
|
17
18
|
--------------------------------------------------
|
18
19
|
|
@@ -26,16 +27,18 @@ Or with bundler:
|
|
26
27
|
gem 'intrinio'
|
27
28
|
```
|
28
29
|
|
30
|
+
|
29
31
|
Features
|
30
32
|
--------------------------------------------------
|
31
33
|
|
32
34
|
* Easy to use interface.
|
33
35
|
* Use as a library or through the command line.
|
34
|
-
* Access any Intrinio endpoint directly.
|
35
|
-
* Display output
|
36
|
-
* Save output to a file.
|
36
|
+
* Access any Intrinio endpoint and option directly.
|
37
|
+
* Display output as JSON or CSV.
|
38
|
+
* Save output to a file as JSON or CSV.
|
37
39
|
* Includes a built in file cache (disabled by default).
|
38
40
|
|
41
|
+
|
39
42
|
Usage
|
40
43
|
--------------------------------------------------
|
41
44
|
|
@@ -68,12 +71,26 @@ result = intrinio.get! "indices", type: 'economic', page_size: 5
|
|
68
71
|
# => JSON string
|
69
72
|
```
|
70
73
|
|
74
|
+
When calling any endpoint that returns a `data` attribute, you can also
|
75
|
+
call `get_csv` in order to convert the data to a CSV string.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
result = intrinio.get_csv "indices", page_size: 5
|
79
|
+
# => CSV string
|
80
|
+
```
|
81
|
+
|
71
82
|
To save the output directly to a file, use the `save` method:
|
72
83
|
|
73
84
|
```ruby
|
74
85
|
intrinio.save "filename.json", "indices", type: 'economic', page_size: 5
|
75
86
|
```
|
76
87
|
|
88
|
+
Or, to save CSV, use the `save_csv` method:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
intrinio.save_csv "filename.csv" "indices", page_size: 5
|
92
|
+
```
|
93
|
+
|
77
94
|
Debugging your request and adding "sticky" query parameters that stay with
|
78
95
|
you for the following requests is also easy:
|
79
96
|
|
@@ -86,6 +103,7 @@ puts intrinio.historical_data identifier: '$INTDSRUSM193N', item: 'level'
|
|
86
103
|
intrinio.param page_size: nil # remove param
|
87
104
|
```
|
88
105
|
|
106
|
+
|
89
107
|
Command Line
|
90
108
|
--------------------------------------------------
|
91
109
|
|
@@ -105,6 +123,26 @@ These commands are available:
|
|
105
123
|
|
106
124
|
Run `intrinio --help` for more information, or view the [full usage help][2].
|
107
125
|
|
126
|
+
Examples:
|
127
|
+
|
128
|
+
```bash
|
129
|
+
# Shows the first 5 indices
|
130
|
+
$ intrinio see indices page_size:5
|
131
|
+
|
132
|
+
# Pass arguments that require spaces
|
133
|
+
$ intrinio see indices "query:interest rate" page_size:5
|
134
|
+
|
135
|
+
# Saves a file
|
136
|
+
$ intrinio save aapl.json historical_data identifier:AAPL \
|
137
|
+
item:adj_close_price frequency:monthly page_size:10
|
138
|
+
|
139
|
+
# Shows the URL that Intrinio has constructed, good for debugging
|
140
|
+
$ intrinio url indices query:interest page_size:5
|
141
|
+
# => https://api.intrinio.com/indices?query=interest&page_size=5
|
142
|
+
|
143
|
+
```
|
144
|
+
|
145
|
+
|
108
146
|
Caching
|
109
147
|
--------------------------------------------------
|
110
148
|
|
data/lib/intrinio.rb
CHANGED
data/lib/intrinio/api.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'csv'
|
2
3
|
|
3
4
|
module Intrinio
|
4
5
|
# Provides access to all the Intrinio API endpoints
|
@@ -6,6 +7,11 @@ module Intrinio
|
|
6
7
|
attr_reader :opts
|
7
8
|
|
8
9
|
def initialize(opts={})
|
10
|
+
if opts[:auth]
|
11
|
+
opts[:username], opts[:password] = opts[:auth].split ':'
|
12
|
+
opts.delete :auth
|
13
|
+
end
|
14
|
+
|
9
15
|
defaults = {
|
10
16
|
username: nil,
|
11
17
|
password: nil,
|
@@ -35,5 +41,27 @@ module Intrinio
|
|
35
41
|
|
36
42
|
super opts[:base_url]
|
37
43
|
end
|
44
|
+
|
45
|
+
def get_csv(*args)
|
46
|
+
result = get *args
|
47
|
+
|
48
|
+
raise Intrinio::BadResponse, "Result is not a hash" unless result.is_a? Hash
|
49
|
+
raise Intrinio::IncompatibleResponse, "Result does not contain a data attribute" unless result.has_key? :data
|
50
|
+
|
51
|
+
data = result[:data]
|
52
|
+
|
53
|
+
header = data.first.keys
|
54
|
+
result = CSV.generate do |csv|
|
55
|
+
csv << header
|
56
|
+
data.each { |row| csv << row.values }
|
57
|
+
end
|
58
|
+
|
59
|
+
result
|
60
|
+
end
|
61
|
+
|
62
|
+
def save_csv(file, *args)
|
63
|
+
data = get_csv *args
|
64
|
+
File.write file, data
|
65
|
+
end
|
38
66
|
end
|
39
67
|
end
|
@@ -27,6 +27,8 @@ module Intrinio
|
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
+
attr_reader :csv
|
31
|
+
|
30
32
|
def intrinio!
|
31
33
|
Intrinio::API.new options
|
32
34
|
end
|
@@ -37,6 +39,7 @@ module Intrinio
|
|
37
39
|
path = args['PATH']
|
38
40
|
params = args['PARAMS']
|
39
41
|
file = args['FILE']
|
42
|
+
@csv = args['--csv']
|
40
43
|
|
41
44
|
return get(path, params) if args['get']
|
42
45
|
return pretty(path, params) if args['pretty']
|
@@ -46,16 +49,23 @@ module Intrinio
|
|
46
49
|
end
|
47
50
|
|
48
51
|
def get(path, params)
|
49
|
-
|
52
|
+
if csv
|
53
|
+
puts intrinio.get_csv path, translate_params(params)
|
54
|
+
else
|
55
|
+
puts intrinio.get! path, translate_params(params)
|
56
|
+
end
|
50
57
|
end
|
51
58
|
|
52
59
|
def save(file, path, params)
|
53
|
-
|
60
|
+
if csv
|
61
|
+
success = intrinio.save_csv file, path, translate_params(params)
|
62
|
+
else
|
63
|
+
success = intrinio.save file, path, translate_params(params)
|
64
|
+
end
|
54
65
|
puts success ? "Saved #{file}" : "Saving failed"
|
55
66
|
end
|
56
67
|
|
57
68
|
def pretty(path, params)
|
58
|
-
intrinio.format = :json
|
59
69
|
response = intrinio.get path, translate_params(params)
|
60
70
|
puts JSON.pretty_generate response
|
61
71
|
end
|
data/lib/intrinio/docopt.txt
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
Intrinio
|
2
2
|
|
3
3
|
Usage:
|
4
|
-
intrinio get PATH [PARAMS...]
|
4
|
+
intrinio get [--csv] PATH [PARAMS...]
|
5
5
|
intrinio pretty PATH [PARAMS...]
|
6
6
|
intrinio see PATH [PARAMS...]
|
7
7
|
intrinio url PATH [PARAMS...]
|
8
|
-
intrinio save FILE PATH [PARAMS...]
|
8
|
+
intrinio save [--csv] FILE PATH [PARAMS...]
|
9
9
|
intrinio (-h|--help|--version)
|
10
10
|
|
11
11
|
Commands:
|
@@ -36,3 +36,29 @@ Parameters:
|
|
36
36
|
|
37
37
|
FILE:
|
38
38
|
Path to the output file.
|
39
|
+
|
40
|
+
Flags:
|
41
|
+
--csv
|
42
|
+
When this flag is provided, the data will be converted to CSV before
|
43
|
+
it is displayed or saved. Note that this works only with endpoints that
|
44
|
+
have a 'data' attribute.
|
45
|
+
|
46
|
+
Examples:
|
47
|
+
intrinio see indices page_size:5
|
48
|
+
|
49
|
+
intrinio pretty indices "query:interest rate" page_size:5
|
50
|
+
|
51
|
+
intrinio see companies identifier:AAPL
|
52
|
+
|
53
|
+
intrinio see historical_data identifier:\$INTDSRUSM193N item:level \
|
54
|
+
start_date:2015-01-01
|
55
|
+
|
56
|
+
intrinio see historical_data identifier:\$SP500 item:percent_change \
|
57
|
+
frequency:monthly page_size:10
|
58
|
+
|
59
|
+
intrinio save aapl.json historical_data identifier:AAPL \
|
60
|
+
item:adj_close_price frequency:monthly page_size:10
|
61
|
+
|
62
|
+
intrinio get --csv indices page_size:5
|
63
|
+
|
64
|
+
intrinio save --csv indices.csv indices page_size:5
|
data/lib/intrinio/version.rb
CHANGED
data/lib/intrinio/web_api.rb
CHANGED
@@ -16,7 +16,7 @@ module Intrinio
|
|
16
16
|
|
17
17
|
# Allow using any method as the first segment of the path
|
18
18
|
# object.user 'details' becomes object.get 'user/details'
|
19
|
-
def method_missing(method_sym, *arguments, &
|
19
|
+
def method_missing(method_sym, *arguments, &_block)
|
20
20
|
get "/#{method_sym}", *arguments
|
21
21
|
end
|
22
22
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: intrinio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docopt
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '5.0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '5.0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: byebug
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- lib/intrinio/api.rb
|
164
164
|
- lib/intrinio/command_line.rb
|
165
165
|
- lib/intrinio/docopt.txt
|
166
|
+
- lib/intrinio/exceptions.rb
|
166
167
|
- lib/intrinio/version.rb
|
167
168
|
- lib/intrinio/web_api.rb
|
168
169
|
homepage: https://github.com/DannyBen/intrinio
|