pushkin-logger 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2bf5e72152d65f3424c4d6451e6c3430e7b37faf439b9775c521dbaede7d061e
4
+ data.tar.gz: 2ba9fe9d1715d526391db320905a69a705db3b417e661e7f41193a39d303127a
5
+ SHA512:
6
+ metadata.gz: 23f294013d8257e7e5339b05715f17f19c8e488a660d5c4476e82b0404e61ab60b1d94c349ec53f56541d3a07662c3f25a5d1753e307da78fb2b4d1cb57e35b4
7
+ data.tar.gz: 55fbe84038b2c5483499d6112c5f1126ed732d5ffa3adc25a147a01e2ca571fc19a8e8de4605474f7d285520da278960663694e889e85379a85fd60b3bf4862c
data/.standard.yml ADDED
@@ -0,0 +1,2 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-06-30
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in pushkin-logger.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "standard", "~> 1.3"
13
+ gem "pry"
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pushkin-logger (0.1.0)
5
+ httparty (~> 0.20.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ coderay (1.1.3)
12
+ httparty (0.20.0)
13
+ mime-types (~> 3.0)
14
+ multi_xml (>= 0.5.2)
15
+ method_source (1.0.0)
16
+ mime-types (3.4.1)
17
+ mime-types-data (~> 3.2015)
18
+ mime-types-data (3.2022.0105)
19
+ minitest (5.16.1)
20
+ multi_xml (0.6.0)
21
+ parallel (1.22.1)
22
+ parser (3.1.2.0)
23
+ ast (~> 2.4.1)
24
+ pry (0.14.1)
25
+ coderay (~> 1.1)
26
+ method_source (~> 1.0)
27
+ rainbow (3.1.1)
28
+ rake (13.0.6)
29
+ regexp_parser (2.5.0)
30
+ rexml (3.2.5)
31
+ rubocop (1.29.1)
32
+ parallel (~> 1.10)
33
+ parser (>= 3.1.0.0)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ regexp_parser (>= 1.8, < 3.0)
36
+ rexml (>= 3.2.5, < 4.0)
37
+ rubocop-ast (>= 1.17.0, < 2.0)
38
+ ruby-progressbar (~> 1.7)
39
+ unicode-display_width (>= 1.4.0, < 3.0)
40
+ rubocop-ast (1.18.0)
41
+ parser (>= 3.1.1.0)
42
+ rubocop-performance (1.13.3)
43
+ rubocop (>= 1.7.0, < 2.0)
44
+ rubocop-ast (>= 0.4.0)
45
+ ruby-progressbar (1.11.0)
46
+ standard (1.12.1)
47
+ rubocop (= 1.29.1)
48
+ rubocop-performance (= 1.13.3)
49
+ unicode-display_width (2.2.0)
50
+
51
+ PLATFORMS
52
+ arm64-darwin-20
53
+ x86_64-darwin-20
54
+
55
+ DEPENDENCIES
56
+ minitest (~> 5.0)
57
+ pry
58
+ pushkin-logger!
59
+ rake (~> 13.0)
60
+ standard (~> 1.3)
61
+
62
+ BUNDLED WITH
63
+ 2.2.32
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # Pushkin
2
+
3
+ Pushkin is a simple http client for sending various user/system events to Pushkin API endpoint. It's used primarily for logging events in ticketing services.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pushkin-logger'
11
+ ```
12
+
13
+ And then execute:
14
+ ```bash
15
+ $ bundle install
16
+ ```
17
+
18
+ ## Basic Usage
19
+ ```ruby
20
+ client = Pushkin::Client.new(
21
+ ENV['PUSHKIN_API_URL'],
22
+ ENV['PUSHKIN_API_TOKEN']
23
+ )
24
+
25
+ data = {
26
+ log_level: 'info', # optional ['info', 'warn', 'error'], default: 'system'
27
+ action: 'my.action',
28
+ properties: { foo: 'bar' }
29
+ }
30
+
31
+ client.push(data)
32
+ ```
33
+ ## Advanced
34
+ Predefined actions to track orders and tickets sold:
35
+ ```ruby
36
+ order.intent
37
+ coupon.create
38
+ coupon.activate
39
+ ticket.order
40
+ ticket.create
41
+ ticket.preregister
42
+ ticket.upload
43
+ ticket.download
44
+ payment.received
45
+ ```
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitLab at https://gitlab.vesputi.com/mobilitybox/pushkin-gem.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ require "standard/rake"
13
+
14
+ task default: %i[test standard]
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 "pushkin"
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,42 @@
1
+ require "httparty"
2
+ module Pushkin
3
+ class Client
4
+ include HTTParty
5
+
6
+ def initialize(api_url, api_token)
7
+ @options = {
8
+ headers: {
9
+ "Authorization" => "Bearer #{api_token}",
10
+ "Accept-Language" => "en",
11
+ "Accept" => "application/json",
12
+ "Content-Type" => "application/json",
13
+ "User-Agent" => "Pushkin v#{Pushkin::VERSION}",
14
+ "Client-Language" => "ruby",
15
+ "Client-Language-Version" => "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})",
16
+ "Client-Platform" => RUBY_PLATFORM,
17
+ "Client-Engine" => defined?(RUBY_ENGINE) ? RUBY_ENGINE : "",
18
+ "Client-Hostname" => Socket.gethostname,
19
+ "Client-Pid" => Process.pid.to_s,
20
+ "Client-Thread" => Thread.current.object_id.to_s
21
+ }
22
+ }
23
+ @api_url = api_url
24
+ end
25
+
26
+ def push(data)
27
+ body = prepare_data(data)
28
+ @options = @options.merge(body: body)
29
+
30
+ self.class.post("#{@api_url}/api/events/", @options)
31
+ end
32
+
33
+ private
34
+
35
+ def prepare_data(data)
36
+ data.merge(
37
+ pushed_at: DateTime.current,
38
+ service_identifier: Rails.application.class.module_parent_name
39
+ ).to_json
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pushkin
4
+ VERSION = "0.1.0"
5
+ end
data/lib/pushkin.rb ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "pushkin/version"
4
+ require_relative "pushkin/client"
5
+
6
+ module Pushkin
7
+ class Error < StandardError; end
8
+
9
+ LOG_PREFIX = "[pushkin]"
10
+
11
+ def self.logger
12
+ return @logger if @logger
13
+
14
+ @logger = if defined?(Rails)
15
+ Rails.logger
16
+ else
17
+ Logger.new($stdout)
18
+ end
19
+ end
20
+
21
+ def self.logger=(new_logger)
22
+ @logger = new_logger
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pushkin-logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mobilitybox Dev Team
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.20.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.20.0
27
+ description:
28
+ email:
29
+ - dev-op@vesputi.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".standard.yml"
35
+ - CHANGELOG.md
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - README.md
39
+ - Rakefile
40
+ - bin/console
41
+ - bin/setup
42
+ - lib/pushkin.rb
43
+ - lib/pushkin/client.rb
44
+ - lib/pushkin/version.rb
45
+ homepage: https://themobilitybox.com
46
+ licenses:
47
+ - MIT
48
+ metadata:
49
+ homepage_uri: https://themobilitybox.com
50
+ source_code_uri: https://gitlab.vesputi.com/mobilitybox/pushkin
51
+ changelog_uri: https://gitlab.vesputi.com/mobilitybox/pushkin/CHANGELOG.md
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.6.0
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.1.6
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: A http client for shipping events to Pushkin Service.
71
+ test_files: []