cherrypie-rails-sdk 0.2.3 → 0.2.7
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 +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +4 -1
- data/README.md +6 -30
- data/cherrypie_rails_sdk.gemspec +1 -1
- data/lib/cherrypie_rails_sdk.rb +21 -8
- data/lib/cherrypie_rails_sdk/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32a0755c03ac3669e78ac0fc76bc9c0651bffba375792dcea1275a14d3b33fec
|
4
|
+
data.tar.gz: 2625a3c584c468dd03468a52e15214baacf0f636ddc1c9677a2e3cecaf3ffec3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60c8651155c6c7657c43f1b6d94aab1c2e4c3bd05f4b5fe630cd08caa328dff2a380c0c58231430ad0ad04179932d28d64e6e1da782a3b66876f138f1b3376e9
|
7
|
+
data.tar.gz: a1fe05068eec81fe776482a0f67b332da54194461db09895c2d940adcdbc87e7455361139759a90cf288f86088c8baed658c183a62c8b9a834dc2a11ab649b0b
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cherrypie-rails-sdk (0.
|
4
|
+
cherrypie-rails-sdk (0.2.6)
|
5
|
+
concurrent-ruby
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
8
9
|
specs:
|
10
|
+
concurrent-ruby (1.1.9)
|
9
11
|
diff-lcs (1.4.4)
|
10
12
|
rake (13.0.6)
|
11
13
|
rspec (3.10.0)
|
@@ -27,6 +29,7 @@ PLATFORMS
|
|
27
29
|
|
28
30
|
DEPENDENCIES
|
29
31
|
cherrypie-rails-sdk!
|
32
|
+
concurrent-ruby
|
30
33
|
rake (~> 13.0)
|
31
34
|
rspec (~> 3.0)
|
32
35
|
|
data/README.md
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# CherryPie Rails SDK
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Cherrypie Rails SDK.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
7
|
Add this line to your application's Gemfile:
|
10
8
|
|
11
9
|
```ruby
|
12
|
-
gem '
|
10
|
+
gem 'cherrypie-rails-sdk', '~> 0.2.6'
|
13
11
|
```
|
14
12
|
|
15
13
|
And then execute:
|
@@ -18,7 +16,7 @@ And then execute:
|
|
18
16
|
|
19
17
|
Or install it yourself as:
|
20
18
|
|
21
|
-
$ gem install
|
19
|
+
$ gem install cherrypie-rails-sdk
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
@@ -30,23 +28,11 @@ require_relative "boot"
|
|
30
28
|
require "rails/all"
|
31
29
|
require 'cherrypie_rails_sdk'
|
32
30
|
|
33
|
-
# Require the gems listed in Gemfile, including any gems
|
34
|
-
# you've limited to :test, :development, or :production.
|
35
31
|
Bundler.require(*Rails.groups)
|
36
32
|
|
37
|
-
module
|
33
|
+
module ExampleApp
|
38
34
|
class Application < Rails::Application
|
39
|
-
|
40
|
-
config.load_defaults 6.1
|
41
|
-
|
42
|
-
# Configuration for the application, engines, and railties goes here.
|
43
|
-
#
|
44
|
-
# These settings can be overridden in specific environments using the files
|
45
|
-
# in config/environments, which are processed later.
|
46
|
-
#
|
47
|
-
# config.time_zone = "Central Time (US & Canada)"
|
48
|
-
# config.eager_load_paths << Rails.root.join("extras")
|
49
|
-
|
35
|
+
...
|
50
36
|
config.middleware.use(CherrypieRailsSdk::Middleware, "<TOKEN>",
|
51
37
|
lambda{ |request| {
|
52
38
|
# request: ActionDispatch::Request
|
@@ -56,13 +42,3 @@ module HelloApp
|
|
56
42
|
end
|
57
43
|
end
|
58
44
|
```
|
59
|
-
|
60
|
-
## Development
|
61
|
-
|
62
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
63
|
-
|
64
|
-
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
65
|
-
|
66
|
-
## Contributing
|
67
|
-
|
68
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cherrypie_rails_sdk.
|
data/cherrypie_rails_sdk.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
30
|
# Uncomment to register a new dependency of your gem
|
31
|
-
|
31
|
+
spec.add_dependency "concurrent-ruby"
|
32
32
|
|
33
33
|
# For more information and examples about making a new gem, checkout our
|
34
34
|
# guide at: https://bundler.io/guides/creating_gem.html
|
data/lib/cherrypie_rails_sdk.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "cherrypie_rails_sdk/version"
|
4
|
+
require 'concurrent'
|
4
5
|
|
5
6
|
module CherrypieRailsSdk
|
6
7
|
class Error < StandardError; end
|
7
8
|
class Middleware
|
8
|
-
|
9
|
+
include Concurrent::Async
|
10
|
+
|
11
|
+
def initialize(app, api_key, identity_function, api_url: "https://api.cherrypie.app")
|
12
|
+
super()
|
9
13
|
@app = app
|
10
14
|
@api_key = api_key
|
11
15
|
@api_url = api_url
|
@@ -30,14 +34,21 @@ module CherrypieRailsSdk
|
|
30
34
|
end
|
31
35
|
|
32
36
|
def _build_response_payload(status, headers, response)
|
33
|
-
body =
|
37
|
+
body = nil
|
38
|
+
if response.respond_to?(:body)
|
39
|
+
body = response.body
|
40
|
+
end
|
34
41
|
return {
|
35
42
|
"headers"=> headers,
|
36
43
|
"body"=> body,
|
37
44
|
"statusCode"=> status,
|
38
45
|
}
|
39
46
|
end
|
40
|
-
|
47
|
+
|
48
|
+
def _send_log(http, request)
|
49
|
+
http.request(request)
|
50
|
+
end
|
51
|
+
|
41
52
|
def _call env
|
42
53
|
request_started_on = Time.now
|
43
54
|
@status, @headers, @response = @app.call(env)
|
@@ -64,7 +75,8 @@ module CherrypieRailsSdk
|
|
64
75
|
|
65
76
|
uri = URI("#{@api_url}/v1/logs")
|
66
77
|
http = Net::HTTP.new(uri.host, uri.port)
|
67
|
-
|
78
|
+
http.use_ssl = true
|
79
|
+
cherrypie_request = Net::HTTP::Post.new(
|
68
80
|
uri.request_uri,
|
69
81
|
{
|
70
82
|
'Content-Type' => 'application/json',
|
@@ -72,10 +84,11 @@ module CherrypieRailsSdk
|
|
72
84
|
'Accept'=>'application/json',
|
73
85
|
}
|
74
86
|
)
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
87
|
+
cherrypie_request.body = payload
|
88
|
+
# Only log non-300 statuses.
|
89
|
+
if !(@status >= 300 && @status <= 399)
|
90
|
+
cherrypie_response = self.async._send_log(http, cherrypie_request)
|
91
|
+
end
|
79
92
|
[@status, @headers, @response]
|
80
93
|
end
|
81
94
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cherrypie-rails-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Macro Computer Club
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
12
|
-
dependencies:
|
11
|
+
date: 2021-08-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: concurrent-ruby
|
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'
|
13
27
|
description: CherryPie Rails SDK
|
14
28
|
email:
|
15
29
|
- founders@cherrypie.app
|