aga-message 0.0.2

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: 4810d922674d6b4e9fed3b5741362cc1641a3153549de9967f2986b871e26fe1
4
+ data.tar.gz: 8dd0ec14a5c72f24dab3cab0b669687eff9bf75d8da98bc7c78e1556246aa279
5
+ SHA512:
6
+ metadata.gz: 273f4b334ac76b789cfdf2ad17075f8d2c8bfbbf62d43e3c0defe0795280ba4fcab58ac02a5741173a7bb86c5f287547a858044f4727a81b46a8260b686061f4
7
+ data.tar.gz: 8c75b961f95cc7e591f2dd0b999d337efc5759f53fd228176a12dcc242d53a1f3b588429ea1db0c96a97ba15e462e1a366487d2f656f69e6f8083d2ed6234f2d
data/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # Aga-message
2
+
3
+ Aga-telegram is a Ruby gem that provides a convenient way to format messages to be sent to customers. It offers a set of utilities and methods to compose and customize messages before sending them to clients through various communication channels.
4
+
5
+ ## Features
6
+
7
+ - Format personalized messages with dynamic content for individual customers.
8
+ - Customize message layout, styling, and formatting.
9
+ - Localization and internationalization support for multilingual messaging.
10
+
11
+ ## Installation
12
+
13
+ Install the gem and add to the application's Gemfile by executing:
14
+
15
+ $ bundle add aga-message
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ $ gem install aga-message
20
+
21
+ ## Usage
22
+
23
+ To use Aga-message in your application, require the gem and start making requests. Here's a basic example:
24
+
25
+ ```
26
+ require 'message'
27
+
28
+ Message.configuration
29
+
30
+ # Output: result
31
+
32
+ [
33
+ {
34
+ :name=>"Bitcoin",
35
+ :symbol=>"BTC",
36
+ :exchanges=> [
37
+ {:exchange=>"Exchange 1", :pair=>"BTC/USDT"},
38
+ {:exchange=>"Exchange 2", :pair=>"BTC/USDT"}
39
+ ],
40
+ :slug=>"bitcoin"
41
+ },
42
+ {
43
+ :name=>"Ethereum",
44
+ :symbol=>"ETH",
45
+ :exchanges=> [
46
+ {:exchange=>"Exchange 1", :pair=>"ETH/USDT"},
47
+ {:exchange=>"Exchange 2", :pair=>"ETH/USDT"}
48
+ ],
49
+ :slug=>"ethereum"
50
+ },
51
+ {
52
+ :name=>"XRP",
53
+ :symbol=>"XRP",
54
+ :exchanges=> [
55
+ {:exchange=>"Exchange 1", :pair=>"XRP/USDT"},
56
+ {:exchange=>"Exchange 2", :pair=>"XRP/USDT"}
57
+ ],
58
+ :slug=>"xrp"
59
+ }
60
+ ]
61
+
62
+
63
+ ```
64
+
65
+ ## Contributing
66
+
67
+ Contributions to Aga-message are welcome! If you encounter any issues or have suggestions for improvements, please submit an issue on the repository. Pull requests are also encouraged.
68
+
69
+
70
+ ## Private License
71
+
72
+ Version 0.0.2, 01/06/2023
73
+
74
+ By obtaining a copy of this software and associated documentation files (the "Software"), you agree that the Software is proprietary to AIGreenAnt and is protected under intellectual property laws. This license grants you limited rights to use the Software solely for internal purposes within your organization.
75
+
76
+ 1. License Grant
77
+
78
+ 1.1 You are granted a non-exclusive, non-transferable license to use the Software for internal purposes only.
79
+
80
+ 1.2 You may not distribute, sublicense, sell, or transfer the Software to any third party without prior written permission from AIGreenAnt.
81
+
82
+ 2. Intellectual Property
83
+
84
+ 2.1 The Software and any associated intellectual property rights, including but not limited to copyrights, patents, trademarks, trade secrets, and any other proprietary rights, are and shall remain the exclusive property of AIGreenAnt.
85
+
86
+ 2.2 You may not remove, alter, or obscure any proprietary notices or labels on the Software.
87
+
88
+ 3. Limitation of Liability
89
+
90
+ 3.1 In no event shall AIGreenAnt be liable for any direct, indirect, incidental, special, or consequential damages arising out of the use or inability to use the Software, even if AIGreenAnt has been advised of the possibility of such damages.
91
+
92
+ 4. Termination
93
+
94
+ 4.1 This license is effective until terminated. AIGreenAnt may terminate this license at any time if you fail to comply with the terms and conditions of this agreement.
95
+
96
+ 4.2 Upon termination, you must immediately cease all use of the Software and destroy all copies in your possession or control.
97
+
98
+ 5. Governing Law
99
+
100
+ 5.1 This license shall be governed by and construed in accordance with the laws of Italy, without regard to its conflict of laws principles.
101
+
102
+ By using the Software, you acknowledge that you have read and understood this license agreement and agree to be bound by its terms and conditions.
@@ -0,0 +1,4 @@
1
+ en:
2
+ movement: MOVEMENT
3
+ crypto: Crypto
4
+ exchanges: Exchanges
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zeitwerk'
4
+
5
+ module Message
6
+ class Autoloader
7
+ class Inflector < ::Zeitwerk::Inflector
8
+ INFLECTIONS_MAP = {
9
+ version: 'VERSION'
10
+ }.freeze
11
+
12
+ def camelize(basename, _abspath)
13
+ INFLECTIONS_MAP[basename.to_sym] || super
14
+ end
15
+ end
16
+
17
+ class << self
18
+ LIB_PATH = ::File.dirname(__dir__).freeze
19
+
20
+ def setup!
21
+ loader = ::Zeitwerk::Loader.new
22
+ loader.tag = 'message'
23
+ loader.inflector = Inflector.new
24
+ loader.push_dir(LIB_PATH)
25
+ loader.collapse(::File.join(LIB_PATH, 'message', 'resources'))
26
+
27
+ ignored_paths.each { |path| loader.ignore(path) }
28
+
29
+ loader.setup
30
+ end
31
+
32
+ private
33
+
34
+ def ignored_paths
35
+ [
36
+ ::File.join(LIB_PATH, 'message', 'patches')
37
+ ].freeze
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Message
4
+ class Base
5
+ class << self
6
+ attr_accessor :app_info
7
+ end
8
+
9
+ self.app_info = ::ENV['APP_INFO'] || "#{::Message::NAME} V#{::Message.version}"
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Message
4
+ class Arbitrage < Common
5
+ private
6
+
7
+ def build_message
8
+ exchanges = @info.exchanges
9
+ message = "\u{1F911}<b>#{I18n.t('movement')} #{last_count}/#{@last_updated}</b> \u{1F911}\n\n" \
10
+ "Crypto: <b>#{@info.slug}</b>\n" \
11
+ "\u{1F6A9}: <b>#{exchange_info(@result.dig(:exchanges, 0))}</b>\n" \
12
+ "\u{1F3C1}: <b>#{exchange_info(@result.dig(:exchanges, 1))}</b>\n" \
13
+ "\u{1F4B8}: <b>#{percentage(exchanges)}</b>\n"
14
+
15
+ @info.html_safe(message)
16
+ end
17
+
18
+ def exchange_info(element)
19
+ return '' if element.nil?
20
+
21
+ element[:exchange] + "(#{@currency.number_to_currency(element[:price])})"
22
+ end
23
+
24
+ def percentage(exchanges)
25
+ return '' if exchanges.nil?
26
+
27
+ percentage = ((exchanges[1][:price] - exchanges.first[:price]) / exchanges.first[:price] * 100).round(2).abs
28
+ @perc.number_to_percentage(percentage)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Message
4
+ class Common
5
+ def initialize(result:, count:)
6
+ @result = result
7
+ @count = count
8
+ @last_updated = Time.now.strftime('%m')
9
+
10
+ @info = Message::Helpers::Info.new(result: @result)
11
+ @perc = Message::Helpers::Percentage.new
12
+ @currency = Message::Helpers::Currency.new
13
+ end
14
+
15
+ def run
16
+ message
17
+ end
18
+
19
+ private
20
+
21
+ def message
22
+ build_message
23
+ end
24
+
25
+ def build_message
26
+ exchanges = @info.exchanges
27
+ message = all_message(exchanges)
28
+
29
+ @info.html_safe(message)
30
+ end
31
+
32
+ def all_message(exchanges)
33
+ message = init_message
34
+ message += "\u{1F510}: <b>#{I18n.t('exchanges')}: </b>\n"
35
+ message += @info.list_exchanges(exchanges).to_s # rubocop: disable Lint/UselessAssignment
36
+ end
37
+
38
+ def init_message
39
+ "\u{1F911}<b>#{I18n.t('movement')} #{last_count}/#{@last_updated}</b> \u{1F911}\n\n" \
40
+ "#{I18n.t('crypto')}: <b>#{@info.slug}</b>\n"
41
+ end
42
+
43
+ def last_count
44
+ @count + 1
45
+ end
46
+
47
+ attr_accessor :last_updated
48
+ end
49
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Message
4
+ module Helpers
5
+ class Currency
6
+ def number_to_currency(number, unit: '$', delimiter: ',', separator: '.')
7
+ integer, decimal = number.to_s.split('.')
8
+ integer.gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
9
+ formatted_number = [integer, decimal].compact.join(separator)
10
+ "#{unit} #{formatted_number}"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Message
4
+ module Helpers
5
+ class Dissipator
6
+ def initialize(result:, service:, count:)
7
+ @result = result
8
+ @service = service
9
+ @count = count
10
+ end
11
+
12
+ def run
13
+ many? ? many_messages : one_message
14
+ end
15
+
16
+ private
17
+
18
+ def many?
19
+ @result.length > 1
20
+ end
21
+
22
+ def one_message
23
+ hash = @result.first
24
+ helper = Object.const_get(service_class).new(result: hash, count: @count)
25
+ message = helper.run
26
+
27
+ formatting(messages: message, count: helper.send(:last_count))
28
+ end
29
+
30
+ def many_messages
31
+ messages = @result.each_slice(10).map do |slice|
32
+ slice.map do |element|
33
+ Object.const_get(service_class).new(result: element, count: @count).run.tap do
34
+ @count += 1
35
+ end
36
+ end.join("\n ========================== \n")
37
+ end
38
+
39
+ formatting(messages: messages, count: @count)
40
+ end
41
+
42
+ def service_class
43
+ "Message::#{@service.to_s.capitalize}"
44
+ end
45
+
46
+ def formatting(messages:, count:)
47
+ { result: messages, count: count }
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Message
4
+ module Helpers
5
+ class Info
6
+ def initialize(result)
7
+ @result = result
8
+ end
9
+
10
+ def exchanges
11
+ @result.dig(:result, :exchanges)
12
+ end
13
+
14
+ def html_safe(string)
15
+ string.dup.force_encoding('UTF-8').encode(html: :safe)
16
+ end
17
+
18
+ def list_exchanges(response)
19
+ response.map { |exchange| "#{exchange[:exchange]} - #{exchange[:pair]}" }.join("\n")
20
+ end
21
+
22
+ def slug
23
+ return '' if @result.dig(:result, :slug).nil?
24
+
25
+ symbol = @result.dig(:result, :symbol)&.upcase
26
+ name = @result.dig(:result, :name)&.capitalize
27
+
28
+ "#{name} (#{symbol})"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Message
4
+ module Helpers
5
+ class Percentage
6
+ def number_to_percentage(number)
7
+ "#{number}%"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Message
4
+ class New < Common
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Message
4
+ class Top < Common
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Message
4
+ VERSION = '0.0.2'
5
+ end
data/lib/message.rb ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tzinfo'
4
+ require 'i18n'
5
+ require_relative './message/autoloader'
6
+
7
+ module Message
8
+ NAME = 'Message Ruby'
9
+
10
+ @mutex = ::Mutex.new
11
+
12
+ class << self
13
+ def app_info=(value)
14
+ ::Message::Base.app_info = value
15
+ end
16
+
17
+ def ping
18
+ { status: 200 }
19
+ end
20
+
21
+ def configuration(locale = :en)
22
+ TZInfo::Timezone.get('Europe/Rome')
23
+
24
+ I18n.load_path += Dir[File.expand_path('./config/locales/*.yml', __dir__)]
25
+ I18n.locale = locale.to_sym
26
+ end
27
+
28
+ def version
29
+ VERSION
30
+ end
31
+ end
32
+ end
33
+
34
+ ::Message::Autoloader.setup!
metadata ADDED
@@ -0,0 +1,225 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aga-message
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Stefano Baldazzi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-06-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: zeitwerk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bump
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: digest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '13.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '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: '0.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.16'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.16'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: i18n
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.14.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.14.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: nokogiri
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.15'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.15'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.14'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.14'
167
+ - !ruby/object:Gem::Dependency
168
+ name: tzinfo
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 2.0.6
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 2.0.6
181
+ description: Message Ruby is a lightweight gem for build message & send via Telegram.
182
+ email:
183
+ - stefanobaldazzi40@gmail.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - README.md
189
+ - lib/config/locales/en.yml
190
+ - lib/message.rb
191
+ - lib/message/autoloader.rb
192
+ - lib/message/base.rb
193
+ - lib/message/resources/arbitrage.rb
194
+ - lib/message/resources/common.rb
195
+ - lib/message/resources/helpers/currency.rb
196
+ - lib/message/resources/helpers/dissipator.rb
197
+ - lib/message/resources/helpers/info.rb
198
+ - lib/message/resources/helpers/percentage.rb
199
+ - lib/message/resources/new.rb
200
+ - lib/message/resources/top.rb
201
+ - lib/message/version.rb
202
+ homepage: https://github.com/Baldaz02/aga-message-ruby
203
+ licenses:
204
+ - MIT
205
+ metadata: {}
206
+ post_install_message:
207
+ rdoc_options: []
208
+ require_paths:
209
+ - lib
210
+ required_ruby_version: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '2.7'
215
+ required_rubygems_version: !ruby/object:Gem::Requirement
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ version: '0'
220
+ requirements: []
221
+ rubygems_version: 3.3.24
222
+ signing_key:
223
+ specification_version: 4
224
+ summary: aga-message0.0.2
225
+ test_files: []