teller 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cf5c1ff1333acb15ef5ba071923ef838b162009404692dd4ac484e523750cbc8
4
+ data.tar.gz: 8f16479f346cfb8ab229f2e59dfddbfff719eec80c7213f31cadbe33e7244c4e
5
+ SHA512:
6
+ metadata.gz: 956fbbad3d348c9542edba1dc41f1ec194e51211f1eab1ea497be1789ecf54972a6d0539dad793a4295aa06da1cea71d1df9d289228dd3fab767c0d739592153
7
+ data.tar.gz: b3364bd36a6594481928ea81814ac90186bda9706f4883792c033bc2068d8fad4578e9f690dabd298164f2f6731599ceccb54c3e685f6bb54968eb6860a20de4
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ Gemfile.lock
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in teller.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
8
+ gem "webmock", "~> 3.18"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Stevie Graham
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # Teller
2
+
3
+ The official Ruby language bindings for the Teller API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'teller'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install teller
20
+
21
+ ## Usage
22
+
23
+ First configure the library for your application
24
+
25
+ ```ruby
26
+ Teller::Config.setup do |c|
27
+ c.certificate = "/path/to/teller/cert.pem"
28
+ c.private_key = "/path/to/its/private_key.pem"
29
+ c.access_token = "access-token-from-teller-connect-enrollment"
30
+ end
31
+ ```
32
+
33
+ Statically configuring an access token might make sense if you're just building something using your own accounts, but it doesn't if you're building something for thousands of users, which is why you can also set your config when instantiating the client.
34
+
35
+ ```ruby
36
+ client = Teller::Client.new access_token: "test_token_ky6igyqi3qxa4"
37
+ ```
38
+
39
+ During instantiation the client will take whatever static config you've made (if any), and apply config given to the constructor. Config values supplied at instantiation will override conflicting statically configured values.
40
+
41
+ Now you have your client configured you can use it to explore the API.
42
+
43
+ ```ruby
44
+ account = client.accounts.first
45
+ # => #<Teller::Resource type="credit", subtype="credit_card", status="open", name="Platinum Card", links={"transactions"=>"https://api.teller.io/accounts/acc_oiin624kqjrg2mp2ea000/transactions", "self"=>"https://api.teller.io/accounts/acc_oiin624kqjrg2mp2ea000", "balances"=>"https://api.teller.io/accounts/acc_oiin624kqjrg2mp2ea000/balances"}, last_four="7857", institution={"name"=>"Security Credit Union", "id"=>"security_cu"}, id="acc_oiin624kqjrg2mp2ea000", enrollment_id="enr_oiin624rqaojse22oe000", currency="USD">
46
+
47
+ account.name
48
+ # => "Platinum Card"
49
+ ```
50
+
51
+ You can easily load related resources linked to in the "links" section of the API response"
52
+
53
+ ```ruby
54
+ account.balances
55
+ # => #<Teller::Resource links={"self"=>"https://api.teller.io/accounts/acc_oiin624kqjrg2mp2ea000/balances", "account"=>"https://api.teller.io/accounts/acc_oiin624kqjrg2mp2ea000"}, ledger="4698.93", available="204.12", account_id="acc_oiin624kqjrg2mp2ea000">
56
+
57
+ account.transactions
58
+ # => [#<Teller::Resource type="card_payment", status="pending", running_balance=nil, links={"self"=>"https://api.teller.io/accounts/acc_oiin624kqjrg2mp2ea000/transactions/txn_oj0t0gfqpvj7favgn8000", "account"=>"https://api.teller.io/accounts/acc_oiin624kqjrg2mp2ea000"}, id="txn_oj0t0gfqpvj7favgn8000", details={"processing_status"=>"complete", "counterparty"=>{"type"=>"organization", "name"=>"WILLIAMS-SONOMA"}, "category"=>"shopping"}, description="Williams-Sonoma", date="2023-07-23", amount="96.95", account_id="acc_oiin624kqjrg2mp2ea000">, ...]
59
+ ```
60
+
61
+ You can also fetch arbitrary members of a collection resource
62
+
63
+ ```ruby
64
+ client.accounts.get("acc_oiin624jqjrg2mp2ea000")
65
+ # => #<Teller::Resource type="depository", subtype="savings", status="open", name="Essential Savings", links={"transactions"=>"https://api.teller.io/accounts/acc_oiin624jqjrg2mp2ea000/transactions", "self"=>"https://api.teller.io/accounts/acc_oiin624jqjrg2mp2ea000", "details"=>"https://api.teller.io/accounts/acc_oiin624jqjrg2mp2ea000/details", "balances"=>"https://api.teller.io/accounts/acc_oiin624jqjrg2mp2ea000/balances"}, last_four="3528", institution={"name"=>"Security Credit Union", "id"=>"security_cu"}, id="acc_oiin624jqjrg2mp2ea000", enrollment_id="enr_oiin624rqaojse22oe000", currency="USD">
66
+ ```
67
+
68
+ The client caches API responses after the first time you invoke a method that requests a given resource. To force the client to redo the request you can call reload
69
+
70
+ ```ruby
71
+ # When called the first time the client will make a request to the Teller API
72
+ client.accounts
73
+
74
+ # On subsequent invocations locally cached data is returned
75
+ client.accounts
76
+ client.accounts
77
+ client.accounts
78
+
79
+ # Calling reload will always result in a new API request
80
+ client.accounts.reload
81
+ ```
82
+
83
+
84
+ ## Development
85
+
86
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
87
+
88
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
89
+
90
+ ## Contributing
91
+
92
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tellerhq/teller-ruby.
93
+
94
+ ## License
95
+
96
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "teller"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/teller/api.rb ADDED
@@ -0,0 +1,56 @@
1
+ class Teller::API
2
+ class Error < StandardError; end
3
+ def initialize(config)
4
+ @config = config
5
+ end
6
+
7
+ def delete(url)
8
+ request(:delete, url)
9
+ end
10
+
11
+ def get(url)
12
+ request(:get, url)
13
+ end
14
+
15
+ def post(url, body)
16
+ request(:post, url, body)
17
+ end
18
+
19
+ def request(method, url, body=nil)
20
+ uri = URI.parse(url)
21
+
22
+ http = Net::HTTP.new(uri.host, uri.port)
23
+ http.use_ssl = true
24
+
25
+ if @config.certificate && @config.private_key
26
+ http.cert = @config.certificate
27
+ http.key = @config.private_key
28
+ end
29
+
30
+ klass = Net::HTTP.const_get(method.to_s.capitalize)
31
+
32
+ request = klass.new(uri.request_uri)
33
+
34
+ if body
35
+ request.body = body.to_json
36
+ request.add_field("Content-Type", "application/json")
37
+ end
38
+
39
+
40
+ if @config.access_token
41
+ request.add_field('Authorization', "Basic #{Base64.strict_encode64("#{@config.access_token}:")}")
42
+ end
43
+
44
+ response = http.request(request)
45
+
46
+ case response
47
+ when Net::HTTPNoContent
48
+ return
49
+ when Net::HTTPSuccess
50
+ JSON.parse(response.body)
51
+ when Net::HTTPClientError, Net::HTTPServerError
52
+ error = JSON.parse(response.body)
53
+ raise Error, "#{error["error"]["code"]} - #{error["error"]["message"]}"
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,26 @@
1
+ module Teller
2
+ class Client
3
+ URL = "https://api.teller.io".freeze
4
+
5
+ def initialize(overrides={})
6
+ config = Teller::Config.dup
7
+ config.setup(overrides)
8
+
9
+ client = Teller::API.new(config)
10
+ entrypoint = client.get(URL)
11
+ @target = Teller::Resource.new(entrypoint, client)
12
+ end
13
+
14
+ def method_missing(method, *args, &block)
15
+ if @target.respond_to?(method)
16
+ @target.send(method, *args, &block)
17
+ else
18
+ super
19
+ end
20
+ end
21
+
22
+ def respond_to_missing?(method, include_private = false)
23
+ @target.respond_to?(method)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,41 @@
1
+ module Teller
2
+ class CollectionResource
3
+ def initialize(url, collection, client)
4
+ @url = url
5
+ @collection = collection.map { |i| Teller::Resource.new(i, client) }
6
+ @client = client
7
+ end
8
+
9
+ def get(id)
10
+ url = @url + "/" + id
11
+ Teller::Resource.new(@client.get(url), @client)
12
+ end
13
+
14
+ def delete
15
+ @client.delete @url
16
+ @collection = []
17
+ true
18
+ end
19
+
20
+ def reload
21
+ @collection = @client.get(@url).map { |i| Teller::Resource.new(i, @client) }
22
+ self
23
+ end
24
+
25
+ def method_missing(method, *args, &block)
26
+ if @collection.respond_to?(method)
27
+ @collection.send(method, *args, &block)
28
+ else
29
+ super
30
+ end
31
+ end
32
+
33
+ def respond_to_missing?(method, include_private = false)
34
+ @collection.respond_to?(method) || super
35
+ end
36
+
37
+ def inspect
38
+ @collection
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,49 @@
1
+ require 'openssl'
2
+
3
+ module Teller::Config
4
+ class Error < StandardError; end
5
+
6
+ attr_accessor :access_token, :certificate, :private_key
7
+
8
+ def setup(opts = {})
9
+ if block_given?
10
+ yield(self)
11
+ else
12
+ opts.each { |k, v| send(:"#{k}=", v) }
13
+ end
14
+ end
15
+
16
+ def certificate=(path)
17
+ if path
18
+ begin
19
+ File.open(path, 'r') do |file|
20
+ @certificate = OpenSSL::X509::Certificate.new(file)
21
+ end
22
+ rescue Errno::ENOENT
23
+ raise Error, "Certificate file not found: #{path}"
24
+ rescue OpenSSL::X509::CertificateError
25
+ raise Error, "Invalid certificate data in file: #{path}"
26
+ end
27
+ else
28
+ @certificate = nil
29
+ end
30
+ end
31
+
32
+ def private_key=(path)
33
+ if path
34
+ begin
35
+ File.open(path, 'r') do |file|
36
+ @private_key = OpenSSL::PKey.read(file, nil)
37
+ end
38
+ rescue Errno::ENOENT
39
+ raise Error, "Private key file not found: #{path}"
40
+ rescue OpenSSL::PKey::PKeyError
41
+ raise Error, "Invalid private key data in file: #{path}"
42
+ end
43
+ else
44
+ @private_key = nil
45
+ end
46
+ end
47
+
48
+ extend self
49
+ end
@@ -0,0 +1,47 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'base64'
5
+ require 'ostruct'
6
+
7
+ class Teller::Resource < OpenStruct
8
+ def initialize(state, client)
9
+ @client = client
10
+ super(state)
11
+ end
12
+
13
+ def method_missing(method, *args, &block)
14
+ if @table[:links].key?(method.to_s)
15
+ @table[method] ||= subresource(table[:links][method.to_s])
16
+ @table[method]
17
+ else
18
+ super
19
+ end
20
+ end
21
+
22
+ def delete
23
+ @client.delete @table[:links]["self"]
24
+ true
25
+ end
26
+
27
+ def reload
28
+ initialize(@client.get(@table[:links]["self"]), @client)
29
+ self
30
+ end
31
+
32
+ def respond_to_missing?(method, include_private = false)
33
+ @table[:links]&.key?(method.to_s) || super
34
+ end
35
+
36
+ private
37
+
38
+ def subresource(link)
39
+ state = @client.get(link)
40
+
41
+ if state.is_a?(Array)
42
+ Teller::CollectionResource.new(link, state, @client)
43
+ else
44
+ Teller::Resource.new(state, @client)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module Teller
2
+ VERSION = "0.0.1"
3
+ end
data/lib/teller.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "teller/version"
2
+ require "teller/config"
3
+ require "teller/resource"
4
+ require "teller/collection_resource"
5
+ require "teller/api"
6
+ require "teller/client"
7
+
8
+
9
+ module Teller
10
+ end
data/teller.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ require_relative 'lib/teller/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "teller"
5
+ spec.version = Teller::VERSION
6
+ spec.authors = ["Stevie Graham"]
7
+ spec.email = ["sg@teller.io"]
8
+
9
+ spec.summary = "The official Teller Ruby language bindings/"
10
+ spec.homepage = "https://github.com/tellerhq/teller-ruby"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = spec.homepage
16
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: teller
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stevie Graham
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-02-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - sg@teller.io
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".travis.yml"
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - bin/console
27
+ - bin/setup
28
+ - lib/teller.rb
29
+ - lib/teller/api.rb
30
+ - lib/teller/client.rb
31
+ - lib/teller/collection_resource.rb
32
+ - lib/teller/config.rb
33
+ - lib/teller/resource.rb
34
+ - lib/teller/version.rb
35
+ - teller.gemspec
36
+ homepage: https://github.com/tellerhq/teller-ruby
37
+ licenses:
38
+ - MIT
39
+ metadata:
40
+ homepage_uri: https://github.com/tellerhq/teller-ruby
41
+ source_code_uri: https://github.com/tellerhq/teller-ruby
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.3.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.5.6
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: The official Teller Ruby language bindings/
61
+ test_files: []