contactually-ruby 0.0.2 → 0.0.3

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: 0ad5e5f35bd6313dabb8c0d31f19c7f04148b35c
4
- data.tar.gz: ebb1775b23927a2ff1949f8fb4ae63b4a48ff01b
3
+ metadata.gz: ca49195fe60d8e9e06181f7dd4a8bec6c68f008b
4
+ data.tar.gz: 06cd3a35e1a1fbc2df24ee3eccf4640719b533e5
5
5
  SHA512:
6
- metadata.gz: 1fa545571fa44178ee7fbe365cf31b3f39f712d12a65e138cbb0042b141dd34e71a2aa48c177e7e1f1279c81bf0c1680bfce7613261656622ae7b80cf0832089
7
- data.tar.gz: 838af6c311ab5ad8a4a7bf65f6771f2056ff1f1d86a4948848d4899b357e823dae688779657b5893b32eb581131b35762326934a7ca4cac2a982e0e2299765ce
6
+ metadata.gz: 3abac75528e1e2fc3307df86dfc9223050795351dec7a627c83b5627a8f35ebf65b319eb052a3c661e3f97ccbf0ef58dbc62e50617d5c1ef8b66cc74de1c1367
7
+ data.tar.gz: 03502ad51ec24596b735eda32c5ea6fb63bae6fc361366266af1b9f78c16f08fe89d2e3d68d7fda45c917352e14607cd26539e7f8d10c009f5ff56b02cfde180
@@ -37,9 +37,17 @@ module Contactually
37
37
  Contactually::Utils.build_contact(hash);
38
38
  end
39
39
 
40
- def index(params = {})
41
- hash = @master.call('contacts.json', :get, params)
42
- Contactually::Utils.contacts_hash_to_objects(hash)
40
+ def index(all=false, params = {})
41
+ contacts = []
42
+ i = 1
43
+ while true
44
+ params = {page: i} if all
45
+ h = @master.call('contacts.json', :get, params)
46
+ contacts.concat(Contactually::Utils.contacts_hash_to_objects(h))
47
+ i += 1
48
+ break if !all || h['meta']['next_page'] == nil || h['meta']['next_page'] == ''
49
+ end
50
+ contacts
43
51
  end
44
52
 
45
53
  def search(params = {})
@@ -1,3 +1,3 @@
1
1
  module Contactually
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -4,6 +4,7 @@ describe Contactually::Contacts do
4
4
 
5
5
  let(:contact_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/contact.json")) }
6
6
  let(:contacts_index_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/contacts_index.json")) }
7
+ let(:contacts_index_page_2_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/contacts_index_page_2.json")) }
7
8
 
8
9
  before(:all) do
9
10
  Contactually.configure { |c| c.access_token = 'VALID_ACCESS_TOKEN' }
@@ -93,14 +94,21 @@ describe Contactually::Contacts do
93
94
  describe '#index' do
94
95
  it 'calls the api with correct params' do
95
96
  allow(@master).to receive(:call).with('contacts.json', :get, { foo: :bar }).and_return({ 'data' => [] })
96
- subject.index({ foo: :bar })
97
+ subject.index(nil, { foo: :bar })
97
98
  expect(@master).to have_received(:call)
98
99
  end
99
100
 
100
101
  it 'returns contacts from json response' do
101
102
  allow(@master).to receive(:call).with('contacts.json', :get, {}).and_return(JSON.load(contacts_index_json))
102
- expect(subject.index({})).to be_kind_of Array
103
- expect(subject.index({})[0]).to be_kind_of Contactually::Contact
103
+ expect(subject.index(nil, {})).to be_kind_of Array
104
+ expect(subject.index(nil, {})[0]).to be_kind_of Contactually::Contact
105
+ end
106
+
107
+ it 'pages through all pages of results' do
108
+ expect(@master).to receive(:call).with('contacts.json', :get, {page: 1}).twice.and_return(JSON.load(contacts_index_json))
109
+ expect(@master).to receive(:call).with('contacts.json', :get, {page: 2}).twice.and_return(JSON.load(contacts_index_page_2_json))
110
+ expect(subject.index(true, {})).to be_kind_of Array
111
+ expect(subject.index(true, {})[0]).to be_kind_of Contactually::Contact
104
112
  end
105
113
  end
106
114
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "total": 4,
4
- "next_page": null,
4
+ "next_page": "https://api.contactually.com/v2/contacts?page=2",
5
5
  "previous_page": null
6
6
  },
7
7
  "data": [
@@ -0,0 +1,172 @@
1
+ {
2
+ "meta": {
3
+ "total": 4,
4
+ "next_page": null,
5
+ "previous_page": null
6
+ },
7
+ "data": [
8
+ {
9
+ "id": 41296013,
10
+ "user_id": 7,
11
+ "first_name": "Test",
12
+ "last_name": "Ing",
13
+ "full_name": "Test Ing",
14
+ "initials": "TI",
15
+ "title": "",
16
+ "company": null,
17
+ "email": "testing@contact.com",
18
+ "avatar": "",
19
+ "avatar_url": "",
20
+ "last_contacted": null,
21
+ "visible": true,
22
+ "twitter": null,
23
+ "facebook_url": null,
24
+ "linkedin_url": null,
25
+ "first_contacted": null,
26
+ "created_at": "2013-07-02T15:45:01Z",
27
+ "updated_at": "2013-07-02T15:45:01Z",
28
+ "hits": 0,
29
+ "team_parent_id": null,
30
+ "snoozed_at": null,
31
+ "snooze_days": null,
32
+ "groupings": [],
33
+ "email_addresses": [
34
+ "testing@contact.com"
35
+ ],
36
+ "tags": [],
37
+ "contact_status": null,
38
+ "team_last_contacted": null,
39
+ "team_last_contacted_by": null,
40
+ "phone_numbers": [],
41
+ "addresses": [],
42
+ "social_profiles": [],
43
+ "websites": [],
44
+ "custom_fields": []
45
+ },
46
+ {
47
+ "id": 41314854,
48
+ "user_id": 7,
49
+ "first_name": "Whats",
50
+ "last_name": "Uppp",
51
+ "full_name": "Whats Uppp",
52
+ "initials": "WU",
53
+ "title": null,
54
+ "company": null,
55
+ "email": null,
56
+ "avatar": "",
57
+ "avatar_url": "",
58
+ "last_contacted": null,
59
+ "visible": true,
60
+ "twitter": null,
61
+ "facebook_url": null,
62
+ "linkedin_url": null,
63
+ "first_contacted": null,
64
+ "created_at": "2013-07-02T18:56:37Z",
65
+ "updated_at": "2013-07-02T18:56:37Z",
66
+ "hits": 0,
67
+ "team_parent_id": null,
68
+ "snoozed_at": null,
69
+ "snooze_days": null,
70
+ "groupings": [],
71
+ "email_addresses": [],
72
+ "tags": [],
73
+ "contact_status": null,
74
+ "team_last_contacted": null,
75
+ "team_last_contacted_by": null,
76
+ "phone_numbers": [],
77
+ "addresses": [],
78
+ "social_profiles": [],
79
+ "websites": [],
80
+ "custom_fields": []
81
+ },
82
+ {
83
+ "id": 41438693,
84
+ "user_id": 7,
85
+ "first_name": "Adding",
86
+ "last_name": "Contactually",
87
+ "full_name": "Adding Contactually",
88
+ "initials": "AC",
89
+ "title": null,
90
+ "company": null,
91
+ "email": "addingto@contacsafasdf.com",
92
+ "avatar": "",
93
+ "avatar_url": "",
94
+ "last_contacted": null,
95
+ "visible": true,
96
+ "twitter": null,
97
+ "facebook_url": null,
98
+ "linkedin_url": null,
99
+ "first_contacted": null,
100
+ "created_at": "2013-07-03T14:35:29Z",
101
+ "updated_at": "2013-07-03T14:35:29Z",
102
+ "hits": 0,
103
+ "team_parent_id": null,
104
+ "snoozed_at": null,
105
+ "snooze_days": null,
106
+ "groupings": [],
107
+ "email_addresses": [
108
+ "addingto@contacsafasdf.com"
109
+ ],
110
+ "tags": [],
111
+ "contact_status": null,
112
+ "team_last_contacted": null,
113
+ "team_last_contacted_by": null,
114
+ "phone_numbers": [],
115
+ "addresses": [],
116
+ "social_profiles": [],
117
+ "websites": [],
118
+ "custom_fields": []
119
+ },
120
+ {
121
+ "id": 46013214,
122
+ "user_id": 7,
123
+ "first_name": "Gray",
124
+ "last_name": "Hammer",
125
+ "full_name": "Gray Hammer",
126
+ "initials": "GH",
127
+ "title": null,
128
+ "company": null,
129
+ "email": "grayhammer@email.com",
130
+ "avatar": "",
131
+ "avatar_url": "",
132
+ "last_contacted": null,
133
+ "visible": true,
134
+ "twitter": null,
135
+ "facebook_url": null,
136
+ "linkedin_url": null,
137
+ "first_contacted": null,
138
+ "created_at": "2013-08-26T19:17:54Z",
139
+ "updated_at": "2013-08-26T19:17:54Z",
140
+ "hits": 0,
141
+ "team_parent_id": null,
142
+ "snoozed_at": null,
143
+ "snooze_days": null,
144
+ "groupings": [],
145
+ "email_addresses": [
146
+ "grayhammer@email.com"
147
+ ],
148
+ "tags": [],
149
+ "contact_status": null,
150
+ "team_last_contacted": null,
151
+ "team_last_contacted_by": null,
152
+ "phone_numbers": [
153
+ {
154
+ "_id": "521ba9e2b70ec689fe00000a",
155
+ "created_at": "2013-08-26T19:17:54Z",
156
+ "deleted_at": null,
157
+ "extra_data": null,
158
+ "label": "Main",
159
+ "primary": null,
160
+ "remote_id": null,
161
+ "updated_at": "2013-08-26T19:17:54Z",
162
+ "username": null,
163
+ "value": "587-658-7687"
164
+ }
165
+ ],
166
+ "addresses": [],
167
+ "social_profiles": [],
168
+ "websites": [],
169
+ "custom_fields": []
170
+ }
171
+ ]
172
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contactually-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Segraves
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-13 00:00:00.000000000 Z
11
+ date: 2016-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -139,6 +139,7 @@ files:
139
139
  - spec/fixtures/buckets_index.json
140
140
  - spec/fixtures/contact.json
141
141
  - spec/fixtures/contacts_index.json
142
+ - spec/fixtures/contacts_index_page_2.json
142
143
  - spec/fixtures/content.json
143
144
  - spec/fixtures/contents_index.json
144
145
  - spec/fixtures/grouping.json
@@ -190,6 +191,7 @@ test_files:
190
191
  - spec/fixtures/buckets_index.json
191
192
  - spec/fixtures/contact.json
192
193
  - spec/fixtures/contacts_index.json
194
+ - spec/fixtures/contacts_index_page_2.json
193
195
  - spec/fixtures/content.json
194
196
  - spec/fixtures/contents_index.json
195
197
  - spec/fixtures/grouping.json