pipejump 0.2.0
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.
- data/.document +5 -0
- data/.gitignore +25 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +25 -0
- data/LICENSE +20 -0
- data/README.rdoc +120 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/lib/pipejump/base/collection.rb +117 -0
- data/lib/pipejump/base/connection.rb +54 -0
- data/lib/pipejump/base/errors.rb +11 -0
- data/lib/pipejump/base/resource.rb +182 -0
- data/lib/pipejump/base/session.rb +172 -0
- data/lib/pipejump/resources/account.rb +20 -0
- data/lib/pipejump/resources/client.rb +162 -0
- data/lib/pipejump/resources/contact.rb +225 -0
- data/lib/pipejump/resources/deal.rb +246 -0
- data/lib/pipejump/resources/note.rb +159 -0
- data/lib/pipejump/resources/reminder.rb +171 -0
- data/lib/pipejump/resources/source.rb +159 -0
- data/lib/pipejump.rb +19 -0
- data/spec/connection.sample.yml +3 -0
- data/spec/pipejump/resources/client_spec.rb +119 -0
- data/spec/pipejump/resources/contact_spec.rb +93 -0
- data/spec/pipejump/resources/deal_spec.rb +115 -0
- data/spec/pipejump/resources/note_spec.rb +100 -0
- data/spec/pipejump/resources/reminder_spec.rb +120 -0
- data/spec/pipejump/resources/source_spec.rb +91 -0
- data/spec/pipejump/session_spec.rb +44 -0
- data/spec/spec_helper.rb +12 -0
- metadata +117 -0
@@ -0,0 +1,246 @@
|
|
1
|
+
module Pipejump
|
2
|
+
|
3
|
+
# A Deal is represented by an instance of Pipejump::Deal.
|
4
|
+
#
|
5
|
+
# *Note*: To access any deals, you need a valid Session instance, referred to as @session in the following examples.
|
6
|
+
#
|
7
|
+
# == Access
|
8
|
+
#
|
9
|
+
# === Collection
|
10
|
+
#
|
11
|
+
# To fetch a collection of Pipejump::Deal instances, call
|
12
|
+
#
|
13
|
+
#
|
14
|
+
# @session.deals
|
15
|
+
# # => #<Pipejump::Collection resource: Pipejump::Deal>
|
16
|
+
#
|
17
|
+
#
|
18
|
+
# This returns a Pipejump::Collection instance. To retrieve an array of Pipejump::Deal instances, call the _all_ method on the collection:
|
19
|
+
#
|
20
|
+
#
|
21
|
+
# @session.deals.all
|
22
|
+
# # => [#<Pipejump::Deal name: "Good Deal", scope: "0", hot: "false", stage_name: "incoming", deal_tags: "", id: "1">,
|
23
|
+
# # #<Pipejump::Deal name: "Ok Deal", scope: "0", hot: "false", stage_name: "incoming", deal_tags: "", id: "2">]
|
24
|
+
#
|
25
|
+
#
|
26
|
+
# Instead of _all_, you can also call a variety of Array methods in the collection which will be delegated to the array returned by _all_, such as:
|
27
|
+
#
|
28
|
+
# * first
|
29
|
+
# * last
|
30
|
+
# * each
|
31
|
+
# * size
|
32
|
+
# * collect
|
33
|
+
# * reject
|
34
|
+
#
|
35
|
+
# *Examples*:
|
36
|
+
#
|
37
|
+
# @session.deals.first
|
38
|
+
# # => #<Pipejump::Deal name: "Good Deal", scope: "0", hot: "false", stage_name: "incoming", deal_tags: "", id: "1">
|
39
|
+
# @session.deals.last
|
40
|
+
# # => #<Pipejump::Deal name: "Ok Deal", scope: "0", hot: "false", stage_name: "incoming", deal_tags: "", id: "2">
|
41
|
+
# @session.deals.size
|
42
|
+
# # => 2
|
43
|
+
# @session.deals.each { |deal| puts deal.name }
|
44
|
+
# # Prints out "Good Deal" and "Ok Deal"
|
45
|
+
# @session.deals.collect { |deal| deal.name }
|
46
|
+
# # => ["Good Deal", "Ok Deal"]
|
47
|
+
# @session.deals.reject { |deal| deal.name == 'Good Deal' }
|
48
|
+
# # => ["Ok Deal"]
|
49
|
+
#
|
50
|
+
#
|
51
|
+
# === Resource
|
52
|
+
#
|
53
|
+
# To fetch a single deal, call the _find_ method with the deal id as an argument:
|
54
|
+
#
|
55
|
+
#
|
56
|
+
# @session.deals.find(1)
|
57
|
+
# # => #<Pipejump::Deal name: "Good Deal", scope: "0", hot: "false", stage_name: "incoming", deal_tags: "", id: "1">
|
58
|
+
#
|
59
|
+
#
|
60
|
+
# == Creation
|
61
|
+
#
|
62
|
+
# *Note*: Deals require the following fields in the hash of attributes:
|
63
|
+
#
|
64
|
+
# * _name_: a valid name
|
65
|
+
# * _client_id_: a valid a Client id
|
66
|
+
#
|
67
|
+
# To create a new deal, call the _create_ method on the Deal Pipejump::Collection with a hash of attributes as an argument.
|
68
|
+
#
|
69
|
+
#
|
70
|
+
# @session.deals.create(:name => 'Great Deal', :client_id => 1)
|
71
|
+
# # => #<Pipejump::Deal name: "Great Deal", scope: "0", hot: "false", stage_name: "incoming", deal_tags: "", id: "3">
|
72
|
+
#
|
73
|
+
#
|
74
|
+
# If the deal was created properly, it will be returned with a id assigned to it. You can check it by calling the created? method
|
75
|
+
#
|
76
|
+
#
|
77
|
+
# deal = @session.deals.create(:name => 'Great Deal', :client_id => 1)
|
78
|
+
# # => #<Pipejump::Deal name: "Great Deal", scope: "0", hot: "false", stage_name: "incoming", deal_tags: "", id: "3">
|
79
|
+
# deal.created?
|
80
|
+
# # => true
|
81
|
+
# deal = @session.deals.create(:name => '')
|
82
|
+
# # => #<Pipejump::Deal name: "">
|
83
|
+
# deal.created?
|
84
|
+
# # => false
|
85
|
+
#
|
86
|
+
#
|
87
|
+
# You can access validation/creation errors by calling the _errors_ method on the instance returned by _create_:
|
88
|
+
#
|
89
|
+
#
|
90
|
+
# deal = @session.deals.create(:name => '')
|
91
|
+
# # => #<Pipejump::Deal name: "">
|
92
|
+
# deal.created?
|
93
|
+
# # => false
|
94
|
+
# deal.errors
|
95
|
+
# # => {"deal"=>[{"error"=>{"code"=>"E0001", "field"=>"name", "description"=>"Please enter a deal name"}},
|
96
|
+
# # {"error"=>{"code"=>"E0001", "field"=>"client", "description"=>"Please enter a valid client id"}}]}
|
97
|
+
#
|
98
|
+
#
|
99
|
+
# == Update
|
100
|
+
#
|
101
|
+
# To update a deal, change the attributes and call the _save_ method.
|
102
|
+
#
|
103
|
+
# === Changing attributes
|
104
|
+
#
|
105
|
+
# Each attribute has an accessor which you can use to change the values:
|
106
|
+
#
|
107
|
+
#
|
108
|
+
# deal = @session.deals.create(:name => 'Great Deal', :client_id => 1)
|
109
|
+
# # => #<Pipejump::Deal name: "Great Deal", scope: "0", hot: "false", stage_name: "incoming", deal_tags: "", id: "3">
|
110
|
+
# deal.name
|
111
|
+
# # => 'Great Deal'
|
112
|
+
# deal.name = 'Super Deal'
|
113
|
+
# # => 'Super Deal'
|
114
|
+
# deal.name
|
115
|
+
# # => 'Super Deal'
|
116
|
+
#
|
117
|
+
#
|
118
|
+
# === Saving
|
119
|
+
#
|
120
|
+
# Once you've changed the attributes, call the _save_ method on the deal instance:
|
121
|
+
#
|
122
|
+
#
|
123
|
+
# deal = @session.deals.create(:name => 'Great Deal', :client_id => 1)
|
124
|
+
# # => #<Pipejump::Deal name: "Great Deal", scope: "0", hot: "false", stage_name: "incoming", deal_tags: "", id: "3">
|
125
|
+
# deal.name = 'Super Deal'
|
126
|
+
# # => 'Super Deal'
|
127
|
+
# deal.save
|
128
|
+
# # => true
|
129
|
+
#
|
130
|
+
#
|
131
|
+
# _save_ returns _true_ if save was successful and _false_ if it failed. In the latter scenario, you can access the errors via the _errors_ method:
|
132
|
+
#
|
133
|
+
#
|
134
|
+
# deal = @session.deals.create(:name => 'Great Deal', :client_id => 1)
|
135
|
+
# # => #<Pipejump::Deal name: "Great Deal", scope: "0", hot: "false", stage_name: "incoming", deal_tags: "", id: "3">
|
136
|
+
# deal.name = 'Super Deal'
|
137
|
+
# # => 'Super Deal'
|
138
|
+
# deal.save
|
139
|
+
# # => true
|
140
|
+
# deal.name = ''
|
141
|
+
# # => ''
|
142
|
+
# deal.save
|
143
|
+
# # => false
|
144
|
+
# deal.errors
|
145
|
+
# # => {"deal"=>[{"error"=>{"code"=>"E0001", "field"=>"name", "description"=>"Please enter a deal name"}} ]}
|
146
|
+
#
|
147
|
+
#
|
148
|
+
# == Removal
|
149
|
+
#
|
150
|
+
# You cannot remove a deal, you can move it between stages
|
151
|
+
#
|
152
|
+
# == Changing stages
|
153
|
+
#
|
154
|
+
# To change a Deal stage, change the value of the _stage_name_ attribute to one of the following:
|
155
|
+
#
|
156
|
+
# * incoming
|
157
|
+
# * qualified
|
158
|
+
# * quote
|
159
|
+
# * closure
|
160
|
+
# * won
|
161
|
+
# * lost
|
162
|
+
# * unqualified
|
163
|
+
#
|
164
|
+
# Afterwards, save the deal to update the Deal stage.
|
165
|
+
#
|
166
|
+
#
|
167
|
+
# deal = @session.deals.create(:name => 'Great Deal', :client_id => 1)
|
168
|
+
# # => #<Pipejump::Deal name: "Great Deal", scope: "0", hot: "false", stage_name: "incoming", deal_tags: "", id: "3">
|
169
|
+
# deal.stage_name = 'qualified'
|
170
|
+
# # => 'qualified'
|
171
|
+
# deal.save
|
172
|
+
# # => true
|
173
|
+
#
|
174
|
+
#
|
175
|
+
# == Contacts
|
176
|
+
#
|
177
|
+
# You can access Deal Contacts assigned to a deal by calling _contacts_ on an instance of a Deal:
|
178
|
+
#
|
179
|
+
#
|
180
|
+
# @deal.contacts
|
181
|
+
#
|
182
|
+
#
|
183
|
+
# For more information, consult the Deal Contacts page.
|
184
|
+
#
|
185
|
+
# == Notes
|
186
|
+
#
|
187
|
+
# You can access Notes of a specific deal by calling _notes_ on an instance of a Deal:
|
188
|
+
#
|
189
|
+
#
|
190
|
+
# @deal.notes
|
191
|
+
#
|
192
|
+
#
|
193
|
+
# For more information, consult the Notes page.
|
194
|
+
#
|
195
|
+
# == Reminders
|
196
|
+
#
|
197
|
+
# You can access Reminders of a specific deal by calling _reminders_ on an instance of a Deal:
|
198
|
+
#
|
199
|
+
#
|
200
|
+
# @deal.reminders
|
201
|
+
#
|
202
|
+
#
|
203
|
+
# For more information, consult the Reminders page.
|
204
|
+
class Deal < Resource
|
205
|
+
belongs_to :client
|
206
|
+
has_many :contacts do
|
207
|
+
disable :find, :create
|
208
|
+
|
209
|
+
# Updates the Contact resources assigned to a deal
|
210
|
+
#
|
211
|
+
# Accepts the following arguments:
|
212
|
+
# * String:
|
213
|
+
# @deal.contacts.update('1, 2')
|
214
|
+
# * Array of integers:
|
215
|
+
# @deal.contacts.update([1, 2])
|
216
|
+
# * Array of Resource objects:
|
217
|
+
# @deal.contacts.update([@contact.id, @contact2.id])
|
218
|
+
# * mixed Array of Resource objects and integers:
|
219
|
+
# @deal.contacts.update([1, @contact2])
|
220
|
+
def update(ids) #:nodoc:
|
221
|
+
if ids.is_a?(Array)
|
222
|
+
ids = ids.collect { |element|
|
223
|
+
if element.is_a?(Pipejump::Resource)
|
224
|
+
element.id
|
225
|
+
elsif element.is_a?(Fixnum)
|
226
|
+
element
|
227
|
+
end
|
228
|
+
}
|
229
|
+
ids = ids.compact.join(',')
|
230
|
+
end
|
231
|
+
code, data = @session.put(collection_path + '/update', "contact_ids=#{ids}")
|
232
|
+
code == 200
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|
236
|
+
|
237
|
+
has_many :notes
|
238
|
+
has_many :reminders
|
239
|
+
|
240
|
+
def to_query #:nodoc:
|
241
|
+
@attributes.collect { |pair| pair[0] = "#{pair[0]}"; pair.join('=') }.join('&')
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|
245
|
+
|
246
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
module Pipejump
|
2
|
+
|
3
|
+
# The Notes resource is represented by an instance of Pipejump::Note.
|
4
|
+
#
|
5
|
+
# *Note*: To access any Notes, you need a valid Deal instance, referred to as @deal in the following examples. Notes belong to a deal, so you can only access them via @deal, not the session.
|
6
|
+
#
|
7
|
+
# == Access
|
8
|
+
#
|
9
|
+
# === Collection
|
10
|
+
#
|
11
|
+
# To fetch a collection of Pipejump::Note instances, call
|
12
|
+
#
|
13
|
+
#
|
14
|
+
# @deal.notes
|
15
|
+
# # => #<Pipejump::Collection resource: Pipejump::Note, owner: #<Pipejump::Deal name: "My Deal", scope: "0", hot: "false", stage_name: "incoming", id: "1", deal_tags: "">>
|
16
|
+
#
|
17
|
+
#
|
18
|
+
# This returns a Pipejump::Collection instance. To retrieve an array of Pipejump::Note instances, call the _all_ method on the collection:
|
19
|
+
#
|
20
|
+
#
|
21
|
+
# @deal.notes.all
|
22
|
+
# # => [#<Pipejump::Note content: "My Note", id: "1">, #<Pipejump::Note content: "Another Note", id: "2">]
|
23
|
+
#
|
24
|
+
#
|
25
|
+
# Instead of _all_, you can also call a variety of Array methods in the collection which will be delegated to the array returned by _all_, such as:
|
26
|
+
#
|
27
|
+
# * first
|
28
|
+
# * last
|
29
|
+
# * each
|
30
|
+
# * size
|
31
|
+
# * collect
|
32
|
+
# * reject
|
33
|
+
#
|
34
|
+
# *Examples*:
|
35
|
+
#
|
36
|
+
# @deal.notes.first
|
37
|
+
# # => #<Pipejump::Note content: "My Note", id: "1">
|
38
|
+
# @deal.notes.last
|
39
|
+
# # => #<Pipejump::Note content: "Another Note", id: "2">
|
40
|
+
# @deal.notes.size
|
41
|
+
# # => 2
|
42
|
+
# @deal.notes.each { |note| puts note.content }
|
43
|
+
# # Prints out "My Note" and "Another Note"
|
44
|
+
# @deal.notes.collect { |note| note.content }
|
45
|
+
# # => ["My Note", "Another Note"]
|
46
|
+
# @deal.notes.reject { |note| note.content == 'My Note' }
|
47
|
+
# # => ["Another Note"]
|
48
|
+
#
|
49
|
+
#
|
50
|
+
# === Resource
|
51
|
+
#
|
52
|
+
# To fetch a single resource, call the _find_ method with the resource id as an argument:
|
53
|
+
#
|
54
|
+
#
|
55
|
+
# @deal.notes.find(1)
|
56
|
+
# # => #<Pipejump::Note content: "My Note", id: "1">
|
57
|
+
#
|
58
|
+
#
|
59
|
+
# == Creation
|
60
|
+
#
|
61
|
+
# *Note*: Notes require the following fields in the hash of attributes:
|
62
|
+
#
|
63
|
+
# * _content_: Note content
|
64
|
+
#
|
65
|
+
# To create a new note, call the _create_ method on the Note Pipejump::Collection with a hash of attributes as an argument:
|
66
|
+
#
|
67
|
+
#
|
68
|
+
# @deal.notes.create(:content => 'Third Note')
|
69
|
+
# # => #<Pipejump::Note content: "Third Note", id: "3">
|
70
|
+
#
|
71
|
+
#
|
72
|
+
# If the resource was created properly, it will be returned with a id assigned to it. You can check it by calling the created? method
|
73
|
+
#
|
74
|
+
#
|
75
|
+
# note = @deal.notes.create(:content => 'Third Note')
|
76
|
+
# # => #<Pipejump::Note content: "Third Note", id: "3">
|
77
|
+
# note.created?
|
78
|
+
# # => true
|
79
|
+
# note = @deal.notes.create(:content => '')
|
80
|
+
# # => #<Pipejump::Note content: "">
|
81
|
+
# note.created?
|
82
|
+
# # => false
|
83
|
+
#
|
84
|
+
#
|
85
|
+
# You can access validation/creation errors by calling the _errors_ method on the instance returned by _create_:
|
86
|
+
#
|
87
|
+
#
|
88
|
+
# note = @deal.notes.create(:content => '')
|
89
|
+
# # => #<Pipejump::Note content: "">
|
90
|
+
# note.created?
|
91
|
+
# # => false
|
92
|
+
# note.errors
|
93
|
+
# # => {"note"=>[{"error"=>{"code"=>"E0001", "field"=>"content", "description"=>"Please enter note's message"}}]}
|
94
|
+
#
|
95
|
+
#
|
96
|
+
# == Update
|
97
|
+
#
|
98
|
+
# To update a resource, change the attributes and call the _save_ method.
|
99
|
+
#
|
100
|
+
# === Changing attributes
|
101
|
+
#
|
102
|
+
# Each attribute has an accessor which you can use to change the values:
|
103
|
+
#
|
104
|
+
#
|
105
|
+
# note = @deal.notes.create(:content => 'Third Note')
|
106
|
+
# # => #<Pipejump::Note content: "Third Note", id: "3">
|
107
|
+
# note.content
|
108
|
+
# # => 'Third Note'
|
109
|
+
# note.content = 'Super Note'
|
110
|
+
# # => 'Super Note'
|
111
|
+
# note.content
|
112
|
+
# # => 'Super Note'
|
113
|
+
#
|
114
|
+
#
|
115
|
+
# === Saving
|
116
|
+
#
|
117
|
+
# Once you've changed the attributes, call the _save_ method on the resource instance:
|
118
|
+
#
|
119
|
+
#
|
120
|
+
# note = @deal.notes.create(:content => 'Third Note')
|
121
|
+
# # => #<Pipejump::Note content: "Third Note", id: "3">
|
122
|
+
# note.content
|
123
|
+
# # => 'Third Note'
|
124
|
+
# note.save
|
125
|
+
# # => true
|
126
|
+
#
|
127
|
+
#
|
128
|
+
# _save_ returns _true_ if save was successful and _false_ if it failed. In the latter scenario, you can access the errors via the _errors_ method:
|
129
|
+
#
|
130
|
+
#
|
131
|
+
# note = @deal.notes.create(:content => 'Third Note')
|
132
|
+
# # => #<Pipejump::Note content: "Third Note", id: "3">
|
133
|
+
# note.content = 'Super Note'
|
134
|
+
# # => 'Super Note'
|
135
|
+
# note.save
|
136
|
+
# # => true
|
137
|
+
# note.content = ''
|
138
|
+
# # => ''
|
139
|
+
# note.save
|
140
|
+
# # => false
|
141
|
+
# note.errors
|
142
|
+
# # => {"note"=>[{"error"=>{"code"=>"E0001", "field"=>"content", "description"=>"Please enter note's message"}}]}
|
143
|
+
#
|
144
|
+
#
|
145
|
+
# == Removal
|
146
|
+
#
|
147
|
+
# To remove a resource, call the _destroy_ method on the instance:
|
148
|
+
#
|
149
|
+
#
|
150
|
+
# note = @deal.notes.find(1)
|
151
|
+
# # => #<Pipejump::Note content: "My Note", id: "1">
|
152
|
+
# note.destroy
|
153
|
+
# # => true
|
154
|
+
#
|
155
|
+
|
156
|
+
class Note < Resource
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
module Pipejump
|
2
|
+
|
3
|
+
# The Reminders resource is represented by an instance of Pipejump::Reminder.
|
4
|
+
#
|
5
|
+
# *Reminder*: To access any Reminders, you need a valid Deal instance, referred to as @deal in the following examples. Reminders belong to a deal, so you can only access them via @deal, not the session.
|
6
|
+
#
|
7
|
+
# == Access
|
8
|
+
#
|
9
|
+
# === Collection
|
10
|
+
#
|
11
|
+
# To fetch a collection of Pipejump::Reminder instances, call
|
12
|
+
#
|
13
|
+
#
|
14
|
+
# @deal.reminders
|
15
|
+
# # => #<Pipejump::Collection resource: Pipejump::Reminder, owner: #<Pipejump::Deal name: "My Deal", scope: "0", hot: "false", stage_name: "incoming", id: "1", deal_tags: "">>
|
16
|
+
#
|
17
|
+
#
|
18
|
+
# This returns a Pipejump::Collection instance. To retrieve an array of Pipejump::Reminder instances, call the _all_ method on the collection:
|
19
|
+
#
|
20
|
+
#
|
21
|
+
# @deal.reminders.all
|
22
|
+
# # => [#<Pipejump::Reminder done: "false", time: "14:00", id: "1", date: "2010-11-11", content: "My Reminder">,
|
23
|
+
# # #<Pipejump::Reminder done: "false", time: "16:00", id: "2", date: "2010-11-11", content: "Another Reminder">]
|
24
|
+
#
|
25
|
+
#
|
26
|
+
# Instead of _all_, you can also call a variety of Array methods in the collection which will be delegated to the array returned by _all_, such as:
|
27
|
+
#
|
28
|
+
# * first
|
29
|
+
# * last
|
30
|
+
# * each
|
31
|
+
# * size
|
32
|
+
# * collect
|
33
|
+
# * reject
|
34
|
+
#
|
35
|
+
# *Examples*:
|
36
|
+
#
|
37
|
+
# @deal.reminders.first
|
38
|
+
# # => #<Pipejump::Reminder done: "false", time: "14:00", id: "1", date: "2010-11-11", content: "My Reminder">
|
39
|
+
# @deal.reminders.last
|
40
|
+
# # => #<Pipejump::Reminder done: "false", time: "16:00", id: "2", date: "2010-11-11", content: "Another Reminder">
|
41
|
+
# @deal.reminders.size
|
42
|
+
# # => 2
|
43
|
+
# @deal.reminders.each { |reminder| puts reminder.content }
|
44
|
+
# # Prints out "My Reminder" and "Another Reminder"
|
45
|
+
# @deal.reminders.collect { |reminder| reminder.content }
|
46
|
+
# # => ["My Reminder", "Another Reminder"]
|
47
|
+
# @deal.reminders.reject { |reminder| reminder.content == 'My Reminder' }
|
48
|
+
# # => ["Another Reminder"]
|
49
|
+
#
|
50
|
+
#
|
51
|
+
# === Resource
|
52
|
+
#
|
53
|
+
# To fetch a single resource, call the _find_ method with the resource id as an argument:
|
54
|
+
#
|
55
|
+
#
|
56
|
+
# @deal.reminders.find(1)
|
57
|
+
# # => #<Pipejump::Reminder done: "false", time: "14:00", id: "1", date: "2010-11-11", content: "My Reminder">
|
58
|
+
#
|
59
|
+
#
|
60
|
+
# == Creation
|
61
|
+
#
|
62
|
+
# *Reminder*: Reminders require the following fields in the hash of attributes:
|
63
|
+
#
|
64
|
+
# * _content_: Reminder content
|
65
|
+
# * _date_: Date for the Reminder (ex. 2010-11-11)
|
66
|
+
# * _time_: Time for the Reminder (ex. 14:00)
|
67
|
+
#
|
68
|
+
# To create a new reminder, call the _create_ method on the Reminder Pipejump::Collection with a hash of attributes as an argument:
|
69
|
+
#
|
70
|
+
#
|
71
|
+
# @deal.reminders.create(:content => 'Third Reminder', :date => '2010-11-11', :time => '19:00'})
|
72
|
+
# # => #<Pipejump::Reminder done: "false", time: "19:00", id: "3", date: "2010-11-11", content: "Third Reminder">
|
73
|
+
#
|
74
|
+
#
|
75
|
+
# If the resource was created properly, it will be returned with a id assigned to it. You can check it by calling the created? method
|
76
|
+
#
|
77
|
+
#
|
78
|
+
# reminder = @deal.reminders.create(:content => 'Third Reminder', :date => '2010-11-11', :time => '19:00'})
|
79
|
+
# # => #<Pipejump::Reminder done: "false", time: "19:00", id: "3", date: "2010-11-11", content: "Third Reminder">
|
80
|
+
# reminder.created?
|
81
|
+
# # => true
|
82
|
+
# reminder = @deal.reminders.create(:content => '')
|
83
|
+
# # => #<Pipejump::Reminder content: "">
|
84
|
+
# reminder.created?
|
85
|
+
# # => false
|
86
|
+
#
|
87
|
+
#
|
88
|
+
# You can access validation/creation errors by calling the _errors_ method on the instance returned by _create_:
|
89
|
+
#
|
90
|
+
#
|
91
|
+
# reminder = @deal.reminders.create(:content => '')
|
92
|
+
# # => #<Pipejump::Reminder content: "">
|
93
|
+
# reminder.created?
|
94
|
+
# # => false
|
95
|
+
# reminder.errors
|
96
|
+
# # => {"reminder"=>[{"error"=>{"code"=>"E0000", "field"=>"time", "description"=>"The time and date must be in the future"}},
|
97
|
+
# # {"error"=>{"code"=>"E0001", "field"=>"date", "description"=>"The time and date must be in the future"}},
|
98
|
+
# # {"error"=>{"code"=>"E0001", "field"=>"content", "description"=>"can't be blank"}}]}
|
99
|
+
#
|
100
|
+
#
|
101
|
+
# == Update
|
102
|
+
#
|
103
|
+
# To update a resource, change the attributes and call the _save_ method.
|
104
|
+
#
|
105
|
+
# === Changing attributes
|
106
|
+
#
|
107
|
+
# Each attribute has an accessor which you can use to change the values:
|
108
|
+
#
|
109
|
+
#
|
110
|
+
# reminder = @deal.reminders.create(:content => 'Third Reminder', :date => '2010-11-11', :time => '19:00'})
|
111
|
+
# # => #<Pipejump::Reminder done: "false", time: "19:00", id: "3", date: "2010-11-11", content: "Third Reminder">
|
112
|
+
# reminder.content
|
113
|
+
# # => 'Third Reminder'
|
114
|
+
# reminder.content = 'Super Reminder'
|
115
|
+
# # => 'Super Reminder'
|
116
|
+
# reminder.content
|
117
|
+
# # => 'Super Reminder'
|
118
|
+
#
|
119
|
+
#
|
120
|
+
# === Saving
|
121
|
+
#
|
122
|
+
# Once you've changed the attributes, call the _save_ method on the resource instance:
|
123
|
+
#
|
124
|
+
#
|
125
|
+
# reminder = @deal.reminders.create(:content => 'Third Reminder', :date => '2010-11-11', :time => '19:00'})
|
126
|
+
# # => #<Pipejump::Reminder done: "false", time: "19:00", id: "3", date: "2010-11-11", content: "Third Reminder">
|
127
|
+
# reminder.content
|
128
|
+
# # => 'Third Reminder'
|
129
|
+
# reminder.save
|
130
|
+
# # => true
|
131
|
+
#
|
132
|
+
#
|
133
|
+
# _save_ returns _true_ if save was successful and _false_ if it failed. In the latter scenario, you can access the errors via the _errors_ method:
|
134
|
+
#
|
135
|
+
#
|
136
|
+
# reminder = @deal.reminders.create(:content => 'Third Reminder', :date => '2010-11-11', :time => '19:00'})
|
137
|
+
# # => #<Pipejump::Reminder done: "false", time: "19:00", id: "3", date: "2010-11-11", content: "Third Reminder">
|
138
|
+
# reminder.content = 'Super Reminder'
|
139
|
+
# # => 'Super Reminder'
|
140
|
+
# reminder.save
|
141
|
+
# # => true
|
142
|
+
# reminder.content = ''
|
143
|
+
# # => ''
|
144
|
+
# reminder.save
|
145
|
+
# # => false
|
146
|
+
# reminder.errors
|
147
|
+
# # => {"reminder"=>[{"error"=>{"code"=>"E0001", "field"=>"content", "description"=>"can't be blank"}}]}
|
148
|
+
#
|
149
|
+
#
|
150
|
+
# == Removal
|
151
|
+
#
|
152
|
+
# To remove a resource, call the _destroy_ method on the instance:
|
153
|
+
#
|
154
|
+
#
|
155
|
+
# reminder = @deal.reminders.find(1)
|
156
|
+
# # => #<Pipejump::Reminder content: "My Reminder", id: "1">
|
157
|
+
# reminder.destroy
|
158
|
+
# # => true
|
159
|
+
#
|
160
|
+
|
161
|
+
class Reminder < Resource
|
162
|
+
|
163
|
+
def before_save #:nodoc:
|
164
|
+
if @attributes['date'].is_a?(Time)
|
165
|
+
@attributes['date'] = @attributes['date'].strftime('%Y-%m-%d')
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|