amorail 0.5.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +23 -0
- data/.gitignore +2 -1
- data/CHANGELOG.md +27 -0
- data/README.md +49 -8
- data/RELEASING.md +43 -0
- data/amorail.gemspec +5 -3
- data/lib/amorail/access_token.rb +44 -0
- data/lib/amorail/client.rb +84 -23
- data/lib/amorail/config.rb +14 -8
- data/lib/amorail/entities/company.rb +2 -0
- data/lib/amorail/entities/contact.rb +2 -0
- data/lib/amorail/entities/contact_link.rb +2 -0
- data/lib/amorail/entities/elementable.rb +4 -2
- data/lib/amorail/entities/lead.rb +2 -0
- data/lib/amorail/entities/leadable.rb +2 -0
- data/lib/amorail/entities/note.rb +2 -0
- data/lib/amorail/entities/task.rb +2 -0
- data/lib/amorail/entities/webhook.rb +2 -0
- data/lib/amorail/entity/finders.rb +2 -0
- data/lib/amorail/entity/params.rb +13 -3
- data/lib/amorail/entity/persistence.rb +2 -0
- data/lib/amorail/entity.rb +20 -3
- data/lib/amorail/exceptions.rb +2 -0
- data/lib/amorail/property.rb +5 -3
- data/lib/amorail/railtie.rb +2 -0
- data/lib/amorail/store_adapters/abstract_store_adapter.rb +23 -0
- data/lib/amorail/store_adapters/memory_store_adapter.rb +50 -0
- data/lib/amorail/store_adapters/redis_store_adapter.rb +83 -0
- data/lib/amorail/store_adapters.rb +15 -0
- data/lib/amorail/version.rb +3 -1
- data/lib/amorail.rb +27 -6
- data/lib/tasks/amorail.rake +2 -0
- data/spec/access_token_spec.rb +59 -0
- data/spec/client_spec.rb +36 -24
- data/spec/company_spec.rb +2 -0
- data/spec/contact_link_spec.rb +2 -0
- data/spec/contact_spec.rb +4 -0
- data/spec/entity_spec.rb +2 -0
- data/spec/fixtures/amorail_test.yml +5 -3
- data/spec/fixtures/authorize.json +6 -0
- data/spec/fixtures/contacts/my_contact_find.json +4 -0
- data/spec/helpers/webmock_helpers.rb +50 -13
- data/spec/lead_spec.rb +2 -0
- data/spec/my_contact_spec.rb +5 -2
- data/spec/note_spec.rb +2 -0
- data/spec/property_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/store_adapters/memory_store_adapter_spec.rb +56 -0
- data/spec/store_adapters/redis_store_adapter_spec.rb +67 -0
- data/spec/support/elementable_example.rb +2 -0
- data/spec/support/entity_class_example.rb +2 -0
- data/spec/support/leadable_example.rb +2 -0
- data/spec/support/my_contact.rb +3 -0
- data/spec/support/my_entity.rb +2 -0
- data/spec/task_spec.rb +2 -0
- data/spec/webhook_spec.rb +2 -0
- metadata +39 -17
- data/.travis.yml +0 -9
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Amorail::StoreAdapters::MemoryStoreAdapter do
|
6
|
+
let!(:expiration) { Time.now.to_i + 86_000 }
|
7
|
+
let(:store) { Amorail::StoreAdapters.build_by_name(:memory) }
|
8
|
+
|
9
|
+
describe '#initialize' do
|
10
|
+
it 'raises error on unknow option' do
|
11
|
+
expect { Amorail::StoreAdapters::MemoryStoreAdapter.new(something: 'something') }.to raise_error(ArgumentError)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#persist_access' do
|
16
|
+
subject { store.persist_access('secret', 'token', 'refresh_token', expiration) }
|
17
|
+
|
18
|
+
it 'save record to memory' do
|
19
|
+
expect { subject }.to change { store.fetch_access('secret') }.from(
|
20
|
+
{}
|
21
|
+
).to(
|
22
|
+
{ token: 'token', refresh_token: 'refresh_token', expiration: expiration }
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#fetch_access' do
|
28
|
+
context 'when token not expired' do
|
29
|
+
it 'returns valid data' do
|
30
|
+
store.persist_access('secret', 'token', 'refresh_token', expiration)
|
31
|
+
expect(store.fetch_access('secret')).to eq({ token: 'token', refresh_token: 'refresh_token', expiration: expiration })
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when token is expired' do
|
36
|
+
it 'returns blank hash' do
|
37
|
+
store.persist_access('secret', 'token', 'refresh_token', Time.now.to_i - 10_000)
|
38
|
+
expect(store.fetch_access('secret')).to eq({})
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#update_access' do
|
44
|
+
let!(:upd_expiration) { Time.now.to_i + 92_000 }
|
45
|
+
subject { store.update_access('secret', 'upd_token', 'upd_refresh', upd_expiration) }
|
46
|
+
|
47
|
+
it 'refresh token data' do
|
48
|
+
store.persist_access('secret', 'token', 'refresh_token', expiration)
|
49
|
+
expect { subject }.to change { store.fetch_access('secret') }.from(
|
50
|
+
{ token: 'token', refresh_token: 'refresh_token', expiration: expiration }
|
51
|
+
).to(
|
52
|
+
{ token: 'upd_token', refresh_token: 'upd_refresh', expiration: upd_expiration }
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Amorail::StoreAdapters::RedisStoreAdapter do
|
6
|
+
before :each do
|
7
|
+
Amorail.config.reload
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:store) { Amorail::StoreAdapters.build_by_name(:redis) }
|
11
|
+
|
12
|
+
describe '#initialize' do
|
13
|
+
it 'raises error on mixed redis options' do
|
14
|
+
expect { Amorail::StoreAdapters::RedisStoreAdapter.new(redis_url: 'redis://127.0.0.1:6379/0',
|
15
|
+
redis_port: '8082') }.to raise_error(ArgumentError)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'raises error on unknown options' do
|
19
|
+
expect { Amorail::StoreAdapters::RedisStoreAdapter.new(redis_url: 'redis://127.0.0.1:6379/0',
|
20
|
+
something: 'smth') }.to raise_error(ArgumentError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'configuration' do
|
25
|
+
let(:adapter) { Amorail::StoreAdapters::RedisStoreAdapter.new }
|
26
|
+
|
27
|
+
it 'set default url' do
|
28
|
+
expect(adapter.storage.id).to eq('redis://127.0.0.1:6379/0')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'set url from env variable' do
|
32
|
+
ENV['REDIS_URL'] = 'redis://localhost:2020/'
|
33
|
+
adapter = Amorail::StoreAdapters::RedisStoreAdapter.new
|
34
|
+
expect(adapter.storage.id).to eq('redis://localhost:2020/0')
|
35
|
+
|
36
|
+
ENV.delete('REDIS_URL')
|
37
|
+
adapter = Amorail::StoreAdapters::RedisStoreAdapter.new
|
38
|
+
expect(adapter.storage.id).to eq('redis://127.0.0.1:6379/0')
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'configuration via host post and db' do
|
42
|
+
adapter = Amorail::StoreAdapters::RedisStoreAdapter.new(
|
43
|
+
redis_host: '127.0.0.2',
|
44
|
+
redis_port: '6372',
|
45
|
+
redis_db_name: '2'
|
46
|
+
)
|
47
|
+
expect(adapter.storage.id).to eq('redis://127.0.0.2:6372/2')
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'configuration via host port and db in module' do
|
51
|
+
Amorail.config.redis_host = '127.0.0.2'
|
52
|
+
Amorail.config.redis_port = '6372'
|
53
|
+
Amorail.config.redis_db_name = '2'
|
54
|
+
expect(adapter.storage.id).to eq('redis://127.0.0.2:6372/2')
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'configuration via redis url' do
|
58
|
+
adapter = Amorail::StoreAdapters::RedisStoreAdapter.new(redis_url: 'redis://127.0.0.2:6322')
|
59
|
+
expect(adapter.storage.id).to eq('redis://127.0.0.2:6322/0')
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'configuration via redis url in module' do
|
63
|
+
Amorail.config.redis_url = 'redis://127.0.0.2:6322'
|
64
|
+
expect(adapter.storage.id).to eq('redis://127.0.0.2:6322/0')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/spec/support/my_contact.rb
CHANGED
data/spec/support/my_entity.rb
CHANGED
data/spec/task_spec.rb
CHANGED
data/spec/webhook_spec.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amorail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alekseenkoss
|
8
8
|
- palkan
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-09-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -113,22 +113,16 @@ dependencies:
|
|
113
113
|
name: anyway_config
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
|
-
- - "~>"
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
version: '0'
|
119
116
|
- - ">="
|
120
117
|
- !ruby/object:Gem::Version
|
121
|
-
version: '0
|
118
|
+
version: '1.0'
|
122
119
|
type: :runtime
|
123
120
|
prerelease: false
|
124
121
|
version_requirements: !ruby/object:Gem::Requirement
|
125
122
|
requirements:
|
126
|
-
- - "~>"
|
127
|
-
- !ruby/object:Gem::Version
|
128
|
-
version: '0'
|
129
123
|
- - ">="
|
130
124
|
- !ruby/object:Gem::Version
|
131
|
-
version: '0
|
125
|
+
version: '1.0'
|
132
126
|
- !ruby/object:Gem::Dependency
|
133
127
|
name: faraday
|
134
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -185,6 +179,20 @@ dependencies:
|
|
185
179
|
- - ">="
|
186
180
|
- !ruby/object:Gem::Version
|
187
181
|
version: '0'
|
182
|
+
- !ruby/object:Gem::Dependency
|
183
|
+
name: redis
|
184
|
+
requirement: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
type: :runtime
|
190
|
+
prerelease: false
|
191
|
+
version_requirements: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - ">="
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0'
|
188
196
|
description: Ruby API client for AmoCRM. You can integrate your system with it.
|
189
197
|
email:
|
190
198
|
- alekseenkoss@gmail.com
|
@@ -193,15 +201,18 @@ executables: []
|
|
193
201
|
extensions: []
|
194
202
|
extra_rdoc_files: []
|
195
203
|
files:
|
204
|
+
- ".github/workflows/rspec.yml"
|
196
205
|
- ".gitignore"
|
197
206
|
- ".rubocop.yml"
|
198
|
-
-
|
207
|
+
- CHANGELOG.md
|
199
208
|
- Gemfile
|
200
209
|
- LICENSE.txt
|
201
210
|
- README.md
|
211
|
+
- RELEASING.md
|
202
212
|
- Rakefile
|
203
213
|
- amorail.gemspec
|
204
214
|
- lib/amorail.rb
|
215
|
+
- lib/amorail/access_token.rb
|
205
216
|
- lib/amorail/client.rb
|
206
217
|
- lib/amorail/config.rb
|
207
218
|
- lib/amorail/entities/company.rb
|
@@ -220,8 +231,13 @@ files:
|
|
220
231
|
- lib/amorail/exceptions.rb
|
221
232
|
- lib/amorail/property.rb
|
222
233
|
- lib/amorail/railtie.rb
|
234
|
+
- lib/amorail/store_adapters.rb
|
235
|
+
- lib/amorail/store_adapters/abstract_store_adapter.rb
|
236
|
+
- lib/amorail/store_adapters/memory_store_adapter.rb
|
237
|
+
- lib/amorail/store_adapters/redis_store_adapter.rb
|
223
238
|
- lib/amorail/version.rb
|
224
239
|
- lib/tasks/amorail.rake
|
240
|
+
- spec/access_token_spec.rb
|
225
241
|
- spec/client_spec.rb
|
226
242
|
- spec/company_spec.rb
|
227
243
|
- spec/contact_link_spec.rb
|
@@ -230,6 +246,7 @@ files:
|
|
230
246
|
- spec/fixtures/accounts/response_1.json
|
231
247
|
- spec/fixtures/accounts/response_2.json
|
232
248
|
- spec/fixtures/amorail_test.yml
|
249
|
+
- spec/fixtures/authorize.json
|
233
250
|
- spec/fixtures/contacts/create.json
|
234
251
|
- spec/fixtures/contacts/find_many.json
|
235
252
|
- spec/fixtures/contacts/find_one.json
|
@@ -250,6 +267,8 @@ files:
|
|
250
267
|
- spec/note_spec.rb
|
251
268
|
- spec/property_spec.rb
|
252
269
|
- spec/spec_helper.rb
|
270
|
+
- spec/store_adapters/memory_store_adapter_spec.rb
|
271
|
+
- spec/store_adapters/redis_store_adapter_spec.rb
|
253
272
|
- spec/support/elementable_example.rb
|
254
273
|
- spec/support/entity_class_example.rb
|
255
274
|
- spec/support/leadable_example.rb
|
@@ -261,7 +280,7 @@ homepage: ''
|
|
261
280
|
licenses:
|
262
281
|
- MIT
|
263
282
|
metadata: {}
|
264
|
-
post_install_message:
|
283
|
+
post_install_message:
|
265
284
|
rdoc_options: []
|
266
285
|
require_paths:
|
267
286
|
- lib
|
@@ -269,19 +288,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
269
288
|
requirements:
|
270
289
|
- - ">="
|
271
290
|
- !ruby/object:Gem::Version
|
272
|
-
version:
|
291
|
+
version: 2.5.0
|
273
292
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
274
293
|
requirements:
|
275
294
|
- - ">="
|
276
295
|
- !ruby/object:Gem::Version
|
277
296
|
version: '0'
|
278
297
|
requirements: []
|
279
|
-
|
280
|
-
|
281
|
-
signing_key:
|
298
|
+
rubygems_version: 3.2.22
|
299
|
+
signing_key:
|
282
300
|
specification_version: 4
|
283
301
|
summary: Ruby API client for AmoCRM
|
284
302
|
test_files:
|
303
|
+
- spec/access_token_spec.rb
|
285
304
|
- spec/client_spec.rb
|
286
305
|
- spec/company_spec.rb
|
287
306
|
- spec/contact_link_spec.rb
|
@@ -290,6 +309,7 @@ test_files:
|
|
290
309
|
- spec/fixtures/accounts/response_1.json
|
291
310
|
- spec/fixtures/accounts/response_2.json
|
292
311
|
- spec/fixtures/amorail_test.yml
|
312
|
+
- spec/fixtures/authorize.json
|
293
313
|
- spec/fixtures/contacts/create.json
|
294
314
|
- spec/fixtures/contacts/find_many.json
|
295
315
|
- spec/fixtures/contacts/find_one.json
|
@@ -310,6 +330,8 @@ test_files:
|
|
310
330
|
- spec/note_spec.rb
|
311
331
|
- spec/property_spec.rb
|
312
332
|
- spec/spec_helper.rb
|
333
|
+
- spec/store_adapters/memory_store_adapter_spec.rb
|
334
|
+
- spec/store_adapters/redis_store_adapter_spec.rb
|
313
335
|
- spec/support/elementable_example.rb
|
314
336
|
- spec/support/entity_class_example.rb
|
315
337
|
- spec/support/leadable_example.rb
|