rapidomize 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d55e2f1c1023596d49a6ccf3656f9877618ab992961dd064034e37405979f975
4
- data.tar.gz: a02a484d0b37f9faff87367900235cb0725d4ff043cba5301e85aab9d3ad3879
3
+ metadata.gz: 9db47828c0c3d7dda1003b776cbc49f4e7e8267a1424674104fa6780de46d8eb
4
+ data.tar.gz: 1562b4b32f519cf3f4010e562acf046527f23a3ec824d456ad0008b30f395ee7
5
5
  SHA512:
6
- metadata.gz: 4e9c69f6163e0af65ad4b173ee5bafea6a995c6a7dcab3330142db28cb8e2e8734e6cca78a01433e989945a0748f7ec152ecc6a1feb6fde64f58fbb6cf2c7d21
7
- data.tar.gz: 4b7374609478c9280fcb0b89908e53aeee8bf35cda155baeab53defcd302def9e0b413b881f98544c79ed9f432424e778f2cdfc0881110a496ceb41aeb473c7f
6
+ metadata.gz: 8280554968746de3e3c47d7a71d13f1515eba5dbcd9ff7cff1e33136d30306e1e6fcff20fe43ea7af067966c5baf8d8216e203acba13853d7d16f22781b51c36
7
+ data.tar.gz: 0af85427c62b8cef55584239dba4e866ac35a2d97e14a3dbf9b6770ef7fc74bf7da57b3b758269ae207e075b17faaa9e9ec692ed76a924a54c548a6037a1ff16
@@ -0,0 +1,59 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ main ]
13
+ pull_request:
14
+ branches: [ main ]
15
+
16
+ jobs:
17
+ test:
18
+ runs-on: ubuntu-latest
19
+ strategy:
20
+ matrix:
21
+ ruby-version: ['2.6', '2.7', '3.0']
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+ - name: Set up Ruby
25
+ # uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
26
+ uses: ruby/setup-ruby@v1
27
+ with:
28
+ ruby-version: ${{ matrix.ruby-version }}
29
+ bundler-cache: true
30
+ - name: Run tests
31
+ run: bundle exec rake
32
+ rubocop:
33
+ runs-on: ubuntu-latest
34
+ steps:
35
+ - uses: actions/checkout@v2
36
+ - name: Set up Ruby
37
+ uses: ruby/setup-ruby@v1
38
+ with:
39
+ ruby-version: '3.0'
40
+ bundler-cache: true
41
+ - name: Linting
42
+ run: bundle exec rake rubocop
43
+ build-docs:
44
+ needs: test
45
+ runs-on: ubuntu-latest
46
+ steps:
47
+ - uses: actions/checkout@v2
48
+ - name: Set up Ruby
49
+ uses: ruby/setup-ruby@v1
50
+ with:
51
+ ruby-version: '3.0'
52
+ bundler-cache: true
53
+ - name: Build docs
54
+ run: bundle exec rake yard
55
+ - name: Deploy
56
+ uses: JamesIves/github-pages-deploy-action@4.0.0
57
+ with:
58
+ branch: gh-pages
59
+ folder: doc
data/.gitignore ADDED
@@ -0,0 +1,61 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ # sensitives
36
+ /data/
37
+
38
+ ## Documentation cache and generated files:
39
+ /.yardoc/
40
+ /_yardoc/
41
+ /doc/
42
+ /rdoc/
43
+
44
+ ## Environment normalization:
45
+ /.bundle/
46
+ /vendor/bundle
47
+ /lib/bundler/man/
48
+
49
+ # for a library or gem, you might want to ignore these files since the code is
50
+ # intended to run in multiple environments; otherwise, check them in:
51
+ # Gemfile.lock
52
+ # .ruby-version
53
+ # .ruby-gemset
54
+
55
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
56
+ .rvmrc
57
+
58
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
59
+ # .rubocop-https?--*
60
+
61
+ .idea/
data/.rubocop.yml ADDED
@@ -0,0 +1,9 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
5
+ Metrics/BlockLength:
6
+ IgnoredMethods: ['describe']
7
+
8
+ Metrics/MethodLength:
9
+ Max: 15
data/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [1.0.1] - 2021-03-11
8
+
9
+ ### Fixed
10
+
11
+ - `spec.files` did not track all required files, used `git ls-files` to capture
12
+ the list of files to be included in the gem.
13
+
14
+ ## [1.0.0] - 2021-02-20
15
+
16
+ ### Added
17
+
18
+ - `Payload` class for handling payloads
19
+ - `Message` class to send data to the Rapidomize cloud
20
+ - `BaseTransport` to enforce an interface on transport classes
21
+ - `CommonHTTP` transport for minimal HTTP transmissions
22
+ - SDK specific error classes, under `RapidomizeError`
23
+ - `InvalidPayloadTypeError`
24
+ - `JSON` encoding module
25
+ - `Client` class to simplify message sending process
26
+ - Specs for `Cient`, `Message` and `Payload` classes
27
+ - CHANGELOG.md file
28
+
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in rapidomize.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rapidomize (1.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.7.0)
10
+ public_suffix (>= 2.0.2, < 5.0)
11
+ asciidoctor (2.0.12)
12
+ ast (2.4.2)
13
+ crack (0.4.5)
14
+ rexml
15
+ diff-lcs (1.4.4)
16
+ hashdiff (1.0.1)
17
+ parallel (1.20.1)
18
+ parser (3.0.0.0)
19
+ ast (~> 2.4.1)
20
+ public_suffix (4.0.6)
21
+ rainbow (3.0.0)
22
+ rake (13.0.3)
23
+ regexp_parser (2.0.3)
24
+ rexml (3.2.4)
25
+ rspec (3.10.0)
26
+ rspec-core (~> 3.10.0)
27
+ rspec-expectations (~> 3.10.0)
28
+ rspec-mocks (~> 3.10.0)
29
+ rspec-core (3.10.1)
30
+ rspec-support (~> 3.10.0)
31
+ rspec-expectations (3.10.1)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.10.0)
34
+ rspec-mocks (3.10.2)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.10.0)
37
+ rspec-support (3.10.2)
38
+ rubocop (1.9.1)
39
+ parallel (~> 1.10)
40
+ parser (>= 3.0.0.0)
41
+ rainbow (>= 2.2.2, < 4.0)
42
+ regexp_parser (>= 1.8, < 3.0)
43
+ rexml
44
+ rubocop-ast (>= 1.2.0, < 2.0)
45
+ ruby-progressbar (~> 1.7)
46
+ unicode-display_width (>= 1.4.0, < 3.0)
47
+ rubocop-ast (1.4.1)
48
+ parser (>= 2.7.1.5)
49
+ rubocop-rake (0.5.1)
50
+ rubocop
51
+ rubocop-rspec (2.2.0)
52
+ rubocop (~> 1.0)
53
+ rubocop-ast (>= 1.1.0)
54
+ ruby-progressbar (1.11.0)
55
+ unicode-display_width (2.0.0)
56
+ webmock (3.11.2)
57
+ addressable (>= 2.3.6)
58
+ crack (>= 0.3.2)
59
+ hashdiff (>= 0.4.0, < 2.0.0)
60
+ yard (0.9.26)
61
+
62
+ PLATFORMS
63
+ x86_64-linux
64
+
65
+ DEPENDENCIES
66
+ asciidoctor (~> 2.0)
67
+ rake (~> 13.0)
68
+ rapidomize!
69
+ rspec (~> 3.10)
70
+ rubocop (~> 1.9)
71
+ rubocop-rake (~> 0.5)
72
+ rubocop-rspec (~> 2.2)
73
+ webmock (~> 3.11)
74
+ yard (~> 0.9)
75
+
76
+ BUNDLED WITH
77
+ 2.2.3
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # Rapidomize
2
+
3
+ This is the Ruby version of Rapidomize SDK.
4
+
5
+ ## Getting Started
6
+
7
+ ### Installation
8
+
9
+ You can install Rapidomize from gem tool,
10
+
11
+ ```shell
12
+ gem install rapidomize
13
+ ```
14
+
15
+ or by adding to the Gemfile
16
+
17
+ ```ruby
18
+ gem 'rapidomize'
19
+ ```
20
+
21
+ ### Usage
22
+
23
+ The most basic usage for the SDK would be a sending a JSON payload to the
24
+ Rapidomize cloud using a webhook. This is a simple task with the
25
+ `Rapidomize::Client` class.
26
+
27
+ ```ruby
28
+ require 'rapidomize'
29
+
30
+ # create a transport for HTTP
31
+ http_transport = Rapidomize::Transports::CommonHTTP.new
32
+
33
+ # create a client with the webhook string
34
+ webhook = "https://rapidomize.com/api/webhook/string"
35
+ rpz = Rapidomize::Client.new(webhook, http_transport)
36
+
37
+ # send a simple payload (as a Hash object)
38
+ res = rpz.send({ message: 'This is a test', time: Time.now })
39
+
40
+ # Client#send returns a Net::HTTTPResponse object.
41
+ puts res.code
42
+ ```
43
+
44
+ ## Concepts
45
+
46
+ There are three basic concepts in this SDK.
47
+ 1. Payloads
48
+ 2. Messages
49
+ 3. Transports
50
+
51
+ ### Payloads
52
+
53
+ Payloads are the data being sent to the cloud. Payloads can
54
+ be serialized to and deserialize from various data formats.
55
+
56
+ > **SDK v1.0**: only supported (de)serialization format is JSON.
57
+
58
+ A payload object has two structures, depending on the type of
59
+ data it holds. And one payload has only one structure.
60
+
61
+ #### Hash-like Payloads
62
+
63
+ This type of payloads are essentially hash objects. This is the
64
+ most basic structure for a payload. They hold data as
65
+ key-value pairs, just like in a ruby hash.
66
+
67
+ Example:
68
+ ```ruby
69
+ # keys can be any type, with a to_s method
70
+ payload[:id] = 'value'
71
+ # all keys are converted to strings internally
72
+ puts payload['id'] # => value
73
+ ```
74
+
75
+ A payload is Hash-like if,
76
+ 1. created from a hash (`Rapidomize::Payload.new.from_hash`)
77
+ 2. created from a JSON string containing a JSON object
78
+ 3. `#[]` operator is used (possibly before `#<<` operator)
79
+
80
+ #### Enum-like payloads
81
+
82
+ Sometimes it may be required to send multiple payloads in a
83
+ single message. But messages accepts only one payload object.
84
+ In these situations, we can use enum-like structure of the
85
+ Payload. `<<` operator can insert a Payload object into
86
+ another Payload.
87
+
88
+ ```ruby
89
+ payload_collection = Rapidomize::Payload.new
90
+
91
+ # to be inserted in to collection
92
+ payload_1 = Rapidomize::Payload.new.from_hash({ id: 1 })
93
+
94
+ # insert a single payload
95
+ payload_collection << payload_1
96
+
97
+ payload_2 = Rapidomize::Payload.new.from_hash({ id: 2 })
98
+ payload_3 = Rapidomize::Payload.new.from_hash({ id: 3 })
99
+
100
+ # << can take arrays of payload
101
+ payload_collection << [payload_2, payload_3]
102
+ # each payload in the array is inserted to the collection
103
+ # separately, so payload_collection is similar to
104
+ # [{id: 1}, {id: 2}, {id: 3}]
105
+ ```
106
+
107
+ A payload is Enum-like, if
108
+ 1. created from a JSON string containing a JSON array
109
+ 2. `#<<` operator is used (possibly before `#[]` operator)
110
+
111
+ Enum-like payloads are `Enumerable`
112
+
113
+ ### Messages
114
+
115
+ A message is like an envelop to send a payload. It has a
116
+ destination URI, an application id and a token to be used
117
+ when sending the payload on a transport.
118
+
119
+ A message must have a destination URI. Application id and
120
+ token are optional.
121
+
122
+ ### Transports
123
+
124
+ Transports are how the data is transmitted to the cloud.
125
+ HTTP, MQTT, WebSockets are the example modes for transports.
126
+
127
+ Each transport class will implement the necessary mechanism
128
+ to send (and receive, if needed) the data to the cloud.
129
+
130
+
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ require 'yard'
13
+
14
+ YARD::Rake::YardocTask.new do |t|
15
+ t.options = %w[--markup asciidoc --no-private]
16
+ end
17
+
18
+ task default: %i[spec]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'rapidomize'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ 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
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rapidomize
4
+ # A client object is a simplification of the message sending
5
+ # process. It merely abstract the Message creation process by
6
+ # automatically creating messages and assign payloads and URIs
7
+ # to them. A transport method is still needed for the delivery
8
+ # process.
9
+ class Client
10
+ attr_accessor :uri, :transport, :app_id, :token
11
+
12
+ # Create a new client with a URI and a transport method. These
13
+ # parameters will be used with every payload sent through this
14
+ # client.
15
+ # @param uri [String] URI for all payloads sent through this client.
16
+ # @param transport [Rapidomize::Transports::BaseTransport] mode of transport.
17
+ # Must be a subclass of BaseTransport
18
+ # @param app_id [String] _(optional)_ Application id for the messages.
19
+ # @param token [String] _(optional)_ Token for message authorization.
20
+ def initialize(uri, transport, app_id = nil, token = nil)
21
+ @uri = URI(uri)
22
+ @transport = transport
23
+ @app_id = app_id
24
+ @token = token
25
+ end
26
+
27
+ # Send the payload
28
+ # @param payload [Hash, String, Payload] payload data to send
29
+ # @return [Net::HTTPResponse] return the response object
30
+ def send(payload)
31
+ pl = Payload.create(payload)
32
+ msg = Message.new(@uri, pl)
33
+ msg.app_id = @app_id unless @app_id.nil?
34
+ msg.token = @token unless @token.nil?
35
+
36
+ @transport.deliver(msg)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rapidomize
4
+ module Encoding
5
+ # Encode payload to JSON and build payload from JSON
6
+ module Json
7
+ # Encode the payload object in JSON
8
+ # @param args same as Ruby JSON.generate
9
+ # @return [String] a JSON string
10
+ def to_json(*args)
11
+ data.to_json(*args)
12
+ end
13
+
14
+ # Add to Payload from a JSON string
15
+ # @example From a json array, build an enum-like payload
16
+ # json_string = " '[{"data":1},{"data": 2}]'
17
+ # payload = Rapidomize::Payload.new.from_json(json_string)
18
+ # This can also be used to add data from JSON strings
19
+ # @param str [String] A valid JSON string
20
+ # @return self
21
+ def from_json(str)
22
+ json = JSON.parse(str)
23
+ if json.is_a? Array
24
+ json.each do |j|
25
+ self << Rapidomize::Payload.new.from_hash(j)
26
+ end
27
+ else
28
+ from_hash(json)
29
+ end
30
+ self
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rapidomize
4
+ # Invalid payload type
5
+ class InvalidPayloadTypeError < RapidomizeError
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rapidomize
4
+ # Generic Error for Rapidomize SDK methods
5
+ class RapidomizeError < StandardError
6
+ end
7
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rapidomize
4
+ # Message objects are at the core of SDK.
5
+ # Each message is an independent entity with following information
6
+ #
7
+ # uri:: A message must have a URI, which is the destination of the message.
8
+ # payload:: _(optional)_ A message may contain a Payload to transmit data
9
+ # token:: _(optional)_ token for authorization purposes
10
+ # app_id:: _(optional)_ app_id of the receiving ICAPP
11
+ class Message
12
+ attr_reader :uri, :payload, :app_id, :token
13
+
14
+ # Initialize a message object
15
+ # @param uri [URI, String] Destination of the message.
16
+ # @param payload [Hash, String, Rapidomize::Payload] Payload to transmit.
17
+ # @param token [String] Authorization token
18
+ # @param app_id [String] Receiving app id
19
+ def initialize(uri, payload = nil, token = nil, app_id = nil)
20
+ raise ArgumentError, 'uri is nil' if uri.nil?
21
+
22
+ @payload = Payload.create(payload)
23
+ @uri = sanitize_uri(uri)
24
+ @app_id = app_id
25
+ @token = token
26
+ end
27
+
28
+ private
29
+
30
+ # sanitize URIs.
31
+ # TODO: make sure the given URI is a valid rapidomize URL
32
+ def sanitize_uri(uri)
33
+ if uri.is_a? String
34
+ URI(uri)
35
+ else
36
+ uri
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rapidomize
4
+ # Payload objects are used to manage the payloads exchanged between
5
+ # Rapidomize Cloud and SDK. Payload objects can encode or decode their
6
+ # state to or from custom formats. (JSON, msgpack, ...).
7
+ #
8
+ # There are two kinds of payload objects:
9
+ #
10
+ # *Hash-like* payloads collects payload information in key-value pairs.
11
+ #
12
+ # *Enum-like* payloads collects information as an array of Hash-like payloads.
13
+ # Useful when sending multiple payloads in one request. This type of payloads
14
+ # are immutable.
15
+ class Payload
16
+ include Enumerable
17
+
18
+ private
19
+
20
+ # Get the internal hash object.
21
+ def hashmap
22
+ raise InvalidPayloadTypeError, 'Cannot use Enum-like payload as Hash-like' unless @type == :hash || @type.nil?
23
+
24
+ @type = :hash
25
+ @hashmap ||= {}
26
+ end
27
+
28
+ # Get the internal array object
29
+ def collection
30
+ raise InvalidPayloadTypeError, 'Cannot use Hash-like payload as Enum-like' unless @type == :enum || @type.nil?
31
+
32
+ @type = :enum
33
+ @collection ||= []
34
+ end
35
+
36
+ public
37
+
38
+ # Factory method create payloads from other data types. This method
39
+ # will return corresponding Payload objects for Hashes, JSON strings.
40
+ # If the given object is already a Payload, it will be copied.
41
+ # It returns an empty Payload when obj is nil
42
+ # @param [Hash, String, Payload, nil] obj A hash, possible JSON string or a Payload object
43
+ # @return a Payload object
44
+ # @raise ArgumentError if obj is not a Hash, String, Payload or nil
45
+ def self.create(obj)
46
+ return Payload.new if obj.nil?
47
+
48
+ case obj
49
+ when Hash
50
+ # noinspection RubyYardParamTypeMatch
51
+ Payload.new.from_hash(obj)
52
+ when String
53
+ # noinspection RubyYardParamTypeMatch
54
+ Payload.new.from_json(obj)
55
+ when Payload
56
+ obj.clone
57
+ else
58
+ raise ArgumentError, "Expected Hash, String or Payload; Given: #{obj.class}"
59
+ end
60
+ end
61
+
62
+ # Get a value from the payload
63
+ # @param key A key to search in the payload
64
+ # @return the value associated with payload key, nil if key is not in payload
65
+ def [](key)
66
+ hashmap[key.to_s]
67
+ end
68
+
69
+ # Set a value in the payload
70
+ # @param key A key to search in the payload
71
+ # @param value to be set for the key
72
+ # @return the value
73
+ def []=(key, value)
74
+ hashmap[key.to_s] = value
75
+ end
76
+
77
+ # Check if the key exists in the payload
78
+ # @param key The key to search in the payload
79
+ # @return true if payload includes `key`
80
+ def has?(key)
81
+ hashmap.include? key.to_s
82
+ end
83
+
84
+ # Set values from a hash object
85
+ # @param hash [Hash] Hash to include data from
86
+ def from_hash(hash)
87
+ hashmap.merge!(hash.transform_keys(&:to_s))
88
+ self
89
+ end
90
+
91
+ # Add a payload to the collection
92
+ # @param payload [Payload] A payload to add
93
+ # @return [Payload] added payload
94
+ def <<(payload)
95
+ if payload.is_a? Array
96
+ payload.each do |elem|
97
+ raise InvalidPayloadTypeError, "Expected: Payload, Given: #{payload.class}" unless elem.is_a? Payload
98
+
99
+ collection << elem
100
+ end
101
+ else
102
+ raise InvalidPayloadTypeError, "Expected: Payload, Given: #{payload.class}" unless payload.is_a? Payload
103
+
104
+ collection << payload
105
+ end
106
+ payload
107
+ end
108
+
109
+ # Return the size of the payload collection
110
+ # @return the size of the payload collection
111
+ def size
112
+ data.size
113
+ end
114
+
115
+ # Each method for enumerable features
116
+ def each(&block)
117
+ if @type == :enum
118
+ collection.each { |payload| block.call(payload) }
119
+ else
120
+ hashmap.each { |key, value| block.call(key, value) }
121
+ end
122
+ end
123
+
124
+ def data
125
+ if @type == :enum
126
+ collection.clone
127
+ else
128
+ hashmap.clone
129
+ end
130
+ end
131
+
132
+ include Encoding::Json
133
+ end
134
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rapidomize
4
+ module Transports
5
+ # Interface for Transport classes to implement
6
+ class BaseTransport
7
+ # Method to invoke to send a message to the URI of the message
8
+ # @param _message [Message] a message object with a URI, *IGNORED* on BaseTransport
9
+ # @raise NotImplementedError on BaseTransport objects
10
+ def deliver(_message)
11
+ raise NotImplementedError
12
+ end
13
+
14
+ # Method to invoke when a message is received from the cloud
15
+ # @raise NotImplementedError on BaseTransport objects
16
+ def receive
17
+ raise NotImplementedError
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rapidomize
4
+ module Transports
5
+ # CommonHTTP transport is used to send payloads via HTTP protocol
6
+ # It is called common http, since it does not maintain a persistent
7
+ # connection with a server.
8
+ # For CommonHTTP to send data, messages must provide a valid URI
9
+ # of the HTTP endpoint.
10
+ class CommonHTTP < BaseTransport
11
+ # Deliver a message to the URI of the message
12
+ # @param message [Message] a message object with a URI
13
+ # @return [Net::HTTPResponse] Response object for the deliver
14
+ def deliver(message)
15
+ # TODO: Add support for other HTTP verbs too. (i.e PUT, GET, UPDATE)
16
+ Net::HTTP.post message.uri,
17
+ message.payload.to_json,
18
+ { 'Content-Type' => 'application/json' }
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rapidomize
4
+ VERSION = '1.0.1'
5
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/rapidomize/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'rapidomize'
7
+ spec.version = Rapidomize::VERSION
8
+ spec.authors = ['Nisal Bandara']
9
+ spec.email = ['nisal.bandara@outlook.com']
10
+ spec.licenses = ['Apache-2.0']
11
+
12
+ spec.summary = 'Rapidomize Ruby SDK'
13
+ spec.description = 'Connect to Rapidomize cloud with Ruby'
14
+ spec.homepage = 'https://rapidomize.github.io/rapidomize-ruby-sdk'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
16
+
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/rapidomize/rapidomize-ruby-sdk'
21
+ spec.metadata['changelog_uri'] = 'https://github.com/rapidomize/rapidomize-ruby-sdk/blob/main/CHANGELOG.md'
22
+
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'asciidoctor', '~> 2.0'
31
+ spec.add_development_dependency 'rake', '~> 13.0'
32
+ spec.add_development_dependency 'rspec', '~> 3.10'
33
+ spec.add_development_dependency 'rubocop', '~> 1.9'
34
+ spec.add_development_dependency 'rubocop-rake', '~> 0.5'
35
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.2'
36
+ spec.add_development_dependency 'webmock', '~> 3.11'
37
+ spec.add_development_dependency 'yard', '~> 0.9'
38
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapidomize
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nisal Bandara
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-20 00:00:00.000000000 Z
11
+ date: 2021-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -129,15 +129,36 @@ executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
+ - ".github/workflows/ruby.yml"
133
+ - ".gitignore"
134
+ - ".rubocop.yml"
135
+ - CHANGELOG.md
136
+ - Gemfile
137
+ - Gemfile.lock
138
+ - LICENSE
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/setup
132
143
  - lib/rapidomize.rb
133
- homepage: https://github.com/rapidomize/rapidomize-ruby-sdk
144
+ - lib/rapidomize/client.rb
145
+ - lib/rapidomize/encoding/json.rb
146
+ - lib/rapidomize/error/invalid_payload_type_error.rb
147
+ - lib/rapidomize/error/rapidomize_error.rb
148
+ - lib/rapidomize/message.rb
149
+ - lib/rapidomize/payload.rb
150
+ - lib/rapidomize/transport/base_transport.rb
151
+ - lib/rapidomize/transport/http_transport.rb
152
+ - lib/rapidomize/version.rb
153
+ - rapidomize.gemspec
154
+ homepage: https://rapidomize.github.io/rapidomize-ruby-sdk
134
155
  licenses:
135
156
  - Apache-2.0
136
157
  metadata:
137
158
  allowed_push_host: https://rubygems.org
138
- homepage_uri: https://github.com/rapidomize/rapidomize-ruby-sdk
159
+ homepage_uri: https://rapidomize.github.io/rapidomize-ruby-sdk
139
160
  source_code_uri: https://github.com/rapidomize/rapidomize-ruby-sdk
140
- changelog_uri: https://github.com/rapidomize/rapidomize-ruby-sdk/CHANGELOG.md
161
+ changelog_uri: https://github.com/rapidomize/rapidomize-ruby-sdk/blob/main/CHANGELOG.md
141
162
  post_install_message:
142
163
  rdoc_options: []
143
164
  require_paths:
@@ -153,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
174
  - !ruby/object:Gem::Version
154
175
  version: '0'
155
176
  requirements: []
156
- rubygems_version: 3.2.3
177
+ rubygems_version: 3.1.2
157
178
  signing_key:
158
179
  specification_version: 4
159
180
  summary: Rapidomize Ruby SDK