storify 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/storify.rb +4 -1
- data/lib/storify/client.rb +45 -10
- data/spec/client_spec.rb +60 -0
- data/spec/storify_spec.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ea74fc535ab92ebe6cb8edd98f0a35d6837caf5
|
4
|
+
data.tar.gz: ed3769c9487cde3762e7a638e0ae1f905544bd46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39692374a62ada22814db5f7b073367720ecfc4ba939b4455da746663d14d0573df18fbf6e0265b319469fed88de9139a504c6afda4a2be36f66c569d4b1917f
|
7
|
+
data.tar.gz: 5edc0ec592ae14b2c363f55072b0fb3a5682ed5d6058d3eace8facdd337f8198acfd48c4d544c9e9383462e5d466788feacfce2be14c4b9bf0c2415bc4ff17a8
|
data/lib/storify.rb
CHANGED
@@ -20,7 +20,10 @@ module Storify
|
|
20
20
|
:users => '/users',
|
21
21
|
:userprofile => '/users/:username',
|
22
22
|
:update_profile => '/users/:username/update',
|
23
|
-
:publish => '/stories/:username/:slug/publish'
|
23
|
+
:publish => '/stories/:username/:slug/publish',
|
24
|
+
:save => '/stories/:username/:slug/save',
|
25
|
+
:create => '/stories/:username/create',
|
26
|
+
:delete => '/stories/:username/:slug/delete'
|
24
27
|
}
|
25
28
|
}
|
26
29
|
|
data/lib/storify/client.rb
CHANGED
@@ -151,7 +151,47 @@ module Storify
|
|
151
151
|
end
|
152
152
|
|
153
153
|
def publish(story, options: {})
|
154
|
+
story_update(story, :publish, options: options)
|
155
|
+
end
|
156
|
+
|
157
|
+
def save(story, options: {})
|
158
|
+
story_update(story, :save, options: options)
|
159
|
+
end
|
160
|
+
|
161
|
+
def create(story, publish = false, options: {})
|
162
|
+
raise "Not a Story" unless story.is_a?(Storify::Story)
|
163
|
+
|
164
|
+
endpoint = Storify::endpoint(version: options[:version],
|
165
|
+
protocol: options[:protocol],
|
166
|
+
method: :create,
|
167
|
+
params: {':username' => username})
|
168
|
+
|
169
|
+
data = call(endpoint, :POST, params: {:publish => publish,
|
170
|
+
:story => story.to_json})
|
171
|
+
|
172
|
+
data['content']['slug']
|
173
|
+
end
|
174
|
+
|
175
|
+
def delete(slug, username = @username, options: {})
|
176
|
+
endpoint = Storify::endpoint(version: options[:version],
|
177
|
+
protocol: options[:protocol],
|
178
|
+
method: :delete,
|
179
|
+
params: {':username' => username,
|
180
|
+
':slug' => slug})
|
181
|
+
|
182
|
+
data = call(endpoint, :POST)
|
183
|
+
|
184
|
+
true
|
185
|
+
end
|
186
|
+
|
187
|
+
def authenticated
|
188
|
+
!@token.nil?
|
189
|
+
end
|
190
|
+
|
154
191
|
|
192
|
+
private
|
193
|
+
|
194
|
+
def story_update(story, method, options: {})
|
155
195
|
# ensure we have a story w/slug and author
|
156
196
|
raise "Not a Story" unless story.is_a?(Storify::Story)
|
157
197
|
raise "No slug found" if story.slug.nil?
|
@@ -162,24 +202,17 @@ module Storify
|
|
162
202
|
username = story.author.username
|
163
203
|
endpoint = Storify::endpoint(version: options[:version],
|
164
204
|
protocol: options[:protocol],
|
165
|
-
method:
|
205
|
+
method: method,
|
166
206
|
params: {':username' => username,
|
167
207
|
':slug' => slug})
|
168
208
|
|
169
|
-
# attempt to publish
|
209
|
+
# attempt to update (publish or save)
|
170
210
|
json = story.to_json
|
171
211
|
data = call(endpoint, :POST, params: {:story => json})
|
172
|
-
true
|
173
|
-
end
|
174
|
-
|
175
212
|
|
176
|
-
|
177
|
-
!@token.nil?
|
213
|
+
true
|
178
214
|
end
|
179
215
|
|
180
|
-
|
181
|
-
private
|
182
|
-
|
183
216
|
def story_list(method, pager, params: {}, options: {}, use_auth: true, uparams: {})
|
184
217
|
endpoint = Storify::endpoint(version: options[:version],
|
185
218
|
protocol: options[:protocol],
|
@@ -224,6 +257,8 @@ module Storify
|
|
224
257
|
data = JSON.parse(e.response)
|
225
258
|
error = data['error']
|
226
259
|
|
260
|
+
puts error.inspect
|
261
|
+
|
227
262
|
return Storify::error(data['code'], error['message'], error['type'], end_of_content: EOC)
|
228
263
|
end
|
229
264
|
|
data/spec/client_spec.rb
CHANGED
@@ -187,6 +187,66 @@ describe Storify::Client do
|
|
187
187
|
end
|
188
188
|
end
|
189
189
|
|
190
|
+
context "POST /stories/:username/:slug/save" do
|
191
|
+
it "should save an existing story" do
|
192
|
+
story = @client.story('no-embeds', @username)
|
193
|
+
element = Storify::Element.new.extend(Storify::ElementRepresentable)
|
194
|
+
element.data = Storify::StoryData.new.extend(Storify::StoryDataRepresentable)
|
195
|
+
element.data.text = "Added new text item"
|
196
|
+
|
197
|
+
# add new element via permalink to end of story
|
198
|
+
story.elements << element
|
199
|
+
|
200
|
+
@client.save(story).should == true
|
201
|
+
|
202
|
+
# publish changes to make them retrievable
|
203
|
+
@client.publish(story).should == true
|
204
|
+
|
205
|
+
# updated
|
206
|
+
revised = @client.story('no-embeds', @username)
|
207
|
+
revised.elements.length.should == 1
|
208
|
+
|
209
|
+
# test removal
|
210
|
+
revised.elements = []
|
211
|
+
@client.save(revised).should == true
|
212
|
+
@client.publish(revised).should == true
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
context "POST /stories/:username/create" do
|
217
|
+
it "should create a story with multiple elements" do
|
218
|
+
story = Storify::Story.new.extend(Storify::StoryRepresentable)
|
219
|
+
story.title = "Another Story"
|
220
|
+
|
221
|
+
story.elements = []
|
222
|
+
story.elements << Storify::Element.new.extend(Storify::ElementRepresentable)
|
223
|
+
story.elements << Storify::Element.new.extend(Storify::ElementRepresentable)
|
224
|
+
story.elements << Storify::Element.new.extend(Storify::ElementRepresentable)
|
225
|
+
|
226
|
+
# add text data item
|
227
|
+
item = story.elements[0]
|
228
|
+
item.data = Storify::StoryData.new.extend(Storify::StoryDataRepresentable)
|
229
|
+
item.data.text = "Start of the story..."
|
230
|
+
|
231
|
+
# add twitter link
|
232
|
+
item = story.elements[1]
|
233
|
+
item.permalink = "http://twitter.com/fmquaglia/status/409875377482264577"
|
234
|
+
|
235
|
+
# twitter link with image
|
236
|
+
item = story.elements[2]
|
237
|
+
item.permalink = "http://twitter.com/NicholleJ/status/407924506380861441"
|
238
|
+
|
239
|
+
slug = @client.create(story, true)
|
240
|
+
slug.should_not eql ""
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
context "POST /stories/:username/:slug/delete" do
|
245
|
+
it "should delete the specified story" do
|
246
|
+
@client.delete('another-story', @username).should == true
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
190
250
|
context "Serialization" do
|
191
251
|
it "should allow a story to be serialized as text" do
|
192
252
|
story = @client.story('austin-startup-digest-for-december-9-2014', 'joshuabaer')
|
data/spec/storify_spec.rb
CHANGED
@@ -89,6 +89,18 @@ describe Storify do
|
|
89
89
|
it "should support the Update User Profile endpoint" do
|
90
90
|
Storify::ENDPOINTS[:v1][:update_profile].should == "/users/:username/update"
|
91
91
|
end
|
92
|
+
|
93
|
+
it "should support the Save Story endpoint" do
|
94
|
+
Storify::ENDPOINTS[:v1][:save].should == "/stories/:username/:slug/save"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should support the Create Story endpoint" do
|
98
|
+
Storify::ENDPOINTS[:v1][:create].should == "/stories/:username/create"
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should support the Delete Story endpoint (undocumented)" do
|
102
|
+
Storify::ENDPOINTS[:v1][:delete].should == "/stories/:username/:slug/delete"
|
103
|
+
end
|
92
104
|
end
|
93
105
|
|
94
106
|
context "API Endpoint URI Builder:" do
|