Skip to content

Commit dc17a0c

Browse files
committed
Merge pull request #98 from ryanhertz/messages-updates
Messages updates
2 parents 9dc98b1 + 6ee96df commit dc17a0c

File tree

6 files changed

+120
-4
lines changed

6 files changed

+120
-4
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v1.3.24
2+
- added replies method and finders to message class
3+
- added to_param method to base class
4+
15
v1.3.23
26
- remove ruby 1.9 hash syntax
37

lib/spark_api/models/base.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ def persisted?;
125125
!@attributes['Id'].nil? && !@attributes['ResourceUri'].nil?
126126
end
127127

128+
def to_param
129+
attributes['Id']
130+
end
131+
128132
protected
129133

130134
def write_attribute(attribute, value)

lib/spark_api/models/message.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module SparkApi
22
module Models
33
class Message < Base
4+
extend Finders
45
self.element_name="messages"
56

67
def save(arguments={})
@@ -13,11 +14,17 @@ def save(arguments={})
1314
end
1415
false
1516
end
17+
1618
def save!(arguments={})
1719
results = connection.post self.class.path, {"Messages" => [ attributes ]}, arguments
1820
true
1921
end
20-
22+
23+
def replies(args = {})
24+
arguments = {:_expand => "Body, Sender"}.merge(args)
25+
Message.collect(connection.get("#{self.class.path}/#{self.Id}/replies", arguments))
26+
end
27+
2128
end
2229
end
2330
end

spec/fixtures/messages/get.json

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"D": {
3+
"Success": true,
4+
"Results": [
5+
{
6+
"Id": "20110353423434130982000000",
7+
"ResourceUri": "/v1/messages/20110353423434130982000000",
8+
"Type": "ShowingRequest",
9+
"SenderId": "20110112234857732941000000",
10+
"Sender": {
11+
"Id": "20110112234857732941000000",
12+
"ResourceUri": "/v1/accounts/20110112234857732941000000",
13+
"UserType": "Member",
14+
"Name": "Joe Realtor",
15+
"OfficeId": "20100113238853732842000000",
16+
"Office": "Joe's Realty",
17+
"CompanyId": null,
18+
"Company": null
19+
},
20+
"RecipientIds": ["20120212334957232744000000"],
21+
"Recipients": [{
22+
"Id": "20120212334957232744000000",
23+
"ResourceUri": "/v1/accounts/20120212334957232744000000",
24+
"UserType": "Member",
25+
"Name": "Sue Realtor",
26+
"OfficeId": "20100113238853732842000000",
27+
"Office": "Joe's Realty",
28+
"CompanyId": null,
29+
"Company": null
30+
}],
31+
"ThreadInfo": {
32+
"HasReplies": true,
33+
"UnreadInThread": true
34+
},
35+
"Subject": "Showing Request For 123 Main St, MLS # 12-345",
36+
"Body": "A showing is requested for ...",
37+
"ListingId": "20110112234857732941000000",
38+
"ReplyToId": null,
39+
"RecipientIds": "20130212233857332441000000",
40+
"CreatedTimestamp": "2013-06-11T11:00:00",
41+
"ModificationTimestamp": "2013-06-11T11:00:00"
42+
},
43+
{
44+
"Id": "20110353423434130982000000",
45+
"ResourceUri": "/v1/messages/20110353423434130982000000",
46+
"Type": "ShowingRequest",
47+
"SenderId": "20110112234857732941000000",
48+
"Sender": {
49+
"Id": "20110112234857732941000000",
50+
"ResourceUri": "/v1/accounts/20110112234857732941000000",
51+
"UserType": "Member",
52+
"Name": "Joe Realtor",
53+
"OfficeId": "20100113238853732842000000",
54+
"Office": "Joe's Realty",
55+
"CompanyId": null,
56+
"Company": null
57+
},
58+
"RecipientIds": ["20120212334957232744000000"],
59+
"Recipients": [{
60+
"Id": "20120212334957232744000000",
61+
"ResourceUri": "/v1/accounts/20120212334957232744000000",
62+
"UserType": "Member",
63+
"Name": "Sue Realtor",
64+
"OfficeId": "20100113238853732842000000",
65+
"Office": "Joe's Realty",
66+
"CompanyId": null,
67+
"Company": null
68+
}],
69+
"ThreadInfo": {
70+
"HasReplies": true,
71+
"UnreadInThread": true
72+
},
73+
"Subject": "Showing Request For 123 Main St, MLS # 12-345",
74+
"Body": "A showing is requested for ...",
75+
"ListingId": "20110112234857732941000000",
76+
"ReplyToId": null,
77+
"RecipientIds": "20130212233857332441000000",
78+
"CreatedTimestamp": "2013-06-11T11:00:00",
79+
"ModificationTimestamp": "2013-06-11T11:00:00"
80+
}
81+
]
82+
}
83+
}

spec/formatters/api_support_formatter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Formatter to support documenting currently-implemented API paths and
44
# methods. This borrows heavily from the standard
55
# DocumentationFormatter, but excludes example groups not related
6-
# tagged with :support. It also formats examples withe a :method tag
6+
# tagged with :support. It also formats examples with a :method tag
77
# with the HTTP method and path ahead of the example description.
88
class ApiSupportFormatter < RSpec::Core::Formatters::DocumentationFormatter
99

spec/unit/spark_api/models/message_spec.rb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
end
1919

2020
context "/messages", :support do
21-
on_get_it "should get all my messages"
21+
on_get_it "should get all my messages" do
22+
stub_api_get("/messages", 'messages/get.json')
23+
messages = Message.find(:all)
24+
messages.size.should == 2
25+
end
2226

2327
on_post_it "should save a new message" do
2428
stub_api_post("/messages", 'messages/new.json', 'messages/post.json')
@@ -42,6 +46,20 @@
4246
end
4347

4448
context "/messages/<message_id>", :support do
45-
on_get_it "should get a single message"
49+
on_get_it "should get a single message" do
50+
subject.attributes["Id"] = "20110353423434130982000000"
51+
stub_api_get("/messages/#{subject.Id}", "messages/get.json")
52+
subject.should be_a(Message)
53+
end
4654
end
55+
56+
context "/messages/<message_id>/replies", :support do
57+
on_get_it "should get all the replies" do
58+
subject.attributes["Id"] = "20110353423434130982000000"
59+
stub_api_get("/messages/#{subject.Id}/replies", "messages/get.json", :_expand => 'Body, Sender')
60+
subject.replies.size.should == 2
61+
end
62+
63+
end
64+
4765
end

0 commit comments

Comments
 (0)