|
74 | 74 | end |
75 | 75 |
|
76 | 76 | it "allows optional params" do |
77 | | - client.interactions_by_update_id(id, page: 2) |
| 77 | + response =<<EOF |
| 78 | +{ |
| 79 | + "total":2, |
| 80 | + "interactions":[ |
| 81 | + { |
| 82 | + "_id":"50f98310c5ac415d7f2e74fd", |
| 83 | + "created_at":1358509258, |
| 84 | + "event":"favorite", |
| 85 | + "id":"50f98310c5ac415d7f2e74fd", |
| 86 | + "interaction_id":"292235127847788544", |
| 87 | + "user":{ |
| 88 | + "username":"Crispy Potatoes", |
| 89 | + "followers":160, |
| 90 | + "avatar":"http:\/\/si0.twimg.com\/profile_images\/...", |
| 91 | + "avatar_https":"https:\/\/si0.twimg.com\/profile_images\/...", |
| 92 | + "twitter_id":"70712344376" |
| 93 | + } |
| 94 | + }, |
| 95 | + { |
| 96 | + "_id":"50f8623ac5ac415d7f1d4f77", |
| 97 | + "created_at":1358454592, |
| 98 | + "event":"retweet", |
| 99 | + "id":"50f8623ac5ac415d7f1d4f77", |
| 100 | + "interaction_id":"292005842654461953", |
| 101 | + "user":{ |
| 102 | + "username":"Lucky Number 8", |
| 103 | + "followers":36079, |
| 104 | + "avatar":"http:\/\/si0.twimg.com\/profile_images\/2901468678\/...", |
| 105 | + "avatar_https":"https:\/\/si0.twimg.com\/profile_images\/2901468678\/...", |
| 106 | + "twitter_id":"1423444249" |
| 107 | + } |
| 108 | + } |
| 109 | + ] |
| 110 | +} |
| 111 | +EOF |
| 112 | + stub_request(:get, "https://api.bufferapp.com/1/updates/4ecda476542f7ee521000006/interactions.json?access_token=some_token&count=3&event=favorite&page=2"). |
| 113 | + with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.8.7'}). |
| 114 | + to_return(:status => 200, :body => response, :headers => {}) |
| 115 | + client.interactions_by_update_id(id, page: 2, count: 3, event: "favorite") |
78 | 116 | end |
79 | 117 | end |
80 | 118 |
|
|
103 | 141 | stub_request(:post, %r{https://api\.bufferapp\.com/1/profiles/4ecda256512f7ee521000001/updates/reorder\.json\?access_token=.*}). |
104 | 142 | with(:body => {"order"=>["4ecda256512f7ee521000001", "4ecda256512f7ee521000001", "4ecda256512f7ee521000001"]}, |
105 | 143 | :headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Faraday v0.8.7'}). |
106 | | - to_return(:status => 200, :body => "", :headers => {}) |
| 144 | + to_return(:status => 200, :body => reorder_updates_body_response, :headers => {}) |
107 | 145 | client.reorder_updates(id_no, order_hash) |
108 | | - |
109 | 146 | end |
110 | 147 | end |
111 | 148 |
|
112 | 149 | describe "#shuffle_updates" do |
113 | 150 | it "connects to appropriate endpoint" do |
114 | 151 | id_no = "4ecda256512f7ee521000001" |
115 | 152 | stub_request(:post, %r{https://api\.bufferapp\.com/1/profiles/4ecda256512f7ee521000001/updates/shuffle\.json\?access_token=.*}). |
116 | | - with(:body => {"count"=>"10"}) |
| 153 | + with(:body => {"count"=>"10"}). |
| 154 | + to_return(:status => 200, :body => '{"success": true, |
| 155 | + "updates": [], |
| 156 | + "time_to_shuffle":0.0041220188140869}') |
117 | 157 | client.shuffle_updates(id_no, count: 10) |
118 | 158 | end |
119 | 159 | end |
| 160 | + |
120 | 161 | describe "#share_update" do |
121 | 162 | it "should connect to correct endpoint" do |
122 | 163 | stub_request(:post, %r{https://api\.bufferapp\.com/1/updates/4ecda256512f7ee521000001/share\.json\?access_token=.*}). |
123 | | - to_return(:status => 200, :body => "{'success': true}", :headers => {}) |
| 164 | + to_return(:status => 200, :body => '{"success": true}', :headers => {}) |
124 | 165 | update_id = "4ecda256512f7ee521000001" |
125 | 166 | client.share_update(update_id) |
126 | 167 | end |
127 | 168 | end |
128 | 169 |
|
| 170 | + describe "#create_update" do |
| 171 | + |
| 172 | + let(:body_content) do {text: "Text for an update", |
| 173 | + profile_ids: [ |
| 174 | + "4eb854340acb04e870000010", |
| 175 | + "4eb9276e0acb04bb81000067" |
| 176 | + ]} |
| 177 | + end |
| 178 | + |
| 179 | + let(:url) { %r{https://api\.bufferapp\.com/1/updates/create\.json\?access_token=.*} } |
| 180 | + |
| 181 | + context "should create an update" do |
| 182 | + it "when only required params are present" do |
| 183 | + stub_request(:post, url). |
| 184 | + with(:body => body_content). |
| 185 | + to_return(:status => 200, :body => create_update_return_body, :headers => {}) |
| 186 | + client.create_update(body: body_content) |
| 187 | + end |
| 188 | + it "when optional params are included" do |
| 189 | + body_content[:media] = {} |
| 190 | + body_content[:media][:link] = "http://google.com" |
| 191 | + body_content[:media][:description] = "Google Homepage" |
| 192 | + stub_request(:post, url). |
| 193 | + with(:body => body_content). |
| 194 | + to_return(:status => 200, :body => create_update_return_body, :headers => {}) |
| 195 | + client.create_update(body: body_content) |
| 196 | + |
| 197 | + end |
| 198 | + end |
| 199 | + end |
| 200 | + |
| 201 | + describe "#modify_update_text" do |
| 202 | + |
| 203 | + let(:body_content) { {text: "Text for an updated text for update"} } |
| 204 | + |
| 205 | + id = "4ecda256512f7ee521000004" |
| 206 | + let(:url) { %r{https://api\.bufferapp\.com/1/updates/#{ id }/update\.json\?access_token=.*} } |
| 207 | + |
| 208 | + context "should modify an update" do |
| 209 | + it "when params are present" do |
| 210 | + stub_request(:post, url). |
| 211 | + with(:body => body_content). |
| 212 | + to_return(:status => 200, :body => modify_update_response, :headers => {}) |
| 213 | + Pry.rescue do |
| 214 | + client.modify_update_text(id, body: body_content) |
| 215 | + end |
| 216 | + end |
| 217 | + end |
| 218 | + end |
| 219 | + |
129 | 220 | describe "#destroy_update" do |
130 | 221 | it "connects to correct endpoint" do |
131 | 222 | stub_request(:post, %r{https://api\.bufferapp\.com/1/updates/4ecda256512f7ee521000001/destroy\.json\?access_token=.*}). |
|
0 commit comments