fredric 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
- SHA1:
3
- metadata.gz: d967dcaedc94f0f9d4eea06e6f37defc4ee1cef0
4
- data.tar.gz: bf8d0abc434b9ae0bb70b103b2b1e3fa127698dc
2
+ SHA256:
3
+ metadata.gz: e8e438025751929982efbc87e5362a4b6f9069296818dd95731240cab3de3825
4
+ data.tar.gz: fae8427f64a5e6aeefcbfe244e3eed28d40ced169cbf3f921391d1b1d99b5531
5
5
  SHA512:
6
- metadata.gz: b6a01e4e40852df35754250407c184b46cd1798ace70bdae57bbc676aa2dd7b9fee01f4c56c64aa8a17125ad5da1b477e017ae51b218893ef233c5bfe300b77b
7
- data.tar.gz: 02fc75cde31ae9ed972e18217c85f53560f2ccc66de2fd22b3f0558d4fdfd077a57e5767520c48ec76e70c8a07e0627e451226a9d7b7e0797f12de7357d72ac2
6
+ metadata.gz: d614754e95206fb5222fb28664bdf0bcf41782c5c002926480c5f4d4276c3da761c7fc7a2e23f2811f0366b1e3889115e4eb9c6934904157c6f8433e3b3f16d3
7
+ data.tar.gz: 54dac1f2e28f16b5895bf5d42af0a39a6db3d4d53fc346df78771aabb386c626939a0df2645a671ff670fac68b2994400eceb982a9cfa06400de25138aeba7b0
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  FRED API Library and Command Line
2
2
  ==================================================
3
3
 
4
- [![Gem](https://img.shields.io/gem/v/fredric.svg?style=flat-square)](https://rubygems.org/gems/fredric)
5
- [![Travis](https://img.shields.io/travis/DannyBen/fredric.svg?style=flat-square)](https://travis-ci.org/DannyBen/fredric)
6
- [![Code Climate](https://img.shields.io/codeclimate/github/DannyBen/fredric.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/fredric)
7
- [![Gemnasium](https://img.shields.io/gemnasium/DannyBen/fredric.svg?style=flat-square)](https://gemnasium.com/DannyBen/fredric)
4
+ [![Gem Version](https://badge.fury.io/rb/fredric.svg)](https://badge.fury.io/rb/fredric)
5
+ [![Build Status](https://travis-ci.com/DannyBen/fredric.svg?branch=master)](https://travis-ci.com/DannyBen/fredric)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/4b0a8627ceb5343b55fa/maintainability)](https://codeclimate.com/github/DannyBen/fredric/maintainability)
7
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/4b0a8627ceb5343b55fa/test_coverage)](https://codeclimate.com/github/DannyBen/fredric/test_coverage)
8
8
 
9
9
  ---
10
10
 
data/bin/fred CHANGED
@@ -3,7 +3,9 @@
3
3
  require 'fredric'
4
4
 
5
5
  begin
6
- Fredric::CommandLine.instance.execute ARGV
6
+ Fredric::CommandLine.execute ARGV
7
7
  rescue APICake::BadResponse => e
8
8
  STDERR.puts "#{e.class} - #{e.message}"
9
+ rescue Fredric::MissingAuth => e
10
+ STDERR.puts e.message
9
11
  end
data/lib/fredric/api.rb CHANGED
@@ -1,22 +1,22 @@
1
- require 'apicake'
2
-
3
- module Fredric
4
- # Provides access to all the FRED API endpoints with dynamic methods
5
- # anc caching.
6
- class API < APICake::Base
7
- base_uri 'https://api.stlouisfed.org/fred'
8
-
9
- attr_reader :api_key
10
-
11
- def initialize(api_key, opts={})
12
- @api_key = api_key
13
- cache.disable unless opts[:use_cache]
14
- cache.dir = opts[:cache_dir] if opts[:cache_dir]
15
- cache.life = opts[:cache_life] if opts[:cache_life]
16
- end
17
-
18
- def default_query
19
- { api_key: api_key, file_type: :json }
20
- end
21
- end
1
+ require 'apicake'
2
+
3
+ module Fredric
4
+ # Provides access to all the FRED API endpoints with dynamic methods
5
+ # anc caching.
6
+ class API < APICake::Base
7
+ base_uri 'https://api.stlouisfed.org/fred'
8
+
9
+ attr_reader :api_key
10
+
11
+ def initialize(api_key, opts={})
12
+ @api_key = api_key
13
+ cache.disable unless opts[:use_cache]
14
+ cache.dir = opts[:cache_dir] if opts[:cache_dir]
15
+ cache.life = opts[:cache_life] if opts[:cache_life]
16
+ end
17
+
18
+ def default_query
19
+ { api_key: api_key, file_type: :json }
20
+ end
21
+ end
22
22
  end
@@ -1,41 +1,18 @@
1
- require 'singleton'
2
- require 'docopt'
1
+ require 'super_docopt'
3
2
  require 'json'
4
3
  require 'awesome_print'
5
4
 
6
5
  module Fredric
7
6
 
8
7
  # 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, Fredric::MissingAuth => e
20
- puts e.message
21
- end
22
- end
23
-
24
- def fredric
25
- @fredric ||= fredric!
26
- end
27
-
28
- private
8
+ class CommandLine < SuperDocopt::Base
9
+ version VERSION
10
+ docopt File.expand_path 'docopt.txt', __dir__
11
+ subcommands ['get', 'pretty', 'see', 'url', 'save']
29
12
 
30
13
  attr_reader :path, :params, :file, :csv
31
14
 
32
- def fredric!
33
- Fredric::API.new api_key, 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)
15
+ def before_execute
39
16
  @path = args['PATH']
40
17
  @params = translate_params args['PARAMS']
41
18
  @file = args['FILE']
@@ -44,12 +21,6 @@ module Fredric
44
21
  unless api_key
45
22
  raise Fredric::MissingAuth, "Missing Authentication\nPlease set FRED_KEY=y0urAP1k3y"
46
23
  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
24
  end
54
25
 
55
26
  def get
@@ -83,6 +54,16 @@ module Fredric
83
54
  puts fredric.url path, params
84
55
  end
85
56
 
57
+ def fredric
58
+ @fredric ||= fredric!
59
+ end
60
+
61
+ private
62
+
63
+ def fredric!
64
+ Fredric::API.new api_key, options
65
+ end
66
+
86
67
  # Convert a params array like [key:value, key:value] to a hash like
87
68
  # {key: value, key: value}
88
69
  def translate_params(pairs)
@@ -1,3 +1,3 @@
1
1
  module Fredric
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fredric
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-03-10 00:00:00.000000000 Z
11
+ date: 2019-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: docopt
14
+ name: super_docopt
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.5'
19
+ version: '0.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.5'
26
+ version: '0.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: awesome_print
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,104 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.1'
55
- - !ruby/object:Gem::Dependency
56
- name: runfile
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '0.8'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '0.8'
69
- - !ruby/object:Gem::Dependency
70
- name: runfile-tasks
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '0.4'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '0.4'
83
- - !ruby/object:Gem::Dependency
84
- name: rspec
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '3.5'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '3.5'
97
- - !ruby/object:Gem::Dependency
98
- name: rdoc
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '5.0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '5.0'
111
- - !ruby/object:Gem::Dependency
112
- name: byebug
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '9.0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '9.0'
125
- - !ruby/object:Gem::Dependency
126
- name: simplecov
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '0.13'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '0.13'
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'
153
55
  description: Easy to use API for the Federal Reserve Economic Data service with a
154
56
  command line interface
155
57
  email: db@dannyben.com
@@ -186,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
88
  version: '0'
187
89
  requirements: []
188
90
  rubyforge_project:
189
- rubygems_version: 2.6.6
91
+ rubygems_version: 2.7.6
190
92
  signing_key:
191
93
  specification_version: 4
192
94
  summary: FRED API Library and Command Line