funds 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/Account.rb +10 -0
- data/lib/FinancialInstitution.rb +13 -0
- data/lib/Holding.rb +11 -0
- data/lib/OFXClient.rb +110 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8e77922ddce09cdfadb5fd3ba65da4a149a4f958
|
4
|
+
data.tar.gz: d2643af7cb5217c2cc4d8052c812a5b89daf259e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d0578930d62810558f4932eb20c2c7c27e0957dc536ff320dde92b6d164d7a1fb1f1e55ad41b67ba0210f1205b997af66c81d15fb0a1f868b027e290f1b8ee34
|
7
|
+
data.tar.gz: 6f6a7d89dda35ac67ea02a7075e00a6a09404242e7896536b545284b90c0e78bea0884d2d7e51fb9c1b828a08ff09fe3c1b967f05f2fdf448418394803c67698
|
data/lib/Account.rb
ADDED
data/lib/Holding.rb
ADDED
data/lib/OFXClient.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require "./FinancialInstitution.rb"
|
2
|
+
require "rubygems"
|
3
|
+
require "httpclient"
|
4
|
+
require "nokogiri"
|
5
|
+
|
6
|
+
class OFXClient
|
7
|
+
|
8
|
+
def self.investment_accounts(fi, username, password)
|
9
|
+
|
10
|
+
# construct our OFX XML
|
11
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
12
|
+
xml.OFX {
|
13
|
+
xml.SIGNONMSGSRQV1 {
|
14
|
+
xml.SONRQ {
|
15
|
+
xml.DTCLIENT Time.new.strftime("%Y%m%d%H%M%S")
|
16
|
+
xml.USERID username
|
17
|
+
xml.USERPASS password
|
18
|
+
xml.LANGUAGE "ENG"
|
19
|
+
xml.FI {
|
20
|
+
xml.FID fi.fid.to_s
|
21
|
+
xml.ORG fi.org
|
22
|
+
}
|
23
|
+
xml.APPID "funds"
|
24
|
+
xml.APPVER "0.0.1"
|
25
|
+
}
|
26
|
+
}
|
27
|
+
xml.SIGNUPMSGSRQV1 {
|
28
|
+
xml.xxxxTRNRQ {
|
29
|
+
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
# insert the required OFX declaration after XML declaration
|
36
|
+
# nokogiri's builder cannot do this
|
37
|
+
ofxDeclaration = "\n<?OFX OFXHEADER=\"200\" VERSION=\"211\" SECURITY=\"NONE\" OLDFILEUID=\"NONE\" NEWFILEUID=\"NONE\"?>"
|
38
|
+
xml = builder.to_xml.insert(21, ofxDeclaration)
|
39
|
+
#puts xml
|
40
|
+
|
41
|
+
|
42
|
+
httpClient = HTTPClient.new
|
43
|
+
|
44
|
+
#required headers
|
45
|
+
extheader = [['Content-Type', 'application/x-ofx']]
|
46
|
+
extheader.push(['Content-Length', xml.bytesize.to_s])
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.investment_holdings(fi, username, password, accountNumber)
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
# returns hash of FI names : fids
|
57
|
+
# names include or match the passed search term
|
58
|
+
def self.search_institutions(term)
|
59
|
+
httpClient = HTTPClient.new
|
60
|
+
res = httpClient.get_content("http://www.ofxhome.com/api.php?search=" + term)
|
61
|
+
doc = Nokogiri::XML(res)
|
62
|
+
return OFXClient::doc_to_hash(doc)
|
63
|
+
end
|
64
|
+
|
65
|
+
# returns hash of ALL FI names : fids
|
66
|
+
def self.all_institutions
|
67
|
+
httpClient = HTTPClient.new
|
68
|
+
res = httpClient.get_content("http://www.ofxhome.com/api.php?all=yes")
|
69
|
+
doc = Nokogiri::XML(res)
|
70
|
+
return OFXClient::doc_to_hash(doc)
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.get_institution(fid)
|
74
|
+
httpClient = HTTPClient.new
|
75
|
+
res = httpClient.get_content("http://www.ofxhome.com/api.php?lookup=" + fid.to_s)
|
76
|
+
doc = Nokogiri::XML(res)
|
77
|
+
|
78
|
+
institutionElements = doc.xpath("//institution")
|
79
|
+
|
80
|
+
if(institutionElements.length == 1)
|
81
|
+
if(institutionElements.first["id"].eql? fid.to_s)
|
82
|
+
name = doc.xpath("//institution//name").first.content
|
83
|
+
org = doc.xpath("//institution//org").first.content
|
84
|
+
url = doc.xpath("//institution//url").first.content
|
85
|
+
|
86
|
+
return FinancialInstitution.new(fid, name, org, url)
|
87
|
+
|
88
|
+
else
|
89
|
+
# error in ofxhome api
|
90
|
+
return nil
|
91
|
+
end
|
92
|
+
else
|
93
|
+
# the institution with specified fid doesn't exist
|
94
|
+
# in the ofxhome.com database
|
95
|
+
return nil
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def self.doc_to_hash(doc)
|
102
|
+
hash = Hash.new
|
103
|
+
doc.xpath("//institutionid").each do |node|
|
104
|
+
hash[node["name"]] = node["id"].to_i
|
105
|
+
end
|
106
|
+
return hash
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: funds
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Forsyth
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.7.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.6.7.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httpclient
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.7.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.7.1
|
41
|
+
description: An Open Financial Exchange client.
|
42
|
+
email: justin@forsyth.im
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/Account.rb
|
48
|
+
- lib/FinancialInstitution.rb
|
49
|
+
- lib/Holding.rb
|
50
|
+
- lib/OFXClient.rb
|
51
|
+
homepage: http://rubygems.org/gems/funds
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.5.1
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Funds (alpha)
|
75
|
+
test_files: []
|