intrinio 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 +4 -4
- data/README.md +11 -3
- data/lib/intrinio/command_line.rb +130 -126
- data/lib/intrinio/docopt.txt +77 -64
- data/lib/intrinio/exceptions.rb +4 -3
- data/lib/intrinio/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1445cecea92901fa631ab950788949e4ffb8472e
|
4
|
+
data.tar.gz: a984c027e44ba371c037e9bf9f595c5b8b260787
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f45beb9d024f240d330a8b39b3e18dc33378d97865ff75980bfbf149ea43c2942dd185fbd89a7ee61a298b1f5e51aa9d14943021b9ca4b05b192aa98bd23e7a2
|
7
|
+
data.tar.gz: 3e5af5e586f14760f6c10b2ab79105af113cef36fcc1209bcb9771dbb4ab88e7fb9439debb1c16d20d51b2af9aa29061adc4adaf68330a3bc1113c74a6cb4d47
|
data/README.md
CHANGED
@@ -47,6 +47,7 @@ First, require and initialize with your username and password.
|
|
47
47
|
```ruby
|
48
48
|
require 'intrinio'
|
49
49
|
intrinio = Intrinio::API.new username: 'me', password: 'secret'
|
50
|
+
# or: Intrinio::API.new auth: 'me:secret'
|
50
51
|
```
|
51
52
|
|
52
53
|
Now, you can access any Intrinio endpoint with any optional parameter, like
|
@@ -63,6 +64,13 @@ a method name, like this:
|
|
63
64
|
result = intrinio.indices type: 'economic', page_size: 5
|
64
65
|
```
|
65
66
|
|
67
|
+
In other words, these calls are the same:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
intrinio.get 'endpoint', param: value
|
71
|
+
intrinio.endpoint, param: value
|
72
|
+
```
|
73
|
+
|
66
74
|
By default, you will get a ruby hash in return. If you wish to get the raw
|
67
75
|
output, you can use the `get!` method:
|
68
76
|
|
@@ -115,11 +123,11 @@ Intrinio authentication, simply set it in the environment variables
|
|
115
123
|
|
116
124
|
These commands are available:
|
117
125
|
|
118
|
-
`$ intrinio get PATH [PARAMS...]` - print the output.
|
126
|
+
`$ intrinio get [--csv] PATH [PARAMS...]` - print the output.
|
119
127
|
`$ intrinio pretty PATH [PARAMS...]` - print a pretty JSON.
|
120
128
|
`$ intrinio see PATH [PARAMS...]` - print a colored output.
|
121
129
|
`$ intrinio url PATH [PARAMS...]` - show the constructed URL.
|
122
|
-
`$ intrinio save FILE PATH [PARAMS...]` - save the output to a file.
|
130
|
+
`$ intrinio save [--csv] FILE PATH [PARAMS...]` - save the output to a file.
|
123
131
|
|
124
132
|
Run `intrinio --help` for more information, or view the [full usage help][2].
|
125
133
|
|
@@ -133,7 +141,7 @@ $ intrinio see indices page_size:5
|
|
133
141
|
$ intrinio see indices "query:interest rate" page_size:5
|
134
142
|
|
135
143
|
# Saves a file
|
136
|
-
$ intrinio save aapl.
|
144
|
+
$ intrinio save --csv aapl.csv historical_data identifier:AAPL \
|
137
145
|
item:adj_close_price frequency:monthly page_size:10
|
138
146
|
|
139
147
|
# Shows the URL that Intrinio has constructed, good for debugging
|
@@ -1,126 +1,130 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
require 'docopt'
|
3
|
-
require 'json'
|
4
|
-
require 'awesome_print'
|
5
|
-
|
6
|
-
module Intrinio
|
7
|
-
|
8
|
-
# Handles the command line interface
|
9
|
-
class CommandLine
|
10
|
-
include Singleton
|
11
|
-
|
12
|
-
# Gets an array of arguments (e.g. ARGV), executes the command if valid
|
13
|
-
# and shows usage patterns / help otherwise.
|
14
|
-
def execute(argv=[])
|
15
|
-
doc = File.read File.dirname(__FILE__) + '/docopt.txt'
|
16
|
-
begin
|
17
|
-
args = Docopt::docopt(doc, argv: argv, version: VERSION)
|
18
|
-
handle args
|
19
|
-
rescue Docopt::Exit => e
|
20
|
-
puts e.message
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def intrinio
|
25
|
-
@intrinio ||= intrinio!
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
attr_reader :csv
|
31
|
-
|
32
|
-
def intrinio!
|
33
|
-
Intrinio::API.new options
|
34
|
-
end
|
35
|
-
|
36
|
-
# Called when the arguments match one of the usage patterns. Will
|
37
|
-
# delegate action to other, more specialized methods.
|
38
|
-
def handle(args)
|
39
|
-
path = args['PATH']
|
40
|
-
params = args['PARAMS']
|
41
|
-
file = args['FILE']
|
42
|
-
@csv
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
return
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
if
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
def
|
78
|
-
intrinio.
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
result
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
result
|
101
|
-
result
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
def
|
110
|
-
@
|
111
|
-
end
|
112
|
-
|
113
|
-
def
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
def
|
118
|
-
ENV['
|
119
|
-
end
|
120
|
-
|
121
|
-
def
|
122
|
-
ENV['
|
123
|
-
end
|
124
|
-
|
125
|
-
|
126
|
-
|
1
|
+
require 'singleton'
|
2
|
+
require 'docopt'
|
3
|
+
require 'json'
|
4
|
+
require 'awesome_print'
|
5
|
+
|
6
|
+
module Intrinio
|
7
|
+
|
8
|
+
# Handles the command line interface
|
9
|
+
class CommandLine
|
10
|
+
include Singleton
|
11
|
+
|
12
|
+
# Gets an array of arguments (e.g. ARGV), executes the command if valid
|
13
|
+
# and shows usage patterns / help otherwise.
|
14
|
+
def execute(argv=[])
|
15
|
+
doc = File.read File.dirname(__FILE__) + '/docopt.txt'
|
16
|
+
begin
|
17
|
+
args = Docopt::docopt(doc, argv: argv, version: VERSION)
|
18
|
+
handle args
|
19
|
+
rescue Docopt::Exit, Intrinio::MissingAuth => e
|
20
|
+
puts e.message
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def intrinio
|
25
|
+
@intrinio ||= intrinio!
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :path, :params, :file, :csv
|
31
|
+
|
32
|
+
def intrinio!
|
33
|
+
Intrinio::API.new options
|
34
|
+
end
|
35
|
+
|
36
|
+
# Called when the arguments match one of the usage patterns. Will
|
37
|
+
# delegate action to other, more specialized methods.
|
38
|
+
def handle(args)
|
39
|
+
@path = args['PATH']
|
40
|
+
@params = translate_params args['PARAMS']
|
41
|
+
@file = args['FILE']
|
42
|
+
@csv = args['--csv']
|
43
|
+
|
44
|
+
if intrinio_auth.empty?
|
45
|
+
raise Intrinio::MissingAuth, "Missing Authentication\nPlease set INTRINIO_AUTH=username:password"
|
46
|
+
end
|
47
|
+
|
48
|
+
return get if args['get']
|
49
|
+
return pretty if args['pretty']
|
50
|
+
return see if args['see']
|
51
|
+
return url if args['url']
|
52
|
+
return save if args['save']
|
53
|
+
end
|
54
|
+
|
55
|
+
def get
|
56
|
+
if csv
|
57
|
+
puts intrinio.get_csv path, params
|
58
|
+
else
|
59
|
+
puts intrinio.get! path, params
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def save
|
64
|
+
if csv
|
65
|
+
success = intrinio.save_csv file, path, params
|
66
|
+
else
|
67
|
+
success = intrinio.save file, path, params
|
68
|
+
end
|
69
|
+
puts success ? "Saved #{file}" : "Saving failed"
|
70
|
+
end
|
71
|
+
|
72
|
+
def pretty
|
73
|
+
response = intrinio.get path, params
|
74
|
+
puts JSON.pretty_generate response
|
75
|
+
end
|
76
|
+
|
77
|
+
def see
|
78
|
+
ap intrinio.get path, params
|
79
|
+
end
|
80
|
+
|
81
|
+
def url
|
82
|
+
intrinio.debug = true
|
83
|
+
puts intrinio.get path, params
|
84
|
+
intrinio.debug = false
|
85
|
+
end
|
86
|
+
|
87
|
+
# Convert a params array like [key:value, key:value] to a hash like
|
88
|
+
# {key: value, key: value}
|
89
|
+
def translate_params(pairs)
|
90
|
+
return nil if pairs.empty?
|
91
|
+
result = {}
|
92
|
+
pairs.each do |pair|
|
93
|
+
key, value = pair.split ':'
|
94
|
+
result[key] = value
|
95
|
+
end
|
96
|
+
result
|
97
|
+
end
|
98
|
+
|
99
|
+
def options
|
100
|
+
result = { username: username, password: password }
|
101
|
+
return result unless cache_dir || cache_life
|
102
|
+
|
103
|
+
result[:use_cache] = true
|
104
|
+
result[:cache_dir] = cache_dir if cache_dir
|
105
|
+
result[:cache_life] = cache_life.to_i if cache_life
|
106
|
+
result
|
107
|
+
end
|
108
|
+
|
109
|
+
def username
|
110
|
+
@username ||= intrinio_auth.split(':').first
|
111
|
+
end
|
112
|
+
|
113
|
+
def password
|
114
|
+
@password ||= intrinio_auth.split(':').last
|
115
|
+
end
|
116
|
+
|
117
|
+
def intrinio_auth
|
118
|
+
ENV['INTRINIO_AUTH'] || ''
|
119
|
+
end
|
120
|
+
|
121
|
+
def cache_dir
|
122
|
+
ENV['INTRINIO_CACHE_DIR']
|
123
|
+
end
|
124
|
+
|
125
|
+
def cache_life
|
126
|
+
ENV['INTRINIO_CACHE_LIFE']
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
data/lib/intrinio/docopt.txt
CHANGED
@@ -1,64 +1,77 @@
|
|
1
|
-
Intrinio
|
2
|
-
|
3
|
-
Usage:
|
4
|
-
intrinio get [--csv] PATH [PARAMS...]
|
5
|
-
intrinio pretty PATH [PARAMS...]
|
6
|
-
intrinio see PATH [PARAMS...]
|
7
|
-
intrinio url PATH [PARAMS...]
|
8
|
-
intrinio save [--csv] FILE PATH [PARAMS...]
|
9
|
-
intrinio (-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 awesome-prints it.
|
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 Intrinio API path, without the query string.
|
30
|
-
For example: `indices` or `historical_data`.
|
31
|
-
|
32
|
-
PARAMS:
|
33
|
-
An optional list of query string parameters, separated by a space, to
|
34
|
-
send with the request. Each parameter should be in the format of
|
35
|
-
key:value, for example: page:2 per_page:10
|
36
|
-
|
37
|
-
FILE:
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
intrinio
|
63
|
-
|
64
|
-
intrinio
|
1
|
+
Intrinio
|
2
|
+
|
3
|
+
Usage:
|
4
|
+
intrinio get [--csv] PATH [PARAMS...]
|
5
|
+
intrinio pretty PATH [PARAMS...]
|
6
|
+
intrinio see PATH [PARAMS...]
|
7
|
+
intrinio url PATH [PARAMS...]
|
8
|
+
intrinio save [--csv] FILE PATH [PARAMS...]
|
9
|
+
intrinio (-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 awesome-prints it.
|
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 Intrinio API path, without the query string.
|
30
|
+
For example: `indices` or `historical_data`.
|
31
|
+
|
32
|
+
PARAMS:
|
33
|
+
An optional list of query string parameters, separated by a space, to
|
34
|
+
send with the request. Each parameter should be in the format of
|
35
|
+
key:value, for example: page:2 per_page:10
|
36
|
+
|
37
|
+
FILE:
|
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
|
+
Environment Variables:
|
47
|
+
INTRINIO_AUTH=username:password
|
48
|
+
Set Intrinio username and password. This variable is required.
|
49
|
+
|
50
|
+
INTRINIO_CACHE_LIFE=360
|
51
|
+
Set the number of seconds to consider the cache fresh. This variable
|
52
|
+
it optional.
|
53
|
+
|
54
|
+
INTRINIO_CACHE_DIR=./cache
|
55
|
+
Set the cache directory. This variable is optional.
|
56
|
+
If both INTRINIO_CACHE_DIR and INTRINIO_CACHE_LIFE are not set, requests
|
57
|
+
will not be cached.
|
58
|
+
|
59
|
+
Examples:
|
60
|
+
intrinio see indices page_size:5
|
61
|
+
|
62
|
+
intrinio pretty indices "query:interest rate" page_size:5
|
63
|
+
|
64
|
+
intrinio see companies identifier:AAPL
|
65
|
+
|
66
|
+
intrinio see historical_data identifier:\$INTDSRUSM193N item:level \
|
67
|
+
start_date:2015-01-01
|
68
|
+
|
69
|
+
intrinio see historical_data identifier:\$SP500 item:percent_change \
|
70
|
+
frequency:monthly page_size:10
|
71
|
+
|
72
|
+
intrinio save aapl.json historical_data identifier:AAPL \
|
73
|
+
item:adj_close_price frequency:monthly page_size:10
|
74
|
+
|
75
|
+
intrinio get --csv indices page_size:5
|
76
|
+
|
77
|
+
intrinio save --csv indices.csv indices page_size:5
|
data/lib/intrinio/exceptions.rb
CHANGED
data/lib/intrinio/version.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.1
|
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-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docopt
|