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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d0685eb48926073584dcdce2b696f9ff9e16cff
4
- data.tar.gz: 92d8f5b8c2dd0cddea07f789c82e09933287876f
3
+ metadata.gz: 1445cecea92901fa631ab950788949e4ffb8472e
4
+ data.tar.gz: a984c027e44ba371c037e9bf9f595c5b8b260787
5
5
  SHA512:
6
- metadata.gz: 5940954864a1e0fd987dbc6c119a8804023d5a3b0cac93f75ee3f752c2b3bb65d138bd070a1249b97801cf71c4e236c5e22c3c63c0efd65b4e7a7aa422ab116e
7
- data.tar.gz: 74e9ee1c8d6a5f16ff78495f89c063d2b503fd04acfaa5dbd5c38245fa2602df5bc24822b7af33dd54d231e4670b08f687a0a5ef9cb714329c56bf260e419de1
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.json historical_data identifier: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 = args['--csv']
43
-
44
- return get(path, params) if args['get']
45
- return pretty(path, params) if args['pretty']
46
- return see(path, params) if args['see']
47
- return url(path, params) if args['url']
48
- return save(file, path, params) if args['save']
49
- end
50
-
51
- def get(path, params)
52
- if csv
53
- puts intrinio.get_csv path, translate_params(params)
54
- else
55
- puts intrinio.get! path, translate_params(params)
56
- end
57
- end
58
-
59
- def save(file, path, params)
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
65
- puts success ? "Saved #{file}" : "Saving failed"
66
- end
67
-
68
- def pretty(path, params)
69
- response = intrinio.get path, translate_params(params)
70
- puts JSON.pretty_generate response
71
- end
72
-
73
- def see(path, params)
74
- ap intrinio.get path, translate_params(params)
75
- end
76
-
77
- def url(path, params)
78
- intrinio.debug = true
79
- puts intrinio.get path, translate_params(params)
80
- intrinio.debug = false
81
- end
82
-
83
- # Convert a params array like [key:value, key:value] to a hash like
84
- # {key: value, key: value}
85
- def translate_params(params)
86
- return nil if params.empty?
87
- result = {}
88
- params.each do |param|
89
- key, value = param.split ':'
90
- result[key] = value
91
- end
92
- result
93
- end
94
-
95
- def options
96
- result = { username: username, password: password }
97
- return result unless cache_dir || cache_life
98
-
99
- result[:use_cache] = true
100
- result[:cache_dir] = cache_dir if cache_dir
101
- result[:cache_life] = cache_life.to_i if cache_life
102
- result
103
- end
104
-
105
- def username
106
- @username ||= intrinio_auth.split(':').first
107
- end
108
-
109
- def password
110
- @password ||= intrinio_auth.split(':').last
111
- end
112
-
113
- def intrinio_auth
114
- ENV['INTRINIO_AUTH'] || ''
115
- end
116
-
117
- def cache_dir
118
- ENV['INTRINIO_CACHE_DIR']
119
- end
120
-
121
- def cache_life
122
- ENV['INTRINIO_CACHE_LIFE']
123
- end
124
-
125
- end
126
- end
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
@@ -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
- 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
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
@@ -1,4 +1,5 @@
1
- module Intrinio
2
- class BadResponse < StandardError; end
3
- class IncompatibleResponse < StandardError; end
1
+ module Intrinio
2
+ class BadResponse < StandardError; end
3
+ class IncompatibleResponse < StandardError; end
4
+ class MissingAuth < StandardError; end
4
5
  end
@@ -1,3 +1,3 @@
1
1
  module Intrinio
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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-30 00:00:00.000000000 Z
11
+ date: 2017-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docopt