bankster-transaction 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 13233f67cf124e55da18ba4f729de47db24fe375
4
+ data.tar.gz: 3969267143d63497d34c88077db153c5c101339b
5
+ SHA512:
6
+ metadata.gz: 8cf75dcceee8ca6b8fee59b9d685ee0c333733bc63ca94d68b3f4775a9186edc4c51a198ffb2cba326079a535a22012ee5920e18d18c28625b5d251d47909348
7
+ data.tar.gz: c7ff5f40bf5368064778f07ac7eb9c77eaec58b776d7fecffff0468994b64f52e8800b11229fc3e9c54df1ad2d7e98e09ac3ef67bd9016ab1f0c6d4e52e79340
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .byebug_history
11
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ 2.3.0
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Roman Lehnert
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.
@@ -0,0 +1,123 @@
1
+ # Bankster::Shared
2
+
3
+ `Bankster::Transaction` provides some resources to transmit a bankster payment transaction.
4
+
5
+ * `Bankster::Transaction`: A PORO that acts as a model.
6
+ * `Bankster::Representers::TransactionRepresenter`: A grape representer that converts a `Bankster::Transaction` to json and vice versa.
7
+ * `schemas/transaction_schema`: A json schmema, that can validate a bankster transaction.
8
+ * `factories/transaction_factory`: A factory that provides mocked bankster transactions.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'bankster_shared'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install bankster_shared
25
+
26
+ ## Usage
27
+
28
+ ### Model
29
+
30
+ The `Bankster::Transaction` model has the following attributes accessible:
31
+
32
+ * name
33
+ * iban
34
+ * bic
35
+ * purpose
36
+ * valutation_date
37
+ * booking_date
38
+ * type
39
+
40
+ ### Representers
41
+
42
+ Given the bankster json api response for a transaction:
43
+
44
+ ```ruby
45
+ api_response = {
46
+ "name":"Max Mustermann",
47
+ ...
48
+ "amount":{"cents":"123","currency":"EUR"}
49
+ }
50
+ ```
51
+
52
+ The representer can fill a `Bankster::Transaction` object from the json:
53
+ ```ruby
54
+ # initialize a transaction object
55
+ transaction = Bankster::Transaction.new
56
+
57
+ # extend it with the representer
58
+ transaction.extend(Bankster::Representers::TransactionRepresenter)
59
+
60
+ # fill it from the json response
61
+ transaction.from_json(api_response)
62
+
63
+ transaction.amount # => Money.new(123, "EUR")
64
+ ```
65
+
66
+ In the other direction, the representer works the same. Given a `Bankster::Transaction` object, you can
67
+ extend it with the representer and call `#to_json` in order to get a json that matches our schema.
68
+
69
+ ```ruby
70
+ # extend the transaction with its representer
71
+ transaction.extend(Bankster::Representers::TransactionRepresenter)
72
+
73
+ # dump the json
74
+ puts transaction.to_json
75
+ # =>
76
+ {"purpose"=>"my purpose", "name"=>"Max Mustermann", "iban"=>"DE123", "bic"=>"ASD", "valutation_date"=>"2015-10-26", "booking_date"=>"2015-10-26", "type"=>"credit_tansfer", "amount"=>{"cents"=>"123", "currency"=>"EUR"}}
77
+ ```
78
+
79
+ ### Schemas
80
+
81
+ This gem provides a json schema that can be used somewhere else. E.g. if you want to speciy that some json string matches the transaction schema:
82
+
83
+ Utilize the [json-schema-matchers gem](https://github.com/sharethrough/json-schema-rspec) to write rspecs.
84
+
85
+ Add the following to your `spec/spec_helper.rb`:
86
+
87
+ ```ruby
88
+ bankster-transaction_dir = Gem::Specification.find_by_name('bankster-transaction').gem_dir
89
+
90
+ Dir[File.join(bankster-transaction_dir, "/lib/schemas/*.json")].each do |file|
91
+ config.json_schemas[File.basename(file, ".json").to_sym] = file
92
+ end
93
+ ```
94
+
95
+ And now, you can specify sth. to match one of the schemas that reside at `lib/schemas/`:
96
+
97
+ ```ruby
98
+ it 'matches the transaction schema' do
99
+ expect(some_json).to match_json_schema(:transaction_schema)
100
+ end
101
+
102
+ ```
103
+
104
+ ### Factories
105
+
106
+ If you intent to use one of the factories that are provided by this gem, just load them in your `spec/spec_helper`:
107
+ ```ruby
108
+ bankster-transaction_dir = Gem::Specification.find_by_name('bankster-transaction').gem_dir
109
+
110
+ Dir.glob(File.join(bankster-transaction_dir, "spec/factories/*.rb")).each { |f| require f }
111
+ ```
112
+
113
+
114
+
115
+ ## Development
116
+
117
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
118
+
119
+ 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).
120
+
121
+ ## Contributing
122
+
123
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bankster/bankster_shared.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'bankster-transaction'
7
+ spec.version = '0.1.1'
8
+ spec.authors = ['Roman Lehnert']
9
+ spec.email = ['roman.lehnert@googlemail.com']
10
+
11
+ spec.summary = 'Bankster::Transaction'
12
+ spec.description = 'Shared stuff for bankster servers and clients'
13
+ spec.homepage = 'http://bankster.io/'
14
+ spec.license = 'MIT'
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_runtime_dependency "roar"
30
+ spec.add_runtime_dependency "representable", "~> 2.4"
31
+ spec.add_runtime_dependency "multi_json"
32
+ spec.add_runtime_dependency "money"
33
+
34
+ spec.add_development_dependency 'json-schema-rspec'
35
+ spec.add_development_dependency 'bundler', '~> 1.10'
36
+ spec.add_development_dependency 'rake', '~> 10.0'
37
+ spec.add_development_dependency 'rspec'
38
+ spec.add_development_dependency 'factory_girl'
39
+ spec.add_development_dependency 'byebug'
40
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bankster_shared"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ require 'money'
2
+ require 'roar/json'
3
+
4
+ require 'models/transaction'
5
+ require 'representers/transaction_representer'
6
+ require 'representers/transactions_representer'
@@ -0,0 +1,12 @@
1
+ module Bankster
2
+ class Transaction
3
+ attr_accessor :purpose
4
+ attr_accessor :iban
5
+ attr_accessor :bic
6
+ attr_accessor :name
7
+ attr_accessor :amount
8
+ attr_accessor :type
9
+ attr_accessor :booking_date
10
+ attr_accessor :valutation_date
11
+ end
12
+ end
@@ -0,0 +1,49 @@
1
+ require 'roar/json'
2
+ module Bankster
3
+ module Representers
4
+ module TransactionRepresenter
5
+ include Roar::JSON
6
+ collection_representer class: Bankster::Transaction
7
+
8
+ property :purpose
9
+ property :name
10
+ property :iban
11
+ property :bic
12
+
13
+ # valutation_date is
14
+ # - a Date object in ruby
15
+ # - a ISO8601 date string in json
16
+ property :valutation_date,
17
+ reader: ->(doc:, represented:, **) { represented.valutation_date = Date.parse(doc['valutation_date']) if doc['valutation_date'] },
18
+ writer: ->(doc:, represented:, **) { doc['valutation_date'] = represented.valutation_date.iso8601 if represented.valutation_date }
19
+
20
+ # booking_date is
21
+ # - a Date object in ruby
22
+ # - a ISO8601 date string in json
23
+ property :booking_date,
24
+ reader: ->(doc:, represented:, **) { represented.booking_date = Date.parse(doc['booking_date']) if doc['booking_date'] },
25
+ writer: ->(doc:, represented:, **) { doc['booking_date'] = represented.booking_date.iso8601 if represented.booking_date }
26
+
27
+ # type is
28
+ # - a symbol in ruby
29
+ # - a string in json
30
+ property :type,
31
+ reader: ->(doc:, represented:, **) { represented.type = doc['type'].to_sym },
32
+ writer: ->(doc:, represented:, **) { doc['type'] = represented.type.to_s }
33
+
34
+ # amount is
35
+ # - a Money object in ruby
36
+ # - a Hash with "cents" and "currency" in json
37
+ property :amount,
38
+ reader: ->(doc:, represented:, **) {
39
+ represented.amount = Money.new(doc['amount']['cents'], doc['amount']['currency'])
40
+ },
41
+ writer: ->(doc:, represented:, **) {
42
+ doc['amount'] = {
43
+ 'cents' => represented.amount.cents.to_s,
44
+ 'currency' => represented.amount.currency
45
+ }
46
+ }
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,11 @@
1
+ require 'roar/json'
2
+ module Bankster
3
+ module Representers
4
+ module TransactionsRepresenter
5
+ include Roar::JSON
6
+ include Representable::JSON::Collection
7
+ include Representable::Hash
8
+ items extend: TransactionRepresenter, class: Bankster::Transaction
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ {
2
+ "type": "object",
3
+ "properties": {
4
+ "purpose": { "type": "string" },
5
+ "name": { "type": "string" },
6
+ "iban": { "type": "string" },
7
+ "bic": { "type": "string" },
8
+ "booking_date": { "type": "date" },
9
+ "valutation_date": { "type": "date" },
10
+ "type": { "type": "string" },
11
+ "amount": {
12
+ "type": "object",
13
+ "properties": {
14
+ "cents": { "type": "string" },
15
+ "currency": { "type": "string" }
16
+ }
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "array",
3
+ "items": {
4
+ "$ref": "transaction_schema.json"
5
+ }
6
+ }
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bankster-transaction
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Roman Lehnert
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: roar
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: representable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: multi_json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: money
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: json-schema-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: factory_girl
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: byebug
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Shared stuff for bankster servers and clients
154
+ email:
155
+ - roman.lehnert@googlemail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rspec"
162
+ - ".ruby-version"
163
+ - ".travis.yml"
164
+ - Gemfile
165
+ - LICENSE.txt
166
+ - README.md
167
+ - Rakefile
168
+ - bankster-transaction.gemspec
169
+ - bin/console
170
+ - bin/setup
171
+ - lib/bankster_shared.rb
172
+ - lib/models/transaction.rb
173
+ - lib/representers/transaction_representer.rb
174
+ - lib/representers/transactions_representer.rb
175
+ - lib/schemas/transaction_schema.json
176
+ - lib/schemas/transactions_schema.json
177
+ homepage: http://bankster.io/
178
+ licenses:
179
+ - MIT
180
+ metadata:
181
+ allowed_push_host: https://rubygems.org
182
+ post_install_message:
183
+ rdoc_options: []
184
+ require_paths:
185
+ - lib
186
+ required_ruby_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ requirements: []
197
+ rubyforge_project:
198
+ rubygems_version: 2.5.1
199
+ signing_key:
200
+ specification_version: 4
201
+ summary: Bankster::Transaction
202
+ test_files: []