plaid-legacy 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ module Plaid
2
+ VERSION = '3.0.0'.freeze
3
+ end
@@ -0,0 +1,153 @@
1
+ module Plaid
2
+ # Public: Representation of a webhook.
3
+ class Webhook
4
+ # Public: The String human readable explanation of this webhook request.
5
+ # E.g. "Initial transaction pull finished".
6
+ attr_reader :message
7
+
8
+ # Public: The String access token for authenticated user.
9
+ attr_reader :access_token
10
+
11
+ # Public: The Integer number of transactions available in Plaid.
12
+ # E.g. 124
13
+ attr_reader :total_transactions
14
+
15
+ # Public: The Integer code denoting the type of webhook this is. E.g. 0
16
+ attr_reader :code
17
+
18
+ # Public: Initialize a Webhook instance.
19
+ #
20
+ # fields - The Hash with fields.
21
+ def initialize(fields)
22
+ @message = fields['message']
23
+ @access_token = fields['access_token']
24
+ @total_transactions = fields['total_transactions']
25
+ @code = fields['code']
26
+ # present only for Removed Transaction Webhook
27
+ @removed_transactions = fields['removed_transactions']
28
+ # present only for Error Response Webhook
29
+ @resolve = fields['resolve']
30
+ end
31
+
32
+ # Public: Share the type of Webhook this is from its code
33
+ #
34
+ # Returns String webhook type
35
+ def type
36
+ Webhook::CODEX[code] || 'ERROR_RESPONSE'
37
+ end
38
+
39
+ # Public: Detect if the webhook is Initial Transaction Webhook. Occurs
40
+ # once the initial transaction pull has finished.
41
+ #
42
+ # Returns true if it is.
43
+ def initial_transaction?
44
+ code == Webhook::INITIAL_TRANSACTION
45
+ end
46
+
47
+ # Public: Detect if the webhook is Historical Transaction Webhook. Occurs
48
+ # once the historical transaction pull has completed, shortly after the
49
+ # initial transaction pull.
50
+ #
51
+ # Returns true if it is.
52
+ def historical_transaction?
53
+ code == Webhook::HISTORICAL_TRANSACTION
54
+ end
55
+
56
+ # Public: Detect if the webhook is Normal Transaction Webhook. Occurs at
57
+ # set intervals throughout the day as data is updated from the financial
58
+ # institutions.
59
+ #
60
+ # Returns true if it is.
61
+ def normal_transaction?
62
+ code == Webhook::NORMAL_TRANSACTION
63
+ end
64
+
65
+ # Public: Detect if the webhook is Removed Transaction Webhook. Occurs when
66
+ # transactions have been removed from our system.
67
+ #
68
+ # Returns true if it is.
69
+ def removed_transaction?
70
+ code == Webhook::REMOVED_TRANSACTION
71
+ end
72
+
73
+ # Public: Detect if the webhook is User's Webhook Updated. Occurs when an
74
+ # user's webhook is updated via a PATCH request without credentials.
75
+ #
76
+ # Returns true if it is.
77
+ def user_webhook_updated?
78
+ code == Webhook::USER_WEBHOOK_UPDATED
79
+ end
80
+
81
+ # Public: Detect if the webhook is Income. Occurs when Income data is ready.
82
+ #
83
+ # Returns true if it is.
84
+ def income?
85
+ code == Webhook::INCOME
86
+ end
87
+
88
+ # Public: Detect if the webhook is Risk. Occurs when Risk data is ready.
89
+ #
90
+ # Returns true if it is.
91
+ def risk?
92
+ code == Webhook::RISK
93
+ end
94
+
95
+ # Public: Detect if the webhook is Error Response Webhook. Triggered when
96
+ # an error has occurred. Includes the relevant Plaid error code with
97
+ # details on both the error type and steps for error resolution.
98
+ #
99
+ # Returns true if it is.
100
+ def error_response?
101
+ Webhook::CODEX[code].nil?
102
+ end
103
+
104
+ # Public: Get transaction IDs that were removed.
105
+ #
106
+ # Returns Array[String] or nil
107
+ def removed_transactions_ids
108
+ @removed_transactions
109
+ end
110
+
111
+ # Public: Get a Plaid::Error instance if this is an Error Response Webhook
112
+ #
113
+ # Returns Plaid::Error or nil
114
+ def error
115
+ if error_response?
116
+ Plaid::PlaidError.new @code, @message, @resolve
117
+ end
118
+ end
119
+
120
+ # Public: Get a String representation of the transaction.
121
+ #
122
+ # Returns a String.
123
+ def inspect
124
+ "#<Plaid::Webhook type=#{type.inspect} code=#{code.inspect}, access_token=#{access_token.inspect}, " \
125
+ "total_transactions=#{total_transactions.inspect}, message=#{message.inspect}>"
126
+ end
127
+
128
+ # Public: Get a String representation of the transaction.
129
+ #
130
+ # Returns a String.
131
+ alias to_s inspect
132
+
133
+ private
134
+
135
+ ERROR_RESPONSE = -1
136
+
137
+ codex = {}
138
+ {
139
+ 'initial transaction' => 0,
140
+ 'historical transaction' => 1,
141
+ 'normal transaction' => 2,
142
+ 'removed transaction' => 3,
143
+ 'user webhook updated' => 4,
144
+ 'income' => 10,
145
+ 'risk' => 20
146
+ }.each do |event, idx|
147
+ name = event.split.map(&:upcase).join('_')
148
+ codex[idx] = name
149
+ const_set name, idx
150
+ end
151
+ CODEX = codex.freeze
152
+ end
153
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'plaid/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'plaid-legacy'
8
+ spec.version = Plaid::VERSION
9
+ spec.authors = ['Oleg Dashevskii']
10
+ spec.email = ['olegdashevskii@gmail.com']
11
+
12
+ spec.summary = 'Ruby bindings for Plaid\'s legacy API'
13
+ spec.description = 'Ruby gem wrapper for the Plaid\'s legacy API. Read more at the ' \
14
+ 'homepage, the wiki, or in the Plaid documentation.'
15
+ spec.homepage = 'https://github.com/plaid/plaid-ruby-legacy'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test/|\.gitignore|\.travis)})
20
+ end
21
+
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.required_ruby_version = '>= 2.0.0'
27
+
28
+ spec.add_dependency 'multi_json', '~> 1.0'
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.7'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'sdoc', '~> 0.4.1'
33
+ spec.add_development_dependency 'pry', '~> 0.10.3'
34
+ spec.add_development_dependency 'webmock', '~> 2.0.0'
35
+ spec.add_development_dependency 'minitest', '~> 5.8'
36
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plaid-legacy
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Oleg Dashevskii
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.4.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.4.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.0.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '5.8'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '5.8'
111
+ description: Ruby gem wrapper for the Plaid's legacy API. Read more at the homepage,
112
+ the wiki, or in the Plaid documentation.
113
+ email:
114
+ - olegdashevskii@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - CHANGELOG.md
120
+ - CONTRIBUTING.md
121
+ - Gemfile
122
+ - LICENSE
123
+ - README.md
124
+ - Rakefile
125
+ - UPGRADING.md
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/plaid.rb
129
+ - lib/plaid/account.rb
130
+ - lib/plaid/category.rb
131
+ - lib/plaid/client.rb
132
+ - lib/plaid/connector.rb
133
+ - lib/plaid/errors.rb
134
+ - lib/plaid/income.rb
135
+ - lib/plaid/info.rb
136
+ - lib/plaid/institution.rb
137
+ - lib/plaid/risk.rb
138
+ - lib/plaid/transaction.rb
139
+ - lib/plaid/user.rb
140
+ - lib/plaid/version.rb
141
+ - lib/plaid/webhook.rb
142
+ - plaid-legacy.gemspec
143
+ homepage: https://github.com/plaid/plaid-ruby-legacy
144
+ licenses:
145
+ - MIT
146
+ metadata: {}
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: 2.0.0
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 2.5.1
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: Ruby bindings for Plaid's legacy API
167
+ test_files: []