Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ jobs:
runs-on: ubuntu-latest

strategy:
matrix: { ruby: ['2.4', '2.5', '2.6', '2.7', '3.0'] }
matrix: { ruby: ['3.2', '3.3', '3.4', '4.0'] }

env:
INTRINIO_AUTH: ${{ secrets.INTRINIO_AUTH }}

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install OS dependencies
run: sudo apt-get -y install libyaml-dev
Expand Down
13 changes: 13 additions & 0 deletions .repocard.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# repocard (https://github.com/dannyben/repocard)

# Project Maturity: Experimental, Alpha, Beta, Stable, Legacy, Archived
item=Project Maturity|yellow|Beta

# API Policy: Unstable, Mostly Stable, SemVer, Locked
item=API Policy|yellow|Mostly Stable

# Maintenance Status: Active, Passive, Bugfix Only, Sunset
item=Maintenance Status|orange|Passive

# Intended Audience: Developers, Power Users, End Users, [Specific Group]
item=Intended Audience|blue|End Users
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--require spec_helper
--color
--format documentation
--fail-fast
15 changes: 15 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins:
- rubocop-performance
- rubocop-rspec

inherit_gem:
rentacop:
- rentacop.yml
- rspec.yml

AllCops:
TargetRubyVersion: 3.2
SuggestExtensions: false
Exclude:
- 'dev/**/*'

3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "https://rubygems.org"
source 'https://rubygems.org'

gem 'byebug'
gem 'rspec'
Expand All @@ -8,4 +8,3 @@ gem 'runfile-tasks'
gem 'simplecov'

gemspec

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Intrinio API Library and Command Line

![repocard](repocard.svg)

This gem provides both a Ruby library and a command line interface for the
[Intrinio][1] data service.

Expand Down
4 changes: 2 additions & 2 deletions bin/intrinio
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'intrinio'
begin
Intrinio::CommandLine.execute ARGV
rescue APICake::BadResponse => e
STDERR.puts "#{e.class} - #{e.message}"
$stderr.puts "#{e.class} - #{e.message}"
rescue Intrinio::MissingAuth => e
STDERR.puts e.message
$stderr.puts e.message
end
26 changes: 16 additions & 10 deletions intrinio.gemspec
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'date'
require 'intrinio/version'

Gem::Specification.new do |s|
s.name = 'intrinio'
s.version = Intrinio::VERSION
s.date = Date.today.to_s
s.summary = "Intrinio API Library and Command Line"
s.description = "Easy to use API for Intrinio data service with a command line interface"
s.authors = ["Danny Ben Shitrit"]
s.summary = 'Intrinio API Library and Command Line'
s.description = 'Easy to use API for Intrinio data service with a command line interface'
s.authors = ['Danny Ben Shitrit']
s.email = 'db@dannyben.com'
s.files = Dir['README.md', 'lib/**/*.*']
s.executables = ["intrinio"]
s.executables = ['intrinio']
s.homepage = 'https://github.com/DannyBen/intrinio'
s.license = 'MIT'
s.required_ruby_version = ">= 2.0.0"
s.required_ruby_version = '>= 3.2'

s.add_runtime_dependency 'super_docopt', '~> 0.1'
s.add_runtime_dependency 'lp', '~> 0.2'
s.add_runtime_dependency 'apicake', '~> 0.1'
s.add_dependency 'apicake', '~> 0.2'
s.add_dependency 'lp', '~> 0.2'
s.add_dependency 'super_docopt', '~> 0.2'

s.metadata = {
'bug_tracker_uri' => 'https://github.com/dannyben/intrinio/issues',
'changelog_uri' => 'https://github.com/dannyben/intrinio/blob/master/CHANGELOG.md',
'source_code_uri' => 'https://github.com/dannyben/intrinio',
'rubygems_mfa_required' => 'true',
}
end
57 changes: 29 additions & 28 deletions lib/intrinio/api.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
require 'apicake'

module Intrinio
# Provides access to all the Intrinio API endpoints with dynamic methods
# anc caching.
class API < APICake::Base
base_uri 'https://api.intrinio.com'

attr_reader :username, :password

def initialize(opts={})
if opts[:auth]
opts[:username], opts[:password] = opts[:auth].split ':'
opts.delete :auth
end

@username, @password = opts[:username], opts[:password]

cache.disable unless opts[:use_cache]
cache.dir = opts[:cache_dir] if opts[:cache_dir]
cache.life = opts[:cache_life] if opts[:cache_life]
end

def default_params
{ basic_auth: { username: username, password: password } }
end
end
end
require 'apicake'

module Intrinio
# Provides access to all the Intrinio API endpoints with dynamic methods
# anc caching.
class API < APICake::Base
base_uri 'https://api.intrinio.com'

attr_reader :username, :password

def initialize(opts = {})
if opts[:auth]
opts[:username], opts[:password] = opts[:auth].split ':'
opts.delete :auth
end

@username = opts[:username]
@password = opts[:password]

cache.disable unless opts[:use_cache]
cache.dir = opts[:cache_dir] if opts[:cache_dir]
cache.life = opts[:cache_life] if opts[:cache_life]
end

def default_params
{ basic_auth: { username: username, password: password } }
end
end
end
23 changes: 11 additions & 12 deletions lib/intrinio/command_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
require 'lp'

module Intrinio

# Handles the command line interface
class CommandLine < SuperDocopt::Base
version VERSION
docopt File.expand_path 'docopt.txt', __dir__
subcommands ['get', 'pretty', 'see', 'url', 'save']
subcommands %w[get pretty see url save]

attr_reader :path, :params, :file, :csv

Expand All @@ -18,9 +17,9 @@ def before_execute
@file = args['FILE']
@csv = args['--csv']

if intrinio_auth.empty?
raise Intrinio::MissingAuth, "Missing Authentication\nPlease set INTRINIO_AUTH=username:password"
end
return unless intrinio_auth.empty?

raise Intrinio::MissingAuth, "Missing Authentication\nPlease set INTRINIO_AUTH=username:password"
end

def get
Expand All @@ -33,12 +32,12 @@ def get
end

def save
if csv
success = intrinio.save_csv file, path, params
success = if csv
intrinio.save_csv file, path, params
else
success = intrinio.save file, path, params
intrinio.save file, path, params
end
puts success ? "Saved #{file}" : "Saving failed"
puts success ? "Saved #{file}" : 'Saving failed'
end

def pretty
Expand All @@ -59,6 +58,7 @@ def url
def translate_params(pairs)
result = {}
return result if pairs.empty?

pairs.each do |pair|
key, value = pair.split ':'
result[key.to_sym] = value
Expand All @@ -70,7 +70,7 @@ def intrinio
@intrinio ||= intrinio!
end

private
private

def intrinio!
Intrinio::API.new options
Expand All @@ -79,7 +79,7 @@ def intrinio!
def options
result = { username: username, password: password }
return result unless cache_dir || cache_life

result[:use_cache] = true
result[:cache_dir] = cache_dir if cache_dir
result[:cache_life] = cache_life.to_i if cache_life
Expand All @@ -105,6 +105,5 @@ def cache_dir
def cache_life
ENV['INTRINIO_CACHE_LIFE']
end

end
end
2 changes: 1 addition & 1 deletion lib/intrinio/exceptions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Intrinio
class MissingAuth < StandardError; end
end
end
4 changes: 2 additions & 2 deletions lib/intrinio/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Intrinio
VERSION = "0.1.6"
end
VERSION = '0.1.6'
end
27 changes: 27 additions & 0 deletions repocard.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 22 additions & 25 deletions spec/intrinio/api_spec.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
require 'spec_helper'

describe API do
before :all do
ENV['INTRINIO_AUTH'] or raise "Please set INTRINIO_AUTH=user:pass before running tests"
ENV['INTRINIO_AUTH'] or raise 'Please set INTRINIO_AUTH=user:pass before running tests'
end

let(:intrinio) { API.new auth: ENV['INTRINIO_AUTH'], use_cache: true }
let(:intrinio) { described_class.new auth: ENV['INTRINIO_AUTH'], use_cache: true }

describe '#new' do
it "initializes with credentials" do
intrinio = API.new username: 'me', password: 'secret'
it 'initializes with credentials' do
intrinio = described_class.new username: 'me', password: 'secret'
expect(intrinio.username).to eq 'me'
expect(intrinio.password).to eq 'secret'
end

it "initializes with compact credentials" do
intrinio = API.new auth: 'me:secret'
it 'initializes with compact credentials' do
intrinio = described_class.new auth: 'me:secret'
expect(intrinio.username).to eq 'me'
expect(intrinio.password).to eq 'secret'
end

it "starts with cache disabled" do
intrinio = API.new
it 'starts with cache disabled' do
intrinio = described_class.new
expect(intrinio.cache).not_to be_enabled
end

it "initializes with options" do
intrinio = API.new username: 'me', password: 'secret',
it 'initializes with options' do
intrinio = described_class.new username: 'me', password: 'secret',
use_cache: true,
cache_dir: 'custom',
cache_life: 1337
Expand All @@ -35,41 +33,40 @@
expect(intrinio.cache.life).to eq 1337
expect(intrinio.cache).to be_enabled
end

end

describe '#get_csv' do
context "with a valid request" do
it "returns a csv string" do
result = intrinio.get_csv :historical_data, identifier: 'AAPL',
item: 'close_price', start_date: '2016-01-01',
context 'with a valid request' do
it 'returns a csv string' do
result = intrinio.get_csv :historical_data, identifier: 'AAPL',
item: 'close_price', start_date: '2016-01-01',
end_date: '2016-01-31', sort_order: 'asc'

expect(result).to match_approval('aapl.csv')
end
end

context "with an invalid request" do
it "raises an error" do
expect{intrinio.get_csv :bogus_endpoint}.to raise_error(APICake::BadResponse)
context 'with an invalid request' do
it 'raises an error' do
expect { intrinio.get_csv :bogus_endpoint }.to raise_error(APICake::BadResponse)
end
end
end

describe '#save_csv' do
let(:filename) { 'tmp.csv' }

it "saves output to a file" do
it 'saves output to a file' do
File.delete filename if File.exist? filename
expect(File).not_to exist(filename)

intrinio.save_csv filename, :historical_data, identifier: 'AAPL',
item: 'close_price', start_date: '2016-01-01',
item: 'close_price', start_date: '2016-01-01',
end_date: '2016-01-31', sort_order: 'asc'

expect(File).to exist(filename)
expect(File.read filename).to match_approval('aapl.csv')

File.delete filename
end
end
Expand Down
Loading