Skip to content

Commit

Permalink
Merge pull request #152 from ryanhertz/unread-messages
Browse files Browse the repository at this point in the history
added unread and unread_count methods to Message
  • Loading branch information
ryanhertz authored Jun 27, 2018
2 parents 7851212 + 8f4427c commit b09f3d4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v1.4.26
- added `unread` and `unread_count` methods to `Message`

v1.4.25
- add request_id reader to error and response classes
- log request_id on successful requests (debug level)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.25
1.4.26
8 changes: 8 additions & 0 deletions lib/spark_api/models/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ def replies(args = {})
Message.collect(connection.get("#{self.class.path}/#{self.Id}/replies", arguments))
end

def self.unread(args={})
collect(connection.get("#{path}/unread", args))
end

def self.unread_count
unread _pagination: 'count'
end

end
end
end
12 changes: 12 additions & 0 deletions spec/fixtures/messages/count.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"D": {
"Success": true,
"Results": [],
"Pagination": {
"TotalRows": 78,
"PageSize": 25,
"TotalPages": 4,
"CurrentPage": 1
}
}
}
16 changes: 16 additions & 0 deletions spec/unit/spark_api/models/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,20 @@

end

context "/messages/unread", :support do

on_get_it "gets unread messages" do
stub_api_get("/messages/unread", 'messages/get.json', {})
messages = Message.unread
messages.size.should == 2
messages.first.should be_a Message
end

on_get_it "gets unread messages count" do
stub_api_get("/messages/unread", 'messages/count.json', _pagination: 'count')
Message.unread_count.should == 78
end

end

end

0 comments on commit b09f3d4

Please sign in to comment.