apisync-rails 0.0.4 → 0.1.1

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
  SHA1:
3
- metadata.gz: 34ddbfb8791d1f24a61b9c7944494f006c2b543a
4
- data.tar.gz: ec710fff7c676929cfd11d70d958aa1b56ca768d
3
+ metadata.gz: a583b9bcbe4c6e0dafb2d339832e45f00d10940c
4
+ data.tar.gz: 767adc9866af63552c5bf288280a265e85e27a81
5
5
  SHA512:
6
- metadata.gz: cd78a4b8aed59f148678befaa4e9e27eb08f32448aedb1a5cfff6783ca6eb74354f3dc494c959043a8f31ca96a73dc80b6af4b9dda46c3416530653835cb2d14
7
- data.tar.gz: '091e34cb46df93b256f10b2811548facbd597d02d75dcdbe29fc61fc9d64c760691c3d97601f271923fd993785f3cfae812b1ec023fb0d89a69d5e04b1bc5742'
6
+ metadata.gz: 0e10811ce56132875c6c302fe78575536f914237ced8a63aad970aea767f4862f4e1b09acdadcee083ddbd4675997060cd7aa746db6f5767e0a983cb4ca84f45
7
+ data.tar.gz: '08476e75fd97d3068103a344304359fe7ff00eade77e99d63038f333fab71564dce0962272353edd76065df2f6d63d8653388c4ebe9d34f279fd14e7caf38d2f'
data/README.md CHANGED
@@ -100,6 +100,11 @@ class Product < ActiveRecord::Base
100
100
  end
101
101
  ```
102
102
 
103
+ **Step 3: test on the console:** on the Rails console, try saving the model.
104
+ The request and response should show up.
105
+
106
+ You can turn off these logs, use `Apisync.verbose = false`.
107
+
103
108
  **Explanation**
104
109
 
105
110
  **sync_if** defines if the item should be synchronized. The method with the
@@ -132,6 +137,13 @@ over and over.
132
137
  By default, `reference_id` is set to whatever **id** value is. You can
133
138
  customize it, e.g `attribute :reference_id, from: :my_custom_id`.
134
139
 
140
+ ### Failed requests
141
+
142
+ A `warning` will be logged (`Rails.logger.warn`) whenever a request fails.
143
+
144
+ In asynchronous cases (e.g Sidekiq), an exception will be raised
145
+ (`Apisync::RequestFailed`) so jobs can be retried.
146
+
135
147
  ### Note on callbacks
136
148
 
137
149
  This gem uses Rails' callbacks to trigger synchronization.
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_dependency "activesupport", ">= 4.2"
25
25
  spec.add_dependency "activerecord", ">= 4.2"
26
- spec.add_dependency "apisync", ">= 0.1.4"
26
+ spec.add_dependency "apisync", ">= 0.2.3"
27
27
 
28
28
  spec.add_development_dependency "bundler", "~> 1.15"
29
29
  spec.add_development_dependency "rake", "~> 10.0"
@@ -7,10 +7,10 @@ class Apisync
7
7
 
8
8
  if ::Rails.respond_to?(:gem_version)
9
9
  rails_version = ::Rails.gem_version.to_s
10
- elsif Rails::VERSION.is_a?(String)
11
- rails_version = Rails::VERSION
12
- elsif Rails::VERSION::STRING
13
- rails_version = Rails::VERSION::STRING
10
+ elsif ::Rails::VERSION.is_a?(String)
11
+ rails_version = ::Rails::VERSION
12
+ elsif ::Rails::VERSION::STRING
13
+ rails_version = ::Rails::VERSION::STRING
14
14
  end
15
15
 
16
16
  headers["X-Framework"] = "Ruby on Rails #{rails_version}"
@@ -23,8 +23,29 @@ class Apisync
23
23
  headers["X-TooManyRequests-Attempts"] = too_many_requests_attempts.to_s
24
24
  end
25
25
 
26
- client = Apisync.new
27
- client.inventory_items.save(attributes: attrs, headers: headers)
26
+ if Apisync.logger.nil?
27
+ Apisync.logger = ::Rails.logger
28
+ end
29
+
30
+ if Apisync.verbose.nil?
31
+ verbose = ::Rails.env.development?
32
+ else
33
+ verbose = Apisync.verbose
34
+ end
35
+
36
+ client = Apisync.new(verbose: verbose)
37
+ response = client.inventory_items.save(attributes: attrs, headers: headers)
38
+
39
+ unless response.success?
40
+ reference_id_msg = ""
41
+ if attrs["reference_id"].present?
42
+ reference_id_msg = "with reference_id '#{attrs[:reference_id]}' "
43
+ end
44
+
45
+ ::Rails.logger.warn "[APISync] Request #{reference_id_msg}failed: #{response.body}"
46
+ end
47
+
48
+ response
28
49
  end
29
50
  end
30
51
  end
@@ -48,6 +48,8 @@ class Apisync
48
48
  validate!(payload)
49
49
  log_warnings(payload)
50
50
 
51
+ Apisync::Rails::Extensions.setup
52
+
51
53
  if defined?(::Sidekiq)
52
54
  Apisync::Rails::SyncModelJob::Sidekiq.perform_async(
53
55
  @model.class.name,
@@ -15,13 +15,17 @@ class Apisync
15
15
  end
16
16
 
17
17
  begin
18
- Apisync::Rails::Http.post(
18
+ response = Apisync::Rails::Http.post(
19
19
  attributes,
20
20
  request_concurrency: :asynchronous,
21
21
  concurrency_lib: "Sidekiq #{::Sidekiq::VERSION}",
22
22
  too_many_requests_attempts: attempt.to_s
23
23
  )
24
24
 
25
+ unless response.success?
26
+ raise Apisync::RequestFailed, "[apisync] Request failed: #{response.body}"
27
+ end
28
+
25
29
  # When there are too many requests and ApiSync's API cannot take it,
26
30
  # this algorithm will push this job to be retried in the future.
27
31
  rescue Apisync::TooManyRequests
@@ -1,5 +1,5 @@
1
1
  class Apisync
2
2
  module Rails
3
- VERSION = "0.0.4"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apisync-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre de Oliveira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-13 00:00:00.000000000 Z
11
+ date: 2018-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.1.4
47
+ version: 0.2.3
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 0.1.4
54
+ version: 0.2.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement