From 1f6cdeb75122353955964bc62d7b17a66b728fa5 Mon Sep 17 00:00:00 2001 From: Lancelot Carlson Date: Fri, 22 Dec 2017 02:41:14 -0500 Subject: [PATCH 1/2] support rspec its, fix tests --- spec/spec_helper.rb | 1 + streak-ruby.gemspec | 1 + 2 files changed, 2 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c60c01d..b463e6a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- require 'streak' +require 'rspec/its' #monkeypatch request methods module Streak diff --git a/streak-ruby.gemspec b/streak-ruby.gemspec index c429364..bbc88b2 100644 --- a/streak-ruby.gemspec +++ b/streak-ruby.gemspec @@ -24,4 +24,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "bundler", "~> 1.3" spec.add_development_dependency "rake" spec.add_development_dependency "rspec" + spec.add_development_dependency "rspec-its" end From 9078b0f23e258ff632c0a7fad29009f444ac6c28 Mon Sep 17 00:00:00 2001 From: Lancelot Carlson Date: Fri, 22 Dec 2017 03:31:11 -0500 Subject: [PATCH 2/2] thread support --- lib/streak.rb | 1 + lib/streak/thread.rb | 14 ++++++++++++++ spec/spec_helper.rb | 27 +++++++++++++++++++++++++++ spec/streak/thread_spec.rb | 24 ++++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 lib/streak/thread.rb create mode 100644 spec/streak/thread_spec.rb diff --git a/lib/streak.rb b/lib/streak.rb index d63854a..461900e 100644 --- a/lib/streak.rb +++ b/lib/streak.rb @@ -15,6 +15,7 @@ require "streak/user" require "streak/search" require "streak/file" +require "streak/thread" module Streak @api_base = "https://www.streak.com/api/v1" diff --git a/lib/streak/thread.rb b/lib/streak/thread.rb new file mode 100644 index 0000000..d1ea0c8 --- /dev/null +++ b/lib/streak/thread.rb @@ -0,0 +1,14 @@ +module Streak + class Thread < StreakObject + def self.all(box_key) + path = "/boxes/#{box_key}/threads" + res = Streak.request(:get, path) + convert_to_streak_object(res, Thread) + end + + def self.find(key) + res = Streak.request(:get, "/threads/#{key}") + convert_to_streak_object(res, Thread) + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b463e6a..253e516 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -165,3 +165,30 @@ def test_user(params={}) "key" => "agptYWlsZm9vZ2FlciYLEgxPcmdhbml6YXRpb24iCnN0cmVhay5jb20MCxIEVXNlchgBDA" }.merge(params) end + +def test_thread(params={}) + { + "creatorKey": "agptYWlsZm9vZ2FlciYLEgxPcmdhbml6YXRpb24iCnN0cmVhay5jb20MCxIEVXNlchgBDA", + "boxKey": "agptYWlsZm9vZ2FlciYLEgxPcmdhbml6YXRpb24iCnN0cmVhay5jb20MCxIEQ2FzZRgJDA", + "pipelineKey": "agptYWlsZm9vZ2FlcioLEgxPcmdhbml6YXRpb24iCnN0cmVhay5jb20MCxIIV29ya2Zsb3cYBQw", + "creationTimestamp": 1367889076605, + "lastUpdatedTimestamp": 1367889076605, + "lastEmailTimestamp": 1367886197000, + "subject": "Re: Some email subject line", + "names": [ + "Adam Smith", + "Betty Smith", + "Carl Jones" + ], + "emailAddresses": [ + "asmith@example.com", + "bsmith@example.com", + "carl.jones@gmail.com" + ], + "threadGmailId": "13e7c4bcce4c3693", + "fileKeys": [], + "files": [], + "gmailThreadKey": "agptYWlsZm9vZ2Flci0LEgxPcmdhbml6YXRpb24iCnN0cmVhay5jb20MCxILR21haWxUaHJlYWQYKQw", + "key": "agptYWlsZm9vZ2Flci0LEgxPcmdhbml6YXRpb24iCnN0cmVhay5jb20MCxILR21haWxUaHJlYWQYKQw" + }.merge(params) +end diff --git a/spec/streak/thread_spec.rb b/spec/streak/thread_spec.rb new file mode 100644 index 0000000..10e0456 --- /dev/null +++ b/spec/streak/thread_spec.rb @@ -0,0 +1,24 @@ +describe Streak::Thread do + let!(:api) { Streak.mock_rest_client = double('RestClient') } + let(:thread) { test_thread } + + describe ".all" do + it "should call the api" do + api.should_receive(:get). + with(Streak.api_url("/boxes/box_key_1/threads"), nil, nil). + and_return(test_response([thread])) + + Streak::Thread.all("box_key_1") + end + end + + describe ".find" do + it "should call the api" do + api.should_receive(:get). + with(Streak.api_url("/threads/thread_key_1"), nil, nil). + and_return(test_response(thread)) + + Streak::Thread.find("thread_key_1") + end + end +end