contacts_client 0.0.27 → 0.0.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/app/models/padma_contact.rb +58 -33
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDk2MDkyZDIxMDQ2ZWEyZWYyMjFiODk0OGZhNDZhNDM0NGE5OTk2ZQ==
4
+ ZDAyNzU4ZGEyYjczMGY4NWMxYjQwYTJmNjJjYzliNWY1ZDNiMWQ2YQ==
5
5
  data.tar.gz: !binary |-
6
- NzJkZWVlZTFmNDU0ZGJlMTY1M2M1NmM1ZDBmZDM3NDQyN2QyODgwNg==
6
+ ZTRiMmYzNDc5MzVhYzVmZjkyMGQwMjVmNjMxOTJjM2MzZTk0ODY2MQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmFhOTQ4ODNmZjk1YzI2NzZjM2YxMTE0YWMwN2MxNjJjMmRjMGMxZjJkMTA0
10
- NmJlNTBhNTI2YzBhOThmZmIyNTk5ZWJmMzVkYWMwNGFlMWI5ZTdkZWYwOWRh
11
- ZDQ2MjMxMDE0ZWRmMDQ4NWU0ZGZjZWY3NTI3ZDllOGE0OTUzYjg=
9
+ NWI2ZGUzZWNjYjViYTY1YmMyMzZhNmZhMTI4NzA3ZDU4ZTdhZWVmODIwZjUx
10
+ ZGM5YjA0Yzc4OTMyOTI2MzVjNTI0NWRkNTBlZDA2MzAwNWZhN2QyNDEzNDMz
11
+ MTJiODI2YmUxZDA2NzYxMmEzNGE0OTdmMGM3MWQ2NTkwNWJkMWM=
12
12
  data.tar.gz: !binary |-
13
- OTcyNjViOWU1ZjUwMGRiOTg2N2M0YTMyNzNmM2UxYTczOWNhODlmYWMzNzAz
14
- YjNiNzY0NWVlYWZlMWU5ZjU2N2FkYTg1MDU0MzJlNmIyMjU3ZjQxZDAxMTEx
15
- YTQyZWVkOGVjZWQ1OWRkYTM4YTIzZGZlZjRiOWJlNmJiM2ZhNTc=
13
+ N2VjOGM3ODk2YTJlODY1NTUwYmM0ZTY3ZDNiYmE2Zjg0NzE4Y2IyNWEwNTk5
14
+ NzNmMDk3NzkwMGZiYWRjOWE4YTdkNzA0YTFiYmNlMWRlNjA3Y2U5ZmYwNmY3
15
+ YzY3ODJlZTI4ZWQxMzBiZjA3ZDk0YmE3M2E5ODJkZDYzNjU5Nzk=
@@ -3,39 +3,39 @@
3
3
  # Configuration for LogicalModel on /config/initializers/contacts_client.rb
4
4
  class PadmaContact < LogicalModel
5
5
 
6
- self.hydra = Contacts::HYDRA
7
- self.resource_path = "/v0/contacts"
8
- self.attribute_keys =
9
- [
10
- :_id,
11
- :first_name, :last_name,
12
- :gender,
13
- :estimated_age,
14
- :avatar,
15
- :status,
16
- :local_status, # will only be setted if #find specifies account_name
17
- :local_statuses,
18
- :last_seen_at, # will only be setted if #find specifies account_name
19
- :last_local_status,
20
- :local_teacher,
21
- :global_teacher_username,
22
- :level,
23
- :coefficient, # will only be setted if #find specifies account_name
24
- :coefficients_counts,
25
- :owner_name,
26
- :linked, # will only be setted if #find specifies account_name
27
- :check_duplicates,
28
- :email, # Primary email (contact attribute)
29
- :telephone, # Primary telephone (contact attribute)
30
- :in_active_merge,
31
- :observation,
32
- :in_professional_training
33
- ]
34
- self.has_many_keys = [:contact_attributes, :attachments, :tags]
35
- self.use_api_key = true
36
- self.api_key_name = "app_key"
37
- self.api_key = Contacts::API_KEY
38
- self.host = Contacts::HOST
6
+ use_hydra Contacts::HYDRA
7
+
8
+ set_resource_url Contacts::HOST,'/v0/contacts'
9
+ set_api_key :app_key, Contacts::API_KEY
10
+
11
+ attribute :_id
12
+ attribute :first_name
13
+ attribute :last_name
14
+ attribute :gender
15
+ attribute :estimated_age
16
+ attribute :avatar
17
+ attribute :status
18
+ attribute :local_status # will only be setted if #find specifies account_name
19
+ attribute :local_statuses
20
+ attribute :last_seen_at # will only be setted if #find specifies account_name
21
+ attribute :last_local_status
22
+ attribute :local_teacher
23
+ attribute :global_teacher_username
24
+ attribute :level
25
+ attribute :coefficient # will only be setted if #find specifies account_name
26
+ attribute :coefficients_counts
27
+ attribute :owner_name
28
+ attribute :linked # will only be setted if #find specifies account_name
29
+ attribute :check_duplicates
30
+ attribute :email # Primary email (contact attribute)
31
+ attribute :telephone # Primary telephone (contact attribute)
32
+ attribute :in_active_merge
33
+ attribute :observation
34
+ attribute :in_professional_training
35
+
36
+ has_many :contact_attributes
37
+ has_many :attachments
38
+ has_many :tags
39
39
 
40
40
  self.enable_delete_multiple = true
41
41
 
@@ -208,6 +208,31 @@ class PadmaContact < LogicalModel
208
208
  return nil
209
209
  end
210
210
 
211
+ DEFAULT_BATCH_SIZE = 500
212
+ MAX_FAILS = 5
213
+ ##
214
+ #
215
+ # @return [Array] contacts
216
+ # @return nil if connection failed
217
+ def self.batch_search(search_options = {}, batch_options = {})
218
+ batch_options[:batch_size] ||= DEFAULT_BATCH_SIZE
219
+ ret = [];
220
+
221
+ page_elements = nil; page = 1; fails = 0;
222
+ until page_elements == [] || fails >= MAX_FAILS do
223
+ page_elements = PadmaContact.search(search_options.merge(per_page: batch_options[:batch_size], page: page))
224
+ if page_elements
225
+ ret += page_elements
226
+ page += 1
227
+ else
228
+ fails += 1
229
+ end
230
+ fails = 0
231
+ end
232
+
233
+ return (fails >= MAX_FAILS)? nil : ret
234
+ end
235
+
211
236
  ##
212
237
  # Search is same as paginate but will make POST /search request instead of GET /index
213
238
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contacts_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.27
4
+ version: 0.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dwayne Macgowan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-25 00:00:00.000000000 Z
11
+ date: 2014-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.5.8
33
+ version: 0.6.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.5.8
40
+ version: 0.6.0
41
41
  description: This is client library for padma-Contacts-ws
42
42
  email:
43
43
  - dwaynemac@gmail.com