da_funk 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90a9a5f13e7351436d38420ccf9e99ca4919f56c
4
- data.tar.gz: c7745e68dbcf4fc145ca67cfc2c472cba6be8eda
3
+ metadata.gz: 0126b30dd3adddbd22dafdc3a478ecba668298c5
4
+ data.tar.gz: b8b4ed57370dde40c82323491769c29ba6ad36fd
5
5
  SHA512:
6
- metadata.gz: 8ec253d98c010406b4d58f7590e5b54345db4fbe6384a049470b8aa2ceb8c599bef0cbef558010ded38e72f83d8712dfe3b4206863f47fc92253e0ef67151999
7
- data.tar.gz: a723618fd4326f4788bd32b90a2be7b7fac2e085b9ed622027555b23efa6fcf6a6641c72d7df9f9bb15f356cf94b127c9d8cb8f0c55b12eb88da2777e5d4b921
6
+ metadata.gz: 04a5c2935a6a4a9c39cb31a45e088afec3625f18b1cb1a317e4c237db3b7e141b7152ee5c61a42b2bf6841c8eeb3103864a283f65152281eee97a030c06820eb
7
+ data.tar.gz: a4cfcd1395e0dade008fbf37326edaae6d738a2785cae0677d060446da0589c8bdd929f28474f61b708ff7f09d625c254f466b87daf7faad8ef8c1fad6342bbf
data/Gemfile.lock CHANGED
@@ -7,7 +7,7 @@ GIT
7
7
  PATH
8
8
  remote: .
9
9
  specs:
10
- da_funk (0.5.4)
10
+ da_funk (0.6.0)
11
11
  bundler (~> 1.7)
12
12
  cloudwalk_handshake (~> 0.5)
13
13
  posxml_parser (~> 0.6)
@@ -17,9 +17,9 @@ PATH
17
17
  GEM
18
18
  remote: https://rubygems.org/
19
19
  specs:
20
- cloudwalk_handshake (0.5.0)
21
- posxml_parser (0.6.1)
22
- rake (10.4.2)
20
+ cloudwalk_handshake (0.5.1)
21
+ posxml_parser (0.7.1)
22
+ rake (10.5.0)
23
23
  yard (0.8.7.6)
24
24
 
25
25
  PLATFORMS
data/README.md CHANGED
@@ -1,102 +1,180 @@
1
- # DaFunk
1
+ # DaFunk, a.k.a. CloudWalk Framework API
2
2
 
3
- Walk Framework API, responsible for managed compatibility between implemented devices, and treat deprecated syntax or behaviour.
3
+ Our goal at [CloudWalk][1] is to provide you with the
4
+ necessary tools to build Point Of Sales (POS) applications
5
+ in an easy and innovative way. To do so, we've developed
6
+ a setup for MRuby programs that allows you to build and
7
+ ship modern day applications to all of your terminals
8
+ instantaneously. For that purpose, you will need to start
9
+ using the API that is provided by this repository.
4
10
 
5
- ## Setup
11
+ ## Index
12
+
13
+ - [Index](#index)
14
+ - [What do I have here?](#what-do-i-have-here)
15
+ - [How do I use this?](#how-do-i-use-this)
16
+ - [Adding support to other platforms](#adding-support-to-other-platforms)
17
+ - [I would like to contribute](#i-would-like-to-contribute)
18
+
19
+ ## What do I have here?
20
+
21
+ This repository contains a set of files and folder that compose the
22
+ **CloudWalk Framework API**. The structure goes as follows:
23
+
24
+ - The `guides` directory, which contains a group of files that are intended to instruct how to use our framework.
25
+ - An `imgs` directory, containing a picture that references the creative origins of this project.
26
+ - A `lib` directory, which holds the main source code of our Framework API.
27
+ - An `out`directory, which has a previous generated binary of this project. All builds target this directory.
28
+ - A `test` directory with example test cases. Tests are divided by _integration_ tests and _unit_ tests.
29
+ - A `utils` folder that contains some scripts which are useful for us to perform tests or interact with the command line environment.
30
+
31
+ ## How do I use this?
32
+
33
+ We strongly recommend using our framework API from our [application skeleton][3],
34
+ it has all the minimal files and the structure needed to build your first application.
6
35
 
7
- 1. Install Ruby 1.9.3 (mruby compatible)
36
+ Essentially add to your `Gemfile`:
8
37
 
9
- 2. Bundle `$ bundle install`
38
+ ```ruby
39
+ gem 'da_funk', :git => 'https://github.com/cloudwalkio/da_funk.git'
40
+ ```
10
41
 
11
- ## Load
42
+ Then require `da_funk` in your application file!
12
43
 
13
- ### All
14
- require 'da_funk'
44
+ ```ruby
45
+ require 'da_funk'
46
+ ```
15
47
 
16
- ### Only ISO8583 module
48
+ For more advanced users only wanting to use the `iso8583` module, here's how you require it:
17
49
 
18
- require 'da_funk/iso8583'
50
+ ```ruby
51
+ require 'da_funk/iso8583'
52
+ ```
19
53
 
20
-
21
- ## Docs (yard)
54
+ A full tutorial on how to develop your first CloudWalk app
55
+ can be found here: <https://docs.cloudwalk.io/en/cli>,
56
+ or checkout this project's source code!
22
57
 
23
- 1. Generate: `$ rake yard`
24
- 2. Open: `open docs/index.html`
58
+ ## Adding support to other platforms
25
59
 
26
- ## How to create Device
60
+ At CloudWalk we develop our framework targeting several POS terminal brands,
61
+ physical devices and even virtual devices (such as our web emulator).
62
+ To deal with the platform differences, we've created an abstraction layer
63
+ in da_funk that helps us modify our framework's behavior for our targets,
64
+ but ensuring the changes needed are minimal and separated from the
65
+ framework's source code. As an example, we offer our project:
66
+ [around_the_world][4], it is the recipe to have MRuby working on
67
+ non embedded platforms and with full compliance with DaFunk API.
27
68
 
28
- ### Steps
69
+ The first step is to add `da_funk` as a submodule in your project, let's say you'll be hosting it on a git server,
70
+ proceed with:
29
71
 
30
- 1. Add da_funk as submodule of your platform project, check the sample [here](https://github.com/cloudwalkio/around_the_world) `$ git submodule add git@github.com:cloudwalkio/da_funk.git <path/to/lib/da_funk>`
72
+ git submodule add git@github.com:cloudwalkio/da_funk.git path/to/lib/da_funk
31
73
 
32
- 2. Develop setup method in platform abstraction.
74
+ Then, in your application, before starting anything, define your
75
+ platform interface. The most important feature it needs to have is
76
+ a `setup` method, which will be called to configure and initialize
77
+ everything before the actual execution.
78
+
79
+ ```ruby
80
+ class PlatformInterface
81
+ def self.setup
82
+ # Configuration and initialization before apps execution
83
+ end
84
+ end
85
+ ```
86
+
87
+ Then you'll need to define your custom classes, but following the structure
88
+ present in our [device][5] source code. These classes can be in the same file
89
+ as the one that has the setup method, here is an example:
90
+
91
+ ```ruby
92
+ class PlatformInterface
93
+ Network = ::Network # Implemented on C
94
+ IO = ::IO # Implemeted on C
95
+
96
+ class Display
97
+ def self.clear
98
+ ::IO.display_clear
99
+ end
100
+
101
+ def self.print_line(buf, row, column)
102
+ # <class created on C or PlatformInterface>._print_line(buf, row, column)
103
+ PlatformInterface._print_line(buf, row, column)
104
+ end
105
+ end
106
+ end
107
+ ```
33
108
 
34
- Setup method will be called in every app execution, should be use to filesystem preparation or any shore needed by the app environment. Check the sample [here](https://github.com/cloudwalkio/mruby-cloudwalk-platform).
109
+ Some important notes regarding your platform interface:
35
110
 
36
- class PlatformInterface
37
- def self.setup
38
- # Configuration and initialization before apps execution
39
- end
40
- end
41
-
42
- 3. Develop interface required by DaFunk on PlatformInterface, could be the same file you have setup method.
111
+ - Be careful with the instance object variable, leave that for DaFunk.
112
+ - Put preference into using class methods instead of making calls as the interface.
113
+ - We might revise this in the future, but for now: any method defined for
114
+ platform-specific usages has to be defined with a name that starts with `_`,
115
+ for example: `_myMethod`.
43
116
 
44
- class PlatformInterface
45
- Network = ::Network # Implemented on C
46
- IO = ::IO # Implemeted on C
117
+ Once you're comfortable with your platform class,
118
+ we need to set it up as the adapter to use by altering DaFunk's device class:
47
119
 
48
- class Display
49
- def self.clear
50
- ::IO.display_clear
51
- end
52
-
53
- def self.print_line(buf, row, column)
54
- # <class created on C or PlatformInterface>._print_line(buf, row, column)
55
- PlatformInterface._print_line(buf, row, column)
56
- end
57
- end
58
- end
120
+ ```ruby
121
+ class Device # Class from DaFunk
122
+ self.adapter = PlatformInterface
123
+ end
124
+ ```
125
+
126
+ The adapter pattern is based is a well studied software design pattern,
127
+ we recommend you to read the [Wiki article][7], it's an interesting bit
128
+ of information that is rooted deep in our solutions.
59
129
 
60
- 4. Configure Adapter
130
+ Finally build it with `rake` or in a more specific manner, with: `mrbc -o platform.mrb </path/to/mrblib/**/*/.rb>`
61
131
 
62
- class Device # Class from DaFunk
63
- self.adapter = PlatformInterface
64
- end
132
+ In [this link][6] there is an example of the whole process. Enjoy the reading! :bowtie:
133
+
134
+ ## I would like to contribute
65
135
 
66
- 5. Compile da_funk into mrb file `$ rake`.
67
- 6. Compile platform abstraction into mrb file `$ mrbc -o platform.mrb </path/to/mrblib/**/*/.rb`
68
- 7. Application file `main.rb`(could be use to test).
69
-
70
- class Main
71
- def self.call
72
- Device::Display.print "Test"
73
- end
74
- end
75
-
76
- Call method should be implemented on applications.
77
-
78
-
79
- ### Adapter pattern
80
- Adapter(platform abstraction) should be configured to access by DaFunk Library
81
-
82
- - [Wiki](http://en.wikipedia.org/wiki/Adapter_pattern)
83
- - Scheme Image (todo)
84
-
85
-
86
- ### Platform Interface
87
-
88
- - Be careful with instance object variable, let't for DaFunk.
89
- - Prefer class methods to call as interface.
90
- - Any method defined on platform language, access by PlatformAbstraction, should defined with _<method name>. # Revise this point
91
-
92
-
93
- ## Contributing
94
-
95
- 1. Fork it
96
- 2. Create your feature branch (`git checkout -b my-new-feature`)
97
- 3. Commit your changes (`git commit -am 'Added some feature'`)
98
- 4. Push to the branch (`git push origin my-new-feature`)
99
- 5. Create new Pull Request
100
-
101
-
102
- ![DaFunk](imgs/daft-punk-da-funk.jpg)
136
+ So, you want to propose changes to our skeleton??!! Thank you sir! We appreciate it :bowtie:
137
+
138
+ Please follow the instructions:
139
+
140
+ 1. Fork it under your github account!
141
+ 2. Create your feature branch `git checkout -b my-new-feature`
142
+ 3. Commit your changes `git commit -am 'Added some feature'`
143
+ 4. Push to the branch `git push origin my-new-feature`
144
+ 5. Create a new Pull Request!
145
+
146
+ ## License
147
+
148
+ ```
149
+ The MIT License (MIT)
150
+
151
+ Copyright (c) 2015 CloudWalk, Inc.
152
+
153
+ Permission is hereby granted, free of charge, to any person obtaining a copy
154
+ of this software and associated documentation files (the "Software"), to deal
155
+ in the Software without restriction, including without limitation the rights
156
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
157
+ copies of the Software, and to permit persons to whom the Software is
158
+ furnished to do so, subject to the following conditions:
159
+
160
+ The above copyright notice and this permission notice shall be included in all
161
+ copies or substantial portions of the Software.
162
+
163
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
164
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
165
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
166
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
167
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
168
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
169
+ SOFTWARE.
170
+ ```
171
+
172
+ [1]: https://www.cloudwalk.io
173
+ [2]: https://www.cloudwalk.io/cli/
174
+ [3]: https://github.com/cloudwalkio/cloudwalk-skeleton
175
+ [4]: https://github.com/cloudwalkio/around_the_world
176
+ [5]: https://github.com/cloudwalkio/da_funk/tree/master/lib/device
177
+ [6]: https://github.com/cloudwalkio/mruby-cloudwalk-platform
178
+ [7]: https://en.wikipedia.org/wiki/Adapter_pattern
179
+
180
+ ![DaFunk](https://raw.githubusercontent.com/cloudwalkio/da_funk/master/imgs/daft-punk-da-funk.jpg)
data/RELEASE_NOTES.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # DaFunk
2
2
 
3
+ ### 0.6.0 - 2016-02-02 - Support to i18n.
4
+ - Add support to i18n.
5
+ - Add I18n messages to ParamsDat/Files/Apps downloading.
6
+ - Add support to ISO8583 file parser.
7
+ - Implemented DaFunk::Helper#try_keys to abstract a helper responsible to wait for range of key only in a period.
8
+ - Implement classes CallbackFlow and ScreenFlow to abstract the development of complex screen flows.
9
+ - Refactoring Device::IO.get_format.
10
+ - Rjust Device::Crypto.crc16_hex return, 4 chars with “0”.
11
+ - Add support to current value on Device::IO.get_format.
12
+ - Send file CRC on file download.
13
+ - Implement String#integer?.
14
+ - Fix number_to_currency to not include label after conversion.
15
+ - Add pagination on Helper.menu.
16
+ - FileDb always work with key and values as string.
17
+ - Fix System Error during Notification Fiber catching all communication exceptions.
18
+ - Update cloudwalk_handshake version to 0.5.1.
19
+ - Update posxml_parser version to 0.7.1.
20
+ - Update readme file.
21
+
3
22
  ### 0.5.4 - 2016-01-08 - Update posxml_parser
4
23
  - Update posxml_parser to version 0.6.1.
5
24
 
data/Rakefile CHANGED
@@ -14,6 +14,11 @@ FILES = FileList[
14
14
  "lib/da_funk.rb",
15
15
  "lib/da_funk/test.rb",
16
16
  "lib/da_funk/screen.rb",
17
+ "lib/da_funk/callback_flow.rb",
18
+ "lib/da_funk/screen_flow.rb",
19
+ "lib/da_funk/i18n_error.rb",
20
+ "lib/da_funk/i18n.rb",
21
+ "lib/da_funk/file_parameter.rb",
17
22
  "lib/device.rb",
18
23
  "lib/device/audio.rb",
19
24
  "lib/device/crypto.rb",
@@ -38,6 +43,7 @@ FILES = FileList[
38
43
  "lib/iso8583/message.rb",
39
44
  "lib/iso8583/util.rb",
40
45
  "lib/iso8583/version.rb",
46
+ "lib/iso8583/file_parser.rb",
41
47
  "lib/device/transaction/iso.rb",
42
48
  "lib/serfx.rb",
43
49
  "lib/serfx/commands.rb",
@@ -0,0 +1,50 @@
1
+ module DaFunk
2
+ class CallbackFlow
3
+ attr_accessor :next
4
+ attr_reader :block, :before, :bind
5
+
6
+ def initialize(bind, callback, &block)
7
+ @bind = bind
8
+ @block = block
9
+ @before = callback
10
+ callback.next = self if callback
11
+ end
12
+
13
+ def dispatch(result)
14
+ return if result.nil?
15
+ Device::Display.clear
16
+ route(check(bind.instance_exec(result, &block)))
17
+ end
18
+
19
+ def check(value)
20
+ unless [true, nil, false].include?(value)
21
+ value = check_keyboard(value)
22
+ end
23
+ value
24
+ end
25
+
26
+ def route(result)
27
+ if result
28
+ if @next
29
+ @next.dispatch(result)
30
+ else
31
+ true
32
+ end
33
+ elsif result.nil?
34
+ else
35
+ @before.dispatch(true)
36
+ end
37
+ end
38
+
39
+ private
40
+ def check_keyboard(value)
41
+ case value
42
+ when Device::IO::CANCEL; return nil
43
+ when Device::IO::BACK; return false
44
+ when Device::IO::ENTER; return true
45
+ end
46
+ true
47
+ end
48
+ end
49
+ end
50
+
@@ -0,0 +1,70 @@
1
+ module DaFunk
2
+ class FileParameter
3
+ FILEPATH = "./shared"
4
+ attr_accessor :crc
5
+ attr_reader :name, :file, :crc_local, :original, :remote
6
+
7
+ def self.delete(collection)
8
+ collection.each do |file_|
9
+ begin
10
+ file_.delete
11
+ rescue RuntimeError
12
+ end
13
+ end
14
+ end
15
+
16
+ def initialize(name, crc)
17
+ @crc = crc
18
+ @original = name
19
+ @remote = @original.sub("#{Device::Setting.company_name}_", "")
20
+ @name = @original.sub("#{Device::Setting.company_name}_", "").split(".").first
21
+ @file = "#{FILEPATH}/#{@remote}"
22
+ @crc_local = @crc if File.exists?(@file)
23
+ end
24
+
25
+ def zip?
26
+ @original.to_s[-4..-1] == ".zip"
27
+ end
28
+
29
+ def exists?
30
+ File.exists? @file
31
+ end
32
+
33
+ def unzip
34
+ if zip? && exists?
35
+ Zip.uncompress(file, FILEPATH, false, false)
36
+ end
37
+ end
38
+
39
+ def download(force = false)
40
+ if force || outdated?
41
+ ret = Device::Transaction::Download.request_file(remote, file, crc_local)
42
+ else
43
+ ret = Device::Transaction::Download::FILE_NOT_CHANGE
44
+ end
45
+ @crc_local = @crc if ret == Device::Transaction::Download::SUCCESS
46
+ ret
47
+ end
48
+
49
+ def delete
50
+ File.delete(self.file) if exists?
51
+ end
52
+
53
+ def outdated?
54
+ return true unless exists?
55
+ unless @crc_local
56
+ handle = File.open(file)
57
+ @crc_local = Device::Crypto.crc16_hex(handle.read)
58
+ end
59
+ @crc_local != @crc
60
+ ensure
61
+ handle.close if handle
62
+ end
63
+
64
+ private
65
+ def remove_company(name)
66
+ name.split("_")[1..-1].join("_")
67
+ end
68
+ end
69
+ end
70
+