pipeline_deals 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +1 -1
- data/LICENSE.txt +2 -2
- data/Rakefile +6 -0
- data/lib/pipeline_deals.rb +11 -2
- data/lib/pipeline_deals/resource.rb +11 -5
- data/lib/pipeline_deals/resources/calendar_entry.rb +7 -0
- data/lib/pipeline_deals/resources/company.rb +2 -0
- data/lib/pipeline_deals/resources/company_custom_field_label.rb +1 -0
- data/lib/pipeline_deals/resources/deal.rb +4 -2
- data/lib/pipeline_deals/resources/deal_custom_field_label.rb +1 -0
- data/lib/pipeline_deals/resources/definitions.rb +12 -10
- data/lib/pipeline_deals/resources/event_category.rb +0 -1
- data/lib/pipeline_deals/resources/lead_source.rb +0 -1
- data/lib/pipeline_deals/resources/note.rb +9 -0
- data/lib/pipeline_deals/resources/note_category.rb +0 -1
- data/lib/pipeline_deals/resources/person.rb +8 -1
- data/lib/pipeline_deals/resources/person_custom_field_label.rb +1 -0
- data/lib/pipeline_deals/resources/predefined_contacts_tags.rb +0 -1
- data/lib/pipeline_deals/resources/user.rb +1 -0
- data/lib/pipeline_deals/version.rb +1 -1
- data/pipeline_deals.gemspec +6 -1
- data/spec/cassettes/PipelineDeals_Deal_calendar_entries.yml +49 -0
- data/spec/cassettes/PipelineDeals_Deal_notes.yml +62 -0
- data/spec/cassettes/PipelineDeals_Person_calendar_entries.yml +49 -0
- data/spec/cassettes/PipelineDeals_Person_documents.yml +47 -0
- data/spec/cassettes/PipelineDeals_Person_items.yml +156 -0
- data/spec/cassettes/PipelineDeals_Person_next_page.yml +57 -0
- data/spec/cassettes/PipelineDeals_Person_notes.yml +53 -0
- data/spec/cassettes/PipelineDeals_Person_per_page.yml +76 -0
- data/spec/cassettes/PipelineDeals_Person_six_things.yml +72 -0
- data/spec/cassettes/deal_create.yml +48 -0
- data/spec/cassettes/deals_filtered_by_custom_field.yml +95 -0
- data/spec/cassettes/get_a_person.yml +49 -0
- data/spec/cassettes/people_filtered_by_status.yml +64 -0
- data/spec/cassettes/person_with_company.yml +49 -0
- data/spec/cassettes/person_with_deals.yml +49 -0
- data/spec/pipeline_deals/admin_spec.rb +3 -4
- data/spec/pipeline_deals/companies_spec.rb +4 -62
- data/spec/pipeline_deals/deals_spec.rb +67 -51
- data/spec/pipeline_deals/people_spec.rb +45 -0
- data/spec/spec_helper.rb +13 -5
- data/spec/support/has_calendar_entries.rb +8 -0
- data/spec/support/has_deals.rb +8 -0
- data/spec/support/has_documents.rb +8 -0
- data/spec/support/has_notes.rb +8 -0
- data/spec/support/has_people.rb +8 -0
- data/spec/{pipeline_deals → support}/pagination_spec.rb +10 -12
- metadata +98 -22
- data/a_spike.rb +0 -72
- data/spec/pipeline_deals/has_documents.rb +0 -9
- data/spec/pipeline_deals/has_people.rb +0 -10
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PipelineDeals::Person do
|
4
|
+
it_should_behave_like "a paginated collection"
|
5
|
+
|
6
|
+
let(:docs_obj) { person }
|
7
|
+
let(:cals_obj) { person }
|
8
|
+
let(:notes_obj) { person }
|
9
|
+
let(:deals_obj) { VCR.use_cassette(:person_with_deals) { PipelineDeals::Person.find 1 } }
|
10
|
+
it_should_behave_like "an object that can have documents"
|
11
|
+
it_should_behave_like "an object that can have deals"
|
12
|
+
it_should_behave_like "an object that can have notes"
|
13
|
+
it_should_behave_like "an object that can have calendar_entries"
|
14
|
+
|
15
|
+
let(:person) { VCR.use_cassette(:get_a_person) { PipelineDeals::Person.find 1 } }
|
16
|
+
let(:person_with_company) { VCR.use_cassette(:person_with_company) { PipelineDeals::Person.find 1 } }
|
17
|
+
|
18
|
+
it "can filter on lead_status" do
|
19
|
+
VCR.use_cassette(:people_filtered_by_status) do
|
20
|
+
people = PipelineDeals::Person.where(conditions: {person_status: [2]})
|
21
|
+
expect(people.size).to eq 4
|
22
|
+
people.all? {|person| [2].include?(person.lead_status.id) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "associations" do
|
27
|
+
it "has a lead_status" do
|
28
|
+
expect(person.lead_status).to be_an_instance_of PipelineDeals::LeadStatus
|
29
|
+
expect(person.lead_status.name).to eq "Hot"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "has a lead_source" do
|
33
|
+
expect(person.lead_source).to be_an_instance_of PipelineDeals::LeadSource
|
34
|
+
expect(person.lead_source.name).to eq "Cold Call"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has a user" do
|
38
|
+
expect(person.user).to be_an_instance_of(PipelineDeals::User)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "has a company" do
|
42
|
+
expect(person_with_company.company).to be_an_instance_of PipelineDeals::Company
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,21 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'vcr'
|
3
3
|
require 'pipeline_deals'
|
4
|
-
require 'pry'
|
5
4
|
|
6
|
-
|
7
|
-
require '
|
8
|
-
|
5
|
+
begin
|
6
|
+
require 'pry'
|
7
|
+
rescue LoadError
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'support/pagination_spec'
|
11
|
+
require 'support/has_documents'
|
12
|
+
require 'support/has_notes'
|
13
|
+
require 'support/has_calendar_entries'
|
14
|
+
require 'support/has_people'
|
15
|
+
require 'support/has_deals'
|
9
16
|
|
10
|
-
PipelineDeals::Resource.site = "http://localhost:3000"
|
17
|
+
PipelineDeals::Resource.site = ENV['PIPELINEDEALS_URL'] || "http://localhost:3000"
|
18
|
+
PipelineDeals.api_key = ENV['PIPELINEDEALS_API_KEY'] || 'iJHyFkMUBSfjUovt29'
|
11
19
|
|
12
20
|
#ActiveResource::Base.logger = Logger.new(STDOUT)
|
13
21
|
|
@@ -0,0 +1,8 @@
|
|
1
|
+
shared_examples_for "an object that can have calendar_entries" do
|
2
|
+
it "has documents" do
|
3
|
+
VCR.use_cassette(cassette('calendar_entries')) do
|
4
|
+
expect(cals_obj.calendar_entries.size).to be >= 1
|
5
|
+
expect(cals_obj.calendar_entries.first).to be_an_instance_of PipelineDeals::CalendarEntry
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
shared_examples_for "an object that can have documents" do
|
2
|
+
it "has documents" do
|
3
|
+
VCR.use_cassette(cassette('documents')) do
|
4
|
+
expect(docs_obj.documents.size).to be >= 1
|
5
|
+
expect(docs_obj.documents.first).to be_an_instance_of PipelineDeals::Document
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
@@ -1,38 +1,36 @@
|
|
1
|
-
|
2
1
|
shared_examples_for "a paginated collection" do
|
3
2
|
let(:paginated_items) { VCR.use_cassette(cassette('items')) { described_class.find(:all) } }
|
4
3
|
|
5
4
|
it "should have a pagination object" do
|
6
|
-
paginated_items.pagination.
|
5
|
+
expect(paginated_items.pagination).to be
|
7
6
|
end
|
8
7
|
|
9
8
|
describe "the pagination object" do
|
10
9
|
let(:pagination) { paginated_items.pagination }
|
11
10
|
|
12
|
-
it "
|
13
|
-
pagination[:total].
|
11
|
+
it "has a total" do
|
12
|
+
expect(pagination[:total]).to be
|
14
13
|
end
|
15
14
|
|
16
|
-
it "
|
17
|
-
pagination[:page].
|
15
|
+
it "has a page number" do
|
16
|
+
expect(pagination[:page]).to be
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
21
20
|
describe "specify per_page" do
|
22
21
|
let(:per_page) { VCR.use_cassette(cassette('per_page')) { described_class.where(per_page: 7) } }
|
23
22
|
|
24
|
-
it "
|
25
|
-
per_page.size.
|
23
|
+
it "can specify a per_page" do
|
24
|
+
expect(per_page.size).to eq 7
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
28
|
describe "getting a different page" do
|
30
29
|
let(:six_things) { VCR.use_cassette(cassette('six_things')) { described_class.where(page: 1, per_page: 6) } }
|
31
30
|
let(:next_page) { VCR.use_cassette(cassette('next_page')) { described_class.where(page: 2, per_page: 3) } }
|
32
|
-
|
33
|
-
|
31
|
+
|
32
|
+
it "gets the next page of stuff" do
|
33
|
+
expect(six_things[3..5].map(&:id)).to eq next_page.map(&:id)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
38
|
-
|
metadata
CHANGED
@@ -1,32 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pipeline_deals
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Grant Ammons
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-08-19 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activeresource
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - '='
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: 4.0.0
|
19
|
+
version: 4.0.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - '='
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: 4.0.0
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: webmock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: vcr
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
30
69
|
description: The pipeline_deals gem is a nice ruby wrapper around the PipelineDeals
|
31
70
|
API.
|
32
71
|
email:
|
@@ -35,18 +74,18 @@ executables: []
|
|
35
74
|
extensions: []
|
36
75
|
extra_rdoc_files: []
|
37
76
|
files:
|
38
|
-
- .gitignore
|
77
|
+
- ".gitignore"
|
39
78
|
- Gemfile
|
40
79
|
- Gemfile.lock
|
41
80
|
- LICENSE.txt
|
42
81
|
- README.md
|
43
82
|
- Rakefile
|
44
|
-
- a_spike.rb
|
45
83
|
- lib/pipeline_deals.rb
|
46
84
|
- lib/pipeline_deals/admin_resource.rb
|
47
85
|
- lib/pipeline_deals/collection.rb
|
48
86
|
- lib/pipeline_deals/resource.rb
|
49
87
|
- lib/pipeline_deals/resources.rb
|
88
|
+
- lib/pipeline_deals/resources/calendar_entry.rb
|
50
89
|
- lib/pipeline_deals/resources/company.rb
|
51
90
|
- lib/pipeline_deals/resources/company_custom_field_label.rb
|
52
91
|
- lib/pipeline_deals/resources/custom_field_label_dropdown_entry.rb
|
@@ -58,6 +97,7 @@ files:
|
|
58
97
|
- lib/pipeline_deals/resources/event_category.rb
|
59
98
|
- lib/pipeline_deals/resources/lead_source.rb
|
60
99
|
- lib/pipeline_deals/resources/lead_status.rb
|
100
|
+
- lib/pipeline_deals/resources/note.rb
|
61
101
|
- lib/pipeline_deals/resources/note_category.rb
|
62
102
|
- lib/pipeline_deals/resources/person.rb
|
63
103
|
- lib/pipeline_deals/resources/person_custom_field_label.rb
|
@@ -71,58 +111,76 @@ files:
|
|
71
111
|
- spec/cassettes/PipelineDeals_Company_people.yml
|
72
112
|
- spec/cassettes/PipelineDeals_Company_per_page.yml
|
73
113
|
- spec/cassettes/PipelineDeals_Company_six_things.yml
|
114
|
+
- spec/cassettes/PipelineDeals_Deal_calendar_entries.yml
|
74
115
|
- spec/cassettes/PipelineDeals_Deal_different_page.yml
|
75
116
|
- spec/cassettes/PipelineDeals_Deal_documents.yml
|
76
117
|
- spec/cassettes/PipelineDeals_Deal_items.yml
|
77
118
|
- spec/cassettes/PipelineDeals_Deal_next_page.yml
|
119
|
+
- spec/cassettes/PipelineDeals_Deal_notes.yml
|
78
120
|
- spec/cassettes/PipelineDeals_Deal_per_page.yml
|
79
121
|
- spec/cassettes/PipelineDeals_Deal_six_things.yml
|
122
|
+
- spec/cassettes/PipelineDeals_Person_calendar_entries.yml
|
123
|
+
- spec/cassettes/PipelineDeals_Person_documents.yml
|
124
|
+
- spec/cassettes/PipelineDeals_Person_items.yml
|
125
|
+
- spec/cassettes/PipelineDeals_Person_next_page.yml
|
126
|
+
- spec/cassettes/PipelineDeals_Person_notes.yml
|
127
|
+
- spec/cassettes/PipelineDeals_Person_per_page.yml
|
128
|
+
- spec/cassettes/PipelineDeals_Person_six_things.yml
|
80
129
|
- spec/cassettes/company_deals.yml
|
81
130
|
- spec/cassettes/company_people.yml
|
131
|
+
- spec/cassettes/deal_create.yml
|
82
132
|
- spec/cassettes/deal_documents.yml
|
83
133
|
- spec/cassettes/deal_user.yml
|
84
134
|
- spec/cassettes/deal_with_company.yml
|
85
135
|
- spec/cassettes/deal_with_primary_contact.yml
|
136
|
+
- spec/cassettes/deals_filtered_by_custom_field.yml
|
86
137
|
- spec/cassettes/deals_filtered_by_stage.yml
|
87
138
|
- spec/cassettes/get_a_company.yml
|
88
139
|
- spec/cassettes/get_a_deal.yml
|
140
|
+
- spec/cassettes/get_a_person.yml
|
89
141
|
- spec/cassettes/get_deals.yml
|
90
142
|
- spec/cassettes/list_deal_stages.yml
|
91
143
|
- spec/cassettes/list_deals.yml
|
92
144
|
- spec/cassettes/paginate_deals.yml
|
145
|
+
- spec/cassettes/people_filtered_by_status.yml
|
146
|
+
- spec/cassettes/person_with_company.yml
|
147
|
+
- spec/cassettes/person_with_deals.yml
|
93
148
|
- spec/cassettes/update_deal.yml
|
94
149
|
- spec/cassettes/update_lead_source.yml
|
95
150
|
- spec/pipeline_deals/admin_spec.rb
|
96
151
|
- spec/pipeline_deals/companies_spec.rb
|
97
152
|
- spec/pipeline_deals/custom_fields_spec.rb
|
98
153
|
- spec/pipeline_deals/deals_spec.rb
|
99
|
-
- spec/pipeline_deals/
|
100
|
-
- spec/pipeline_deals/has_people.rb
|
101
|
-
- spec/pipeline_deals/pagination_spec.rb
|
154
|
+
- spec/pipeline_deals/people_spec.rb
|
102
155
|
- spec/spec_helper.rb
|
156
|
+
- spec/support/has_calendar_entries.rb
|
157
|
+
- spec/support/has_deals.rb
|
158
|
+
- spec/support/has_documents.rb
|
159
|
+
- spec/support/has_notes.rb
|
160
|
+
- spec/support/has_people.rb
|
161
|
+
- spec/support/pagination_spec.rb
|
103
162
|
homepage: https://github.com/PipelineDeals/pipelinedeals_api
|
104
163
|
licenses: []
|
164
|
+
metadata: {}
|
105
165
|
post_install_message:
|
106
166
|
rdoc_options: []
|
107
167
|
require_paths:
|
108
168
|
- lib
|
109
169
|
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
-
none: false
|
111
170
|
requirements:
|
112
|
-
- -
|
171
|
+
- - ">="
|
113
172
|
- !ruby/object:Gem::Version
|
114
173
|
version: '0'
|
115
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
-
none: false
|
117
175
|
requirements:
|
118
|
-
- -
|
176
|
+
- - ">="
|
119
177
|
- !ruby/object:Gem::Version
|
120
178
|
version: '0'
|
121
179
|
requirements: []
|
122
180
|
rubyforge_project:
|
123
|
-
rubygems_version:
|
181
|
+
rubygems_version: 2.2.2
|
124
182
|
signing_key:
|
125
|
-
specification_version:
|
183
|
+
specification_version: 4
|
126
184
|
summary: The pipeline_deals gem is a nice ruby wrapper around the PipelineDeals API.
|
127
185
|
test_files:
|
128
186
|
- spec/cassettes/PipelineDeals_Company_documents.yml
|
@@ -131,33 +189,51 @@ test_files:
|
|
131
189
|
- spec/cassettes/PipelineDeals_Company_people.yml
|
132
190
|
- spec/cassettes/PipelineDeals_Company_per_page.yml
|
133
191
|
- spec/cassettes/PipelineDeals_Company_six_things.yml
|
192
|
+
- spec/cassettes/PipelineDeals_Deal_calendar_entries.yml
|
134
193
|
- spec/cassettes/PipelineDeals_Deal_different_page.yml
|
135
194
|
- spec/cassettes/PipelineDeals_Deal_documents.yml
|
136
195
|
- spec/cassettes/PipelineDeals_Deal_items.yml
|
137
196
|
- spec/cassettes/PipelineDeals_Deal_next_page.yml
|
197
|
+
- spec/cassettes/PipelineDeals_Deal_notes.yml
|
138
198
|
- spec/cassettes/PipelineDeals_Deal_per_page.yml
|
139
199
|
- spec/cassettes/PipelineDeals_Deal_six_things.yml
|
200
|
+
- spec/cassettes/PipelineDeals_Person_calendar_entries.yml
|
201
|
+
- spec/cassettes/PipelineDeals_Person_documents.yml
|
202
|
+
- spec/cassettes/PipelineDeals_Person_items.yml
|
203
|
+
- spec/cassettes/PipelineDeals_Person_next_page.yml
|
204
|
+
- spec/cassettes/PipelineDeals_Person_notes.yml
|
205
|
+
- spec/cassettes/PipelineDeals_Person_per_page.yml
|
206
|
+
- spec/cassettes/PipelineDeals_Person_six_things.yml
|
140
207
|
- spec/cassettes/company_deals.yml
|
141
208
|
- spec/cassettes/company_people.yml
|
209
|
+
- spec/cassettes/deal_create.yml
|
142
210
|
- spec/cassettes/deal_documents.yml
|
143
211
|
- spec/cassettes/deal_user.yml
|
144
212
|
- spec/cassettes/deal_with_company.yml
|
145
213
|
- spec/cassettes/deal_with_primary_contact.yml
|
214
|
+
- spec/cassettes/deals_filtered_by_custom_field.yml
|
146
215
|
- spec/cassettes/deals_filtered_by_stage.yml
|
147
216
|
- spec/cassettes/get_a_company.yml
|
148
217
|
- spec/cassettes/get_a_deal.yml
|
218
|
+
- spec/cassettes/get_a_person.yml
|
149
219
|
- spec/cassettes/get_deals.yml
|
150
220
|
- spec/cassettes/list_deal_stages.yml
|
151
221
|
- spec/cassettes/list_deals.yml
|
152
222
|
- spec/cassettes/paginate_deals.yml
|
223
|
+
- spec/cassettes/people_filtered_by_status.yml
|
224
|
+
- spec/cassettes/person_with_company.yml
|
225
|
+
- spec/cassettes/person_with_deals.yml
|
153
226
|
- spec/cassettes/update_deal.yml
|
154
227
|
- spec/cassettes/update_lead_source.yml
|
155
228
|
- spec/pipeline_deals/admin_spec.rb
|
156
229
|
- spec/pipeline_deals/companies_spec.rb
|
157
230
|
- spec/pipeline_deals/custom_fields_spec.rb
|
158
231
|
- spec/pipeline_deals/deals_spec.rb
|
159
|
-
- spec/pipeline_deals/
|
160
|
-
- spec/pipeline_deals/has_people.rb
|
161
|
-
- spec/pipeline_deals/pagination_spec.rb
|
232
|
+
- spec/pipeline_deals/people_spec.rb
|
162
233
|
- spec/spec_helper.rb
|
163
|
-
|
234
|
+
- spec/support/has_calendar_entries.rb
|
235
|
+
- spec/support/has_deals.rb
|
236
|
+
- spec/support/has_documents.rb
|
237
|
+
- spec/support/has_notes.rb
|
238
|
+
- spec/support/has_people.rb
|
239
|
+
- spec/support/pagination_spec.rb
|
data/a_spike.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'active_resource'
|
3
|
-
require 'pry'
|
4
|
-
|
5
|
-
class PldCollection < ActiveResource::Collection
|
6
|
-
attr_accessor :pagination
|
7
|
-
def initialize(parsed = {})
|
8
|
-
@pagination = parsed['pagination']
|
9
|
-
@elements = parsed['entries']
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class PldResource < ActiveResource::Base
|
14
|
-
self.site = "http://localhost:3000/api/v3"
|
15
|
-
self.collection_parser = PldCollection
|
16
|
-
|
17
|
-
def self.find(*arguments)
|
18
|
-
scope = arguments.slice!(0)
|
19
|
-
options = arguments.slice!(0) || {}
|
20
|
-
|
21
|
-
if options[:params]
|
22
|
-
options[:params].merge!({api_key: 'n8PJJWRsx0MxgOEwGk7'})
|
23
|
-
else
|
24
|
-
options.merge!({params: {api_key: 'n8PJJWRsx0MxgOEwGk7'}})
|
25
|
-
end
|
26
|
-
|
27
|
-
super(scope, options)
|
28
|
-
end
|
29
|
-
|
30
|
-
def save
|
31
|
-
prefix_options[:api_key] = 'n8PJJWRsx0MxgOEwGk7'
|
32
|
-
self.include_root_in_json = true
|
33
|
-
super
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class Person < PldResource
|
38
|
-
end
|
39
|
-
|
40
|
-
class Deal < PldResource
|
41
|
-
has_many :people
|
42
|
-
end
|
43
|
-
|
44
|
-
#################################o
|
45
|
-
# Finding a single and putting
|
46
|
-
#################################o
|
47
|
-
|
48
|
-
# deal = Deal.find(1)
|
49
|
-
# $stdout << "found, deal = #{deal.inspect}\n"
|
50
|
-
# deal.name = 'blah2'
|
51
|
-
# $stdout << "About to save name:\n"
|
52
|
-
# deal.people
|
53
|
-
# deal.person_ids
|
54
|
-
# deal.custom_fields.custom_label_29 = 345
|
55
|
-
#deal.save
|
56
|
-
|
57
|
-
#################################o
|
58
|
-
# fetching collections
|
59
|
-
#################################o
|
60
|
-
|
61
|
-
# deals = Deal.find(:all)
|
62
|
-
# deals = Deal.find(:all, params: {per_page: 5, page: 2})
|
63
|
-
# deals = Deal.find(:all, params: {conditions: {deal_name: 'blah'}})
|
64
|
-
# deals = Deal.where(conditions: {deal_name: 'blah'})
|
65
|
-
|
66
|
-
|
67
|
-
#################################o
|
68
|
-
# creating
|
69
|
-
#################################o
|
70
|
-
|
71
|
-
deal = Deal.new(name: 'yeah2')
|
72
|
-
20.times {deal.save }
|