action_tracker_client 0.1.2 → 0.1.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: a9e768c0943154e44f13861229d10a1b6bfb387e265c5c1f89536760dae4a071
4
- data.tar.gz: 2752ea179b045c7b5b4764c557169bfcd9e847ee5f14fa10ad1e6a0e99ff4577
3
+ metadata.gz: 4a3acbe7a02f6ff3fbceee6c38df52c7d96937839ed71e93ba3ae121f7e06d16
4
+ data.tar.gz: f5d232efd27f372ff37ad9add03e63f422d8d8063569c3f2556e3a4efe3d2ec7
5
5
  SHA512:
6
- metadata.gz: 81ea96dd3607ae73ee323b0a70be67ee45e3a6a136155d33b838165f00d11197bc3dedc72e9ebc69f2bdf53f51fc7b1ae81dd3b0f2dd23d86b07b7e24ce61f0c
7
- data.tar.gz: 5974e50cde35b4cefa30311d29a7012b68ac34ab9fb239a7eeddb9ff89e428ee13ecefc231e6f1012a70bc56367ccead277dcf5429fca06cf5e0ca56cc3c52c3
6
+ metadata.gz: 0ea17c5a474692f2d03c15c601c5af6e5ae0d983931dc0e843ea91743341638c881fc206f5fc079f58f57bbba26840507b6486b9ec9948f4a6b53913d628965e
7
+ data.tar.gz: b212cefcdf7ddd931bfbc3107c1c99fbf10f761fcc1e9abf22019f7fa8c9fffaa46494b7fcc6aac90261f67448519e9f6adcefaae74183a537ed6fe3ac5a8442
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.2)
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,14 +12,14 @@ PATH
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- activemodel (6.0.0)
16
- activesupport (= 6.0.0)
17
- activesupport (6.0.0)
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.1, >= 2.1.8)
22
+ zeitwerk (~> 2.2, >= 2.2.2)
23
23
  addressable (2.6.0)
24
24
  public_suffix (>= 2.0.2, < 4.0)
25
25
  api_signature (0.1.5)
@@ -33,7 +33,7 @@ GEM
33
33
  coderay (1.1.2)
34
34
  coercible (1.0.0)
35
35
  descendants_tracker (~> 0.0.1)
36
- concurrent-ruby (1.1.5)
36
+ concurrent-ruby (1.1.6)
37
37
  crack (0.4.3)
38
38
  safe_yaml (~> 1.0.0)
39
39
  descendants_tracker (0.0.4)
@@ -57,10 +57,10 @@ GEM
57
57
  guard-compat (~> 1.1)
58
58
  rspec (>= 2.99.0, < 4.0)
59
59
  hashdiff (0.3.9)
60
- httparty (0.17.1)
60
+ httparty (0.17.3)
61
61
  mime-types (~> 3.0)
62
62
  multi_xml (>= 0.5.2)
63
- i18n (1.6.0)
63
+ i18n (1.8.2)
64
64
  concurrent-ruby (~> 1.0)
65
65
  ice_nine (0.11.2)
66
66
  listen (3.1.5)
@@ -69,10 +69,10 @@ GEM
69
69
  ruby_dep (~> 1.2)
70
70
  lumberjack (1.0.13)
71
71
  method_source (0.9.2)
72
- mime-types (3.3)
72
+ mime-types (3.3.1)
73
73
  mime-types-data (~> 3.2015)
74
- mime-types-data (3.2019.0904)
75
- minitest (5.12.0)
74
+ mime-types-data (3.2019.1009)
75
+ minitest (5.14.1)
76
76
  model_auditor (0.0.2)
77
77
  multi_xml (0.6.0)
78
78
  nenv (0.3.0)
@@ -86,8 +86,8 @@ GEM
86
86
  byebug (~> 11.0)
87
87
  pry (~> 0.10)
88
88
  public_suffix (3.1.0)
89
- rack (2.0.7)
90
- rake (10.5.0)
89
+ rack (2.2.2)
90
+ rake (13.0.1)
91
91
  rb-fsevent (0.10.3)
92
92
  rb-inotify (0.10.0)
93
93
  ffi (~> 1.0)
@@ -109,7 +109,7 @@ GEM
109
109
  shellany (0.0.1)
110
110
  thor (0.20.3)
111
111
  thread_safe (0.3.6)
112
- tzinfo (1.2.5)
112
+ tzinfo (1.2.7)
113
113
  thread_safe (~> 0.1)
114
114
  virtus (1.0.5)
115
115
  axiom-types (~> 0.1)
@@ -120,7 +120,7 @@ GEM
120
120
  addressable (>= 2.3.6)
121
121
  crack (>= 0.3.2)
122
122
  hashdiff
123
- zeitwerk (2.1.10)
123
+ zeitwerk (2.3.0)
124
124
 
125
125
  PLATFORMS
126
126
  ruby
@@ -130,7 +130,7 @@ DEPENDENCIES
130
130
  bundler (~> 1.16)
131
131
  guard-rspec (~> 4.7, >= 4.7.3)
132
132
  pry-byebug
133
- rake (~> 10.0)
133
+ rake (~> 13.0)
134
134
  rspec (~> 3.0)
135
135
  webmock (~> 3.5, >= 3.5.1)
136
136
 
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
@@ -9,7 +9,7 @@ module ActionTracker
9
9
  include Virtus.model
10
10
  include ActiveModel::Validations
11
11
 
12
- attribute :id, Integer
12
+ attribute :id, String
13
13
 
14
14
  def self.mimic(model_name)
15
15
  @model_name = model_name.to_s.underscore.to_sym
@@ -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, String
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
@@ -3,7 +3,7 @@
3
3
  module ActionTracker
4
4
  module Models
5
5
  class User < ActionTracker::Models::ApplicationRecord
6
- attribute :id, Integer
6
+ attribute :id, String
7
7
  attribute :name, String
8
8
  attribute :type, String
9
9
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ActionTracker
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.7'.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.2
4
+ version: 0.1.7
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-09-23 00:00:00.000000000 Z
11
+ date: 2020-06-10 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
@@ -257,7 +259,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
257
259
  - !ruby/object:Gem::Version
258
260
  version: '0'
259
261
  requirements: []
260
- rubygems_version: 3.0.3
262
+ rubyforge_project:
263
+ rubygems_version: 2.7.6.2
261
264
  signing_key:
262
265
  specification_version: 4
263
266
  summary: ActionTracking service client gem