basecrm 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e150ccbdeb24176553161e55e95a985d0355519d
4
- data.tar.gz: c3425ea82d471eb5c98fd998f3fc4107afdae7d6
3
+ metadata.gz: 5dcaf2ad0e9a6309f0e15de36290dacff0df1909
4
+ data.tar.gz: 7affdbefad17eb59e53933115e6e8d1951ca1a44
5
5
  SHA512:
6
- metadata.gz: be39ed5e4cbdede0f58e3ff0b0ae0a0a15d84107f12a72f2cf708bc1b74b2df6065e839ca0f433a0d3a9958d1725ee8a0334cb55c84747a901a10b668088c30d
7
- data.tar.gz: f8fd742d3ba87a17968f40fdb1eea93a0884a1dd8c9a79e32ec5001cc177ab7f54a1011050ea997223cb278998e6c9b77e6444b6881ddd299e8eaa82f73d3ab5
6
+ metadata.gz: 0a845eafc5a21533161c0ba3eda5080bf1d0786b010ad0d49a4bf75f9d1e31341f6038105d3244641b75877bf34d08e64902132d9f7e8b0403b1fd6cfef082bf
7
+ data.tar.gz: 8fb8d88033550b7f97e5239347ef65447bb183c2129730ed81b849e9ef3ba1dfe38229405e01ef923c2507f9c30491ff611b50aa9a547ac5c4a7fd6fe80c60d4
@@ -71,7 +71,9 @@ module BaseCRM
71
71
  end
72
72
  RUBY
73
73
 
74
- [res.status, res.headers, extract_body(res)]
74
+ body = extract_body(res)
75
+ @config.logger.debug body if @config.debug? && body && @config.logger
76
+ [res.status, res.headers, body]
75
77
  rescue Faraday::Error::ConnectionFailed => e
76
78
  raise ConnectionError, e.message
77
79
  end
@@ -33,14 +33,14 @@ module BaseCRM
33
33
  # @param device_uuid [String] Device's UUID for which to perform synchronization
34
34
  # @param session_id [String] Unique identifier of a synchronization session.
35
35
  # @param queue [String|Symbol] Queue name.
36
- # @return [Array<Array<Meta, Model>>] The list of sync's metadata associated with data and data.
36
+ # @return [Array<Array<Meta, Model>>] The list of sync's metadata associated with data and data, or nil if nothing more to synchronize.
37
37
  def fetch(device_uuid, session_id, queue='main')
38
38
  validate_device!(device_uuid)
39
39
  raise ArgumentError, "session_id must not be nil nor empty" unless session_id && !session_id.strip.empty?
40
40
  raise ArgumentError, "queue name must not be nil nor empty" unless queue && !queue.strip.empty?
41
41
 
42
42
  status, _, root = @client.get("/sync/#{session_id}/queues/#{queue}", {}, build_headers(device_uuid))
43
- return [] if status == 204
43
+ return nil if status == 204
44
44
 
45
45
  root[:items].map do |item|
46
46
  klass = classify_type(item[:meta][:type])
@@ -78,7 +78,10 @@ module BaseCRM
78
78
 
79
79
  def build_headers(device_uuid)
80
80
  {
81
- "X-Basecrm-Device-UUID" => device_uuid
81
+ "X-Basecrm-Device-UUID" => device_uuid,
82
+ "X-Client-Type" => 'api',
83
+ "X-Client-Version" => BaseCRM::VERSION,
84
+ "X-Device-Id" => 'Ruby'
82
85
  }
83
86
  end
84
87
 
data/lib/basecrm/sync.rb CHANGED
@@ -50,7 +50,10 @@ module BaseCRM
50
50
  queued_data = @client.sync.fetch(@device_uuid, session.id)
51
51
 
52
52
  # nothing more to synchronize ?
53
- break if queued_data.empty?
53
+ break unless queued_data
54
+
55
+ # something bad at the backend
56
+ next if queued_data.empty?
54
57
 
55
58
  ack_keys = []
56
59
  queued_data.each do |sync_meta, resource|
@@ -1,3 +1,3 @@
1
1
  module BaseCRM
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -70,6 +70,7 @@ describe BaseCRM::Sync do
70
70
  expect(client.sync).to receive(:start).with(device_uuid).and_return(session)
71
71
  expect(client.sync).to receive(:fetch).with(device_uuid, session_id).and_return(queue_items)
72
72
  expect(client.sync).to receive(:fetch).with(device_uuid, session_id).and_return([])
73
+ expect(client.sync).to receive(:fetch).with(device_uuid, session_id).and_return(nil)
73
74
  expect(client.sync).to receive(:ack).with(device_uuid, ack_keys).and_return(true)
74
75
  end
75
76
 
@@ -45,7 +45,7 @@ describe BaseCRM::SyncService do
45
45
  end
46
46
 
47
47
  it 'returns nil' do
48
- expect(client.http_client).to receive(:post).with('/sync/start', {}, {'X-Basecrm-Device-UUID' => device_uuid}).and_return(http_response)
48
+ expect(client.http_client).to receive(:post).with('/sync/start', {}, hash_including({'X-Basecrm-Device-UUID' => device_uuid})).and_return(http_response)
49
49
  expect(client.sync.start(device_uuid)).to be_nil
50
50
  end
51
51
  end
@@ -77,7 +77,7 @@ describe BaseCRM::SyncService do
77
77
  end
78
78
 
79
79
  before :each do
80
- expect(client.http_client).to receive(:post).with('/sync/start', {}, {'X-Basecrm-Device-UUID' => device_uuid}).and_return(http_response)
80
+ expect(client.http_client).to receive(:post).with('/sync/start', {}, hash_including({'X-Basecrm-Device-UUID' => device_uuid})).and_return(http_response)
81
81
  end
82
82
 
83
83
  it 'returns an instance of BaseCRM::SyncSession' do
@@ -140,7 +140,7 @@ describe BaseCRM::SyncService do
140
140
 
141
141
  context 'non empty ack_keys call' do
142
142
  it 'returns true value' do
143
- expect(client.http_client).to receive(:post).with('/sync/ack', {ack_keys: ack_keys}, {'X-Basecrm-Device-UUID' => device_uuid}).and_return(http_response)
143
+ expect(client.http_client).to receive(:post).with('/sync/ack', {ack_keys: ack_keys}, hash_including({'X-Basecrm-Device-UUID' => device_uuid})).and_return(http_response)
144
144
  expect(client.sync.ack(device_uuid, ack_keys)).to eq(true)
145
145
  end
146
146
  end
@@ -190,9 +190,9 @@ describe BaseCRM::SyncService do
190
190
  [204, {}, nil]
191
191
  end
192
192
 
193
- it 'returns an empty array' do
194
- expect(client.http_client).to receive(:get).with("/sync/#{session_id}/queues/main", {}, {'X-Basecrm-Device-UUID' => device_uuid}).and_return(http_response)
195
- expect(client.sync.fetch(device_uuid, session_id)).to eq([])
193
+ it 'returns nil' do
194
+ expect(client.http_client).to receive(:get).with("/sync/#{session_id}/queues/main", {}, hash_including({'X-Basecrm-Device-UUID' => device_uuid})).and_return(http_response)
195
+ expect(client.sync.fetch(device_uuid, session_id)).to be_nil
196
196
  end
197
197
  end
198
198
 
@@ -240,7 +240,7 @@ describe BaseCRM::SyncService do
240
240
  end
241
241
 
242
242
  before :each do
243
- expect(client.http_client).to receive(:get).with("/sync/#{session_id}/queues/main", {}, {'X-Basecrm-Device-UUID' => device_uuid}).and_return(http_response)
243
+ expect(client.http_client).to receive(:get).with("/sync/#{session_id}/queues/main", {}, hash_including({'X-Basecrm-Device-UUID' => device_uuid})).and_return(http_response)
244
244
  end
245
245
 
246
246
  it 'returns an array' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basecrm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - BaseCRM developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-10 00:00:00.000000000 Z
11
+ date: 2015-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday