compensated 0.1.0.pre4 → 0.1.0.pre5

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: ac2ec14d09df8e16e45e2d6dbbdd0568eea83ad4e19c386f2b2b4a413093c893
4
- data.tar.gz: a09cbd7eb77b776ab13aa363674554ebbbb59281096bb782ad89469b75d296ce
3
+ metadata.gz: fd4ea31bad4284f0d06de15e35b591e22d67b7cc50a1571ef7625d5ef21861b2
4
+ data.tar.gz: 17fc45a9d3a5f69148b4ace3f93ad9617bdafb5b77be9ac19465f102b071eee0
5
5
  SHA512:
6
- metadata.gz: db258bc5034fed17c0e0e0983898c77b8eabc8f81cd049247ee99998abaddb3b6a9cbfde2bbdb548a35621ad493cea26b38d0c9cffb1f1d23409c0df1dd614a7
7
- data.tar.gz: 0b88d6ff66324262a2b912ad1e9382d4e5184acdf111ece2c353fd801ca7fce9bdd73cb7db52f39d25dd3bb719a6af2fb6df3e1b4154580ebb345059579aed86
6
+ metadata.gz: a72e5586b802db61e8ba14af7f26e04381bbc1ab40fcc597ec496efc5420173f37e2a34af549732a4b081a451fe3f3527d0d5488fcf918c9f3d91198f69bc3b9
7
+ data.tar.gz: 31cfcdb556cbb130c131b6981231f650a4214d5bbceb7bed3f9dc0160a7838c6dc8257b512d07bcf1f0c8c9541919ae0b8eb75bbc7f28e177a7a8c00f3332f73
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- compensated (0.1.0.pre4)
4
+ compensated (0.1.0.pre5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,3 +1,4 @@
1
+ require "webrick"
1
2
  module Compensated
2
3
  module Gumroad
3
4
  class EventParser
@@ -8,29 +9,41 @@ module Compensated
8
9
  keys.include?(:seller_id) && keys.include?(:product_id) && keys.include?(:product_permalink) && request.data["product_permalink"].include?("gum.co")
9
10
  end
10
11
 
11
- def parse(request)
12
- if request.body.respond_to?(:read)
13
- body = request.body.read
14
- request.body.rewind
15
- else
16
- body = request.body
17
- end
18
-
12
+ def normalize(data_or_body)
13
+ data = data_or_body.respond_to?(:key) ? data_or_body : data_from_string(data_or_body)
14
+ body = data_or_body.respond_to?(:key) ? nil : data_or_body
19
15
  {
20
16
  raw_body: body,
21
- raw_event_type: request.data["resource_name"].to_sym,
17
+ raw_event_type: data["resource_name"].to_sym,
22
18
  raw_event_id: nil,
23
19
  payment_processor: :gumroad,
24
20
  amount: {
25
- paid: request.data["price"].to_i,
26
- currency: request.data["currency"].upcase,
21
+ paid: data["price"].to_i,
22
+ currency: data["currency"].upcase,
27
23
  },
28
24
  customer: {
29
- id: request.data["purchaser_id"].to_s,
30
- email: request.data["email"],
31
- name: request.data["full_name"],
25
+ id: data["purchaser_id"].to_s,
26
+ email: data["email"],
27
+ name: data["full_name"],
32
28
  },
33
- }
29
+ }.compact
30
+ end
31
+
32
+ def parse(request)
33
+ normalize(request.body)
34
+ end
35
+
36
+ private def read_and_rewind(body)
37
+ if body.respond_to?(:read)
38
+ body = body.read
39
+ body.rewind
40
+ else
41
+ body
42
+ end
43
+ end
44
+
45
+ private def data_from_string(body)
46
+ WEBrick::HTTPUtils.parse_query(read_and_rewind(body))
34
47
  end
35
48
  end
36
49
  Compensated.event_parsers.push(Gumroad::EventParser.new)
@@ -1,3 +1,3 @@
1
1
  module Compensated
2
- VERSION = "0.1.0.pre4"
2
+ VERSION = "0.1.0.pre5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compensated
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre4
4
+ version: 0.1.0.pre5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-26 00:00:00.000000000 Z
11
+ date: 2019-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler