action_tracker_client 0.1.1 → 0.1.6

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: d4c190be868e1b5eed6ba65b5f5d60e91fc7dccbbdc0d29012d5713c3b68bdf3
4
- data.tar.gz: cd4f693844d1dc312d03b96c6f5b25632cd6307f2bd29055026fbd7b7baaa5cf
3
+ metadata.gz: a547b2c68123c0c7d4c04d5b1c3fadc52efaf31b0f00a71e8ee4e96ca0fb93af
4
+ data.tar.gz: 1f2773baf527349b2abcd46c8b082c595aa09cad576e7a2edbd224bd75e3c3a4
5
5
  SHA512:
6
- metadata.gz: 6a76b40225df9342df4b35c0b20e4e3f98b13a250856f5e1359e600cf28272f729629739766829daa3b6db4dc427938fe8d117ba1e843b51422e4c60a7e0997e
7
- data.tar.gz: ab5cae31834a5032b81a675acfa45abe3fe9da5f1fae84e2f08d8b356e4c687f5a81952de0e528c25b436015f88c87d6f4c3487a71578466bee8a93df352bfa9
6
+ metadata.gz: 1ab6f4aa47df79c3a9309f3780477968877d788ab8e5abe4f3bb4834a28e1d85fd54d62ca70d197cfaec22c359f119e0a9df69933048f3b58ffc0f01904a3d00
7
+ data.tar.gz: df14c93b8abba9c5a350033d21beef3582dc6aea66f00813bed754fc20f53a313822898ac9b93c322a8f4969838e6d0f80bad7840a5801e722003e185ec009c6
data/.gitignore CHANGED
@@ -9,3 +9,6 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ # IDE
14
+ .idea/
@@ -1,6 +1,6 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.5.5
3
-
3
+ NewCops: disable
4
4
  Exclude:
5
5
  - "Guardfile"
6
6
  - "Rakefile"
@@ -30,7 +30,7 @@ Lint/AmbiguousBlockAssociation:
30
30
 
31
31
  ##################### Metrics ##################################
32
32
 
33
- Metrics/LineLength:
33
+ Layout/LineLength:
34
34
  Max: 110
35
35
 
36
36
  Metrics/ClassLength:
@@ -45,11 +45,3 @@ Metrics/BlockLength:
45
45
  Max: 50
46
46
  Exclude:
47
47
  - "**/*_spec.rb"
48
-
49
- ##################### Rails ##################################
50
-
51
- Rails:
52
- Enabled: true
53
-
54
- Rails/SkipsModelValidations:
55
- Enabled: false
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- action_tracker_client (0.1.1)
4
+ action_tracker_client (0.1.6)
5
5
  activemodel (>= 4.0)
6
6
  activesupport (>= 4.0)
7
7
  api_signature (~> 0.1.5)
@@ -12,13 +12,14 @@ PATH
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- activemodel (5.2.3)
16
- activesupport (= 5.2.3)
17
- activesupport (5.2.3)
15
+ activemodel (6.0.3.1)
16
+ activesupport (= 6.0.3.1)
17
+ activesupport (6.0.3.1)
18
18
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
19
  i18n (>= 0.7, < 2)
20
20
  minitest (~> 5.1)
21
21
  tzinfo (~> 1.1)
22
+ zeitwerk (~> 2.2, >= 2.2.2)
22
23
  addressable (2.6.0)
23
24
  public_suffix (>= 2.0.2, < 4.0)
24
25
  api_signature (0.1.5)
@@ -32,7 +33,7 @@ GEM
32
33
  coderay (1.1.2)
33
34
  coercible (1.0.0)
34
35
  descendants_tracker (~> 0.0.1)
35
- concurrent-ruby (1.1.5)
36
+ concurrent-ruby (1.1.6)
36
37
  crack (0.4.3)
37
38
  safe_yaml (~> 1.0.0)
38
39
  descendants_tracker (0.0.4)
@@ -56,10 +57,10 @@ GEM
56
57
  guard-compat (~> 1.1)
57
58
  rspec (>= 2.99.0, < 4.0)
58
59
  hashdiff (0.3.9)
59
- httparty (0.17.0)
60
+ httparty (0.17.3)
60
61
  mime-types (~> 3.0)
61
62
  multi_xml (>= 0.5.2)
62
- i18n (1.6.0)
63
+ i18n (1.8.2)
63
64
  concurrent-ruby (~> 1.0)
64
65
  ice_nine (0.11.2)
65
66
  listen (3.1.5)
@@ -68,10 +69,10 @@ GEM
68
69
  ruby_dep (~> 1.2)
69
70
  lumberjack (1.0.13)
70
71
  method_source (0.9.2)
71
- mime-types (3.2.2)
72
+ mime-types (3.3.1)
72
73
  mime-types-data (~> 3.2015)
73
- mime-types-data (3.2019.0331)
74
- minitest (5.11.3)
74
+ mime-types-data (3.2019.1009)
75
+ minitest (5.14.1)
75
76
  model_auditor (0.0.2)
76
77
  multi_xml (0.6.0)
77
78
  nenv (0.3.0)
@@ -85,8 +86,8 @@ GEM
85
86
  byebug (~> 11.0)
86
87
  pry (~> 0.10)
87
88
  public_suffix (3.1.0)
88
- rack (2.0.7)
89
- rake (10.5.0)
89
+ rack (2.2.2)
90
+ rake (13.0.1)
90
91
  rb-fsevent (0.10.3)
91
92
  rb-inotify (0.10.0)
92
93
  ffi (~> 1.0)
@@ -108,7 +109,7 @@ GEM
108
109
  shellany (0.0.1)
109
110
  thor (0.20.3)
110
111
  thread_safe (0.3.6)
111
- tzinfo (1.2.5)
112
+ tzinfo (1.2.7)
112
113
  thread_safe (~> 0.1)
113
114
  virtus (1.0.5)
114
115
  axiom-types (~> 0.1)
@@ -119,6 +120,7 @@ GEM
119
120
  addressable (>= 2.3.6)
120
121
  crack (>= 0.3.2)
121
122
  hashdiff
123
+ zeitwerk (2.3.0)
122
124
 
123
125
  PLATFORMS
124
126
  ruby
@@ -128,9 +130,9 @@ DEPENDENCIES
128
130
  bundler (~> 1.16)
129
131
  guard-rspec (~> 4.7, >= 4.7.3)
130
132
  pry-byebug
131
- rake (~> 10.0)
133
+ rake (~> 13.0)
132
134
  rspec (~> 3.0)
133
135
  webmock (~> 3.5, >= 3.5.1)
134
136
 
135
137
  BUNDLED WITH
136
- 1.16.2
138
+ 1.17.3
data/README.md CHANGED
@@ -62,6 +62,25 @@ end
62
62
  #<ActionTracker::Models::TransitionRecord:0x00007f9584d3dfd0 @id="810b900d-d24b-4206-85e3-b7a53e55a060"...
63
63
  ```
64
64
 
65
+ ### Records filtered by user
66
+ ```ruby
67
+ api = ActionTracker::Models::TransitionRecord.new
68
+ data = api.filtered_by_users(user_id: user.id, target_id: order.id, target_type: 'Order', per_page: 25, cursor: 'Y3VycmVudF9wYWdl')
69
+
70
+ #<ActionTracker::CollectionProxy:0x00007f958b6970a8
71
+ # ...
72
+
73
+ data.each do |record|
74
+ puts record.inspect
75
+ end
76
+
77
+ #<ActionTracker::Models::TransitionRecord:0x00007f9584d44470 @id="a51b2fe2-fa92-4e91-bdcd-5beee9081903"...
78
+ #<ActionTracker::Models::TransitionRecord:0x00007f9584d3dfd0 @id="810b900d-d24b-4206-85e3-b7a53e55a060"...
79
+
80
+ # data = api.filtered_by_users_count(user_id: user.id, target_id: order.id, target_type: 'Order')
81
+ # this will return count of actions
82
+ ```
83
+
65
84
  ### Writing records
66
85
 
67
86
  Call ActionTracker::Recorder after creating or updating your model:
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency 'bundler', '~> 1.16'
24
24
  spec.add_development_dependency 'guard-rspec', '~> 4.7', '>= 4.7.3'
25
- spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rake', '~> 13.0'
26
26
  spec.add_development_dependency 'rspec', '~> 3.0'
27
27
  spec.add_development_dependency 'webmock', '~> 3.5', '>= 3.5.1'
28
28
 
@@ -8,18 +8,19 @@ require 'active_support/core_ext/object'
8
8
 
9
9
  module ActionTracker
10
10
  autoload :Config, 'action_tracker/config'
11
+ autoload :Recorder, 'action_tracker/recorder'
11
12
 
12
13
  autoload :CollectionProxy, 'action_tracker/utils/collection_proxy'
13
14
  autoload :Connection, 'action_tracker/utils/connection'
14
15
  autoload :Pagination, 'action_tracker/utils/pagination'
15
16
  autoload :RecordsCollection, 'action_tracker/utils/records_collection'
16
17
  autoload :SignedRequest, 'action_tracker/utils/signed_request'
17
-
18
- autoload :Recorder, 'action_tracker/recorder'
18
+ autoload :HttpGateway, 'action_tracker/utils/http_gateway'
19
19
 
20
20
  module Models
21
21
  autoload :ApplicationRecord, 'action_tracker/models/application_record'
22
22
  autoload :TransitionRecord, 'action_tracker/models/transition_record'
23
+ autoload :StatisticRecord, 'action_tracker/models/statistic_record'
23
24
  autoload :Payload, 'action_tracker/models/payload'
24
25
  autoload :User, 'action_tracker/models/user'
25
26
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal :true
2
+
3
+ module ActionTracker
4
+ module Models
5
+ class StatisticRecord < ActionTracker::Models::ApplicationRecord
6
+ include ActionTracker::HttpGateway
7
+
8
+ attribute :user_id, Integer
9
+ attribute :report_date, String
10
+ attribute :total_count, Integer
11
+ attribute :targets, Hash
12
+
13
+ def count(params = {})
14
+ request processed_path(collection_path, params)
15
+ end
16
+
17
+ def daily(params = {})
18
+ path = processed_path("#{collection_path}/daily", params)
19
+ parse_response request(path)
20
+ end
21
+
22
+ def collection_path
23
+ 'statistics'
24
+ end
25
+ end
26
+ end
27
+ end
@@ -3,13 +3,15 @@
3
3
  module ActionTracker
4
4
  module Models
5
5
  class TransitionRecord < ActionTracker::Models::ApplicationRecord
6
+ include ActionTracker::HttpGateway
7
+
6
8
  mimic 'transition'
7
9
 
8
- attribute :target_id, Integer
10
+ attribute :target_id, String
9
11
  attribute :target_type, String
10
12
  attribute :created_at, DateTime
11
13
  attribute :payload, ActionTracker::Models::Payload
12
- attribute :reference_id, Integer
14
+ attribute :reference_id, String
13
15
  attribute :reference_type, String
14
16
 
15
17
  delegate :event, :content, :user, to: :payload
@@ -31,14 +33,25 @@ module ActionTracker
31
33
  end
32
34
 
33
35
  def index(params = {})
34
- path = [collection_path, params.to_query].reject(&:blank?).compact.join('?')
35
- @response ||= Connection.new.get(path)
36
+ parse_response request(processed_path(collection_path, params))
37
+ end
36
38
 
37
- ActionTracker::CollectionProxy.new @response, self.class.model_name
39
+ def filtered_by_users(params = {})
40
+ path = processed_path(users(params[:user_id]), params.except(:user_id))
41
+
42
+ parse_response request(path)
38
43
  end
39
44
 
40
- def collection_path
41
- 'transitions'
45
+ def filtered_by_users_count(params = {})
46
+ path = processed_path(users(params[:user_id]) + '/count', params.except(:user_id))
47
+
48
+ request(path)
49
+ end
50
+
51
+ def filtered_by_users_simple_count(params = {})
52
+ path = processed_path(users(params[:user_id]) + '/without_lambda_count', params.except(:user_id))
53
+
54
+ request(path)
42
55
  end
43
56
 
44
57
  def payload
@@ -53,6 +66,14 @@ module ActionTracker
53
66
  [event, content].reject(&:blank?).compact.join(': ')
54
67
  end
55
68
 
69
+ def collection_path
70
+ 'transitions'
71
+ end
72
+
73
+ def users(user_id)
74
+ "users/#{user_id}"
75
+ end
76
+
56
77
  private
57
78
 
58
79
  def check_payload
@@ -13,7 +13,8 @@ module ActionTracker
13
13
  def form
14
14
  @form ||= ActionTracker::Models::TransitionRecord.new(
15
15
  payload: payload,
16
- reference: reference
16
+ reference: reference,
17
+ created_at: created_at
17
18
  ).with_target(target)
18
19
  end
19
20
 
@@ -58,6 +59,10 @@ module ActionTracker
58
59
  options[:title_append]
59
60
  end
60
61
 
62
+ def created_at
63
+ options[:created_at] || Time.zone&.now
64
+ end
65
+
61
66
  def reference
62
67
  options[:reference]
63
68
  end
@@ -23,7 +23,7 @@ module ActionTracker
23
23
  end
24
24
 
25
25
  def raw_data
26
- @response.dig(model_name.plural)
26
+ @response.dig(model_name.plural) || @response.dig('data')
27
27
  end
28
28
 
29
29
  def entry_name(options = {})
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionTracker
4
+ module HttpGateway
5
+ protected
6
+
7
+ def request(path)
8
+ Connection.new.get(path)
9
+ end
10
+
11
+ def response
12
+ @response ||= Connection.new.get(@path)
13
+ end
14
+
15
+ def processed_path(collection_name, params)
16
+ [collection_name, params.to_query].reject(&:blank?).compact.join('?')
17
+ end
18
+
19
+ def parse_response(response)
20
+ ActionTracker::CollectionProxy.new response, self.class.model_name
21
+ end
22
+ end
23
+ end
@@ -2,14 +2,22 @@
2
2
 
3
3
  module ActionTracker
4
4
  module Pagination
5
- delegate :cursor, to: :meta
5
+ delegate :next_cursor, :current_cursor, to: :meta
6
6
 
7
7
  def size
8
8
  raw_data.try(:size)
9
9
  end
10
10
 
11
+ def per_page
12
+ meta.per_page.to_i
13
+ end
14
+
11
15
  def last_page?
12
- cursor.blank?
16
+ next_cursor.blank?
17
+ end
18
+
19
+ def first_page?
20
+ current_cursor.blank?
13
21
  end
14
22
  end
15
23
  end
@@ -1,3 +1,3 @@
1
1
  module ActionTracker
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_tracker_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Malinovskiy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-05 00:00:00.000000000 Z
11
+ date: 2020-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -50,14 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '10.0'
53
+ version: '13.0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '10.0'
60
+ version: '13.0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rspec
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -221,6 +221,7 @@ files:
221
221
  - lib/action_tracker/config.rb
222
222
  - lib/action_tracker/models/application_record.rb
223
223
  - lib/action_tracker/models/payload.rb
224
+ - lib/action_tracker/models/statistic_record.rb
224
225
  - lib/action_tracker/models/transition_record.rb
225
226
  - lib/action_tracker/models/user.rb
226
227
  - lib/action_tracker/recorder.rb
@@ -230,6 +231,7 @@ files:
230
231
  - lib/action_tracker/templates/update.rb
231
232
  - lib/action_tracker/utils/collection_proxy.rb
232
233
  - lib/action_tracker/utils/connection.rb
234
+ - lib/action_tracker/utils/http_gateway.rb
233
235
  - lib/action_tracker/utils/pagination.rb
234
236
  - lib/action_tracker/utils/records_collection.rb
235
237
  - lib/action_tracker/utils/signed_request.rb