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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8d85bc66fbe22cda53c392c416a6432e1c1f6a6853ac09cfb5f2e829b1d11f2
4
- data.tar.gz: bdecc49fdd467bcdd2fea007d129a435965ea67f6e5b87d72c55e23184389fe8
3
+ metadata.gz: 32a0755c03ac3669e78ac0fc76bc9c0651bffba375792dcea1275a14d3b33fec
4
+ data.tar.gz: 2625a3c584c468dd03468a52e15214baacf0f636ddc1c9677a2e3cecaf3ffec3
5
5
  SHA512:
6
- metadata.gz: 8bdfbe7370dbe5a1722275ef7b6e983ff0092aa7c20bf5653f2a78ee3b9b952bc9eed6447dccbcbfe294c00a2d89e5ee83cda525228c48c8554833d9f1e35cd5
7
- data.tar.gz: ce87042d09062ea3b02f64ff09858e63f9c793240efacf3352bdf16aacb8c1b5ce5d16b439d50a8cfd088dc46b4d0c173f126c3e1a2807f0afe705a6bd93a487
6
+ metadata.gz: 60c8651155c6c7657c43f1b6d94aab1c2e4c3bd05f4b5fe630cd08caa328dff2a380c0c58231430ad0ad04179932d28d64e6e1da782a3b66876f138f1b3376e9
7
+ data.tar.gz: a1fe05068eec81fe776482a0f67b332da54194461db09895c2d940adcdbc87e7455361139759a90cf288f86088c8baed658c183a62c8b9a834dc2a11ab649b0b
data/Gemfile CHANGED
@@ -8,3 +8,5 @@ gemspec
8
8
  gem "rake", "~> 13.0"
9
9
 
10
10
  gem "rspec", "~> 3.0"
11
+
12
+ gem 'concurrent-ruby', require: 'concurrent'
data/Gemfile.lock CHANGED
@@ -1,11 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cherrypie-rails-sdk (0.1.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
- # CherrypieRailsSdk
1
+ # CherryPie Rails SDK
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cherrypie_rails_sdk`. To experiment with that code, run `bin/console` for an interactive prompt.
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 'cherrypie_rails_sdk'
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 cherrypie_rails_sdk
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 HelloApp
33
+ module ExampleApp
38
34
  class Application < Rails::Application
39
- # Initialize configuration defaults for originally generated Rails version.
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.
@@ -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
- # spec.add_dependency "example-gem", "~> 1.0"
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
@@ -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
- def initialize(app, api_key, identity_function, api_url: "http://api.cherrypie.app")
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 = response.respond_to?(: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
- request = Net::HTTP::Post.new(
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
- request.body = payload
76
-
77
- response = http.request(request)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CherrypieRailsSdk
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.7"
5
5
  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.3
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 00:00:00.000000000 Z
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