storify 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/fixtures/vcr_cassettes/auth.yml +119 -0
  3. data/fixtures/vcr_cassettes/create.yml +71 -0
  4. data/fixtures/vcr_cassettes/delete.yml +63 -0
  5. data/fixtures/vcr_cassettes/edit_slug.yml +162 -0
  6. data/fixtures/vcr_cassettes/featured.yml +28991 -0
  7. data/fixtures/vcr_cassettes/latest.yml +13835 -0
  8. data/fixtures/vcr_cassettes/popular.yml +17002 -0
  9. data/fixtures/vcr_cassettes/profile.yml +86 -0
  10. data/fixtures/vcr_cassettes/profile_update.yml +238 -0
  11. data/fixtures/vcr_cassettes/publish.yml +352 -0
  12. data/fixtures/vcr_cassettes/save.yml +462 -0
  13. data/fixtures/vcr_cassettes/search.yml +4528 -0
  14. data/fixtures/vcr_cassettes/stories.yml +8505 -0
  15. data/fixtures/vcr_cassettes/story.yml +1194 -0
  16. data/fixtures/vcr_cassettes/topic.yml +31207 -0
  17. data/fixtures/vcr_cassettes/users.yml +1877 -0
  18. data/fixtures/vcr_cassettes/userstories.yml +843 -0
  19. data/lib/storify.rb +1 -1
  20. data/lib/storify/client.rb +30 -35
  21. data/lib/storify/storymeta.rb +2 -1
  22. data/lib/storify/string.rb +10 -0
  23. data/spec/client_auth_spec.rb +28 -15
  24. data/spec/client_edit_slug_spec.rb +30 -0
  25. data/spec/client_profile_spec.rb +19 -0
  26. data/spec/client_profile_update_spec.rb +57 -0
  27. data/spec/client_spec.rb +24 -237
  28. data/spec/client_stories_featured_spec.rb +28 -0
  29. data/spec/client_stories_latest_spec.rb +28 -0
  30. data/spec/client_stories_popular_spec.rb +28 -0
  31. data/spec/client_stories_search_spec.rb +29 -0
  32. data/spec/client_stories_spec.rb +28 -0
  33. data/spec/client_stories_topic_spec.rb +35 -0
  34. data/spec/client_story_create_spec.rb +40 -0
  35. data/spec/client_story_delete_spec.rb +19 -0
  36. data/spec/client_story_publish_spec.rb +74 -0
  37. data/spec/client_story_save_spec.rb +43 -0
  38. data/spec/client_story_spec.rb +46 -0
  39. data/spec/client_users_spec.rb +28 -0
  40. data/spec/client_userstories_spec.rb +32 -0
  41. data/spec/pager_spec.rb +41 -46
  42. data/spec/spec_helper.rb +41 -18
  43. data/spec/storify_spec.rb +73 -72
  44. metadata +97 -4
  45. data/spec/client_noauth_spec.rb +0 -120
@@ -50,12 +50,12 @@ module Storify
50
50
  end
51
51
  end
52
52
 
53
-
54
53
  require 'storify/client'
55
54
  require 'storify/pager'
56
55
  require 'storify/apierror'
57
56
 
58
57
  # base types
58
+ require 'storify/string'
59
59
  require 'storify/features'
60
60
  require 'storify/dategroup'
61
61
  require 'storify/coverphoto'
@@ -17,28 +17,19 @@ module Storify
17
17
  yield self if block_given?
18
18
  end
19
19
 
20
+
20
21
  def auth(password, options: {})
21
22
  endpoint = Storify::endpoint(version: options[:version], method: :auth)
22
- data = call(endpoint, :POST, params: {password: password})
23
+ data = call(endpoint, :POST, params: merge_params!(params: {password: password}))
23
24
  @token = data['content']['_token']
24
25
 
25
26
  self
26
27
  end
27
28
 
28
- def stories(pager: nil, options: {})
29
- story_list(:stories, pager, options: options, use_auth: false)
30
- end
31
-
32
- def latest(pager: nil, options: {})
33
- story_list(:latest, pager, options: options, use_auth: false)
34
- end
35
-
36
- def featured(pager: nil, options: {})
37
- story_list(:featured, pager, options: options, use_auth: false)
38
- end
39
-
40
- def popular(pager: nil, options: {})
41
- story_list(:popular, pager, options: options, use_auth: false)
29
+ %w(stories latest featured popular).each do |m|
30
+ define_method(m) do |pager: nil, options: {}|
31
+ story_list(m.to_sym, pager, options: options, use_auth: false)
32
+ end
42
33
  end
43
34
 
44
35
  def topic(topic, pager: nil, options: {})
@@ -68,7 +59,8 @@ module Storify
68
59
  elements = []
69
60
 
70
61
  begin
71
- data = call(endpoint, :GET, paging: pager.to_hash)
62
+ p = merge_params!(paging: pager.to_hash)
63
+ data = call(endpoint, :GET, params: p)
72
64
  json = JSON.generate(data['content'])
73
65
 
74
66
  if story.nil?
@@ -96,7 +88,7 @@ module Storify
96
88
  method: :editslug,
97
89
  params: params)
98
90
 
99
- data = call(endpoint, :POST, params: {slug: new_slug})
91
+ data = call(endpoint, :POST, params: merge_params!(params: {slug: new_slug}))
100
92
  data['content']['slug']
101
93
  end
102
94
 
@@ -109,7 +101,8 @@ module Storify
109
101
  users = []
110
102
 
111
103
  begin
112
- data = call(endpoint, :GET, paging: pager.to_hash, use_auth: false)
104
+ p = merge_params!(paging: pager.to_hash, use_auth: false)
105
+ data = call(endpoint, :GET, params: p)
113
106
  content = data['content']
114
107
 
115
108
  content['users'].each do |s|
@@ -123,7 +116,7 @@ module Storify
123
116
  users
124
117
  end
125
118
 
126
- def profile(username = @usernmae, options: {})
119
+ def profile(username = @username, options: {})
127
120
  endpoint = Storify::endpoint(version: options[:version],
128
121
  protocol: options[:protocol],
129
122
  method: :userprofile,
@@ -145,7 +138,7 @@ module Storify
145
138
  params: {':username' => username})
146
139
 
147
140
  json = user.to_json
148
- data = call(endpoint, :POST, params: {:user => json})
141
+ data = call(endpoint, :POST, params: merge_params!(params: {:user => json}))
149
142
 
150
143
  true
151
144
  end
@@ -166,8 +159,8 @@ module Storify
166
159
  method: :create,
167
160
  params: {':username' => username})
168
161
 
169
- data = call(endpoint, :POST, params: {:publish => publish,
170
- :story => story.to_json})
162
+ p = merge_params!(params: {:publish => publish, :story => story.to_json})
163
+ data = call(endpoint, :POST, params: p)
171
164
 
172
165
  data['content']['slug']
173
166
  end
@@ -179,7 +172,7 @@ module Storify
179
172
  params: {':username' => username,
180
173
  ':slug' => slug})
181
174
 
182
- data = call(endpoint, :POST)
175
+ data = call(endpoint, :POST, params: merge_params!)
183
176
 
184
177
  true
185
178
  end
@@ -208,7 +201,7 @@ module Storify
208
201
 
209
202
  # attempt to update (publish or save)
210
203
  json = story.to_json
211
- data = call(endpoint, :POST, params: {:story => json})
204
+ data = call(endpoint, :POST, params: merge_params!(params: {:story => json}))
212
205
 
213
206
  true
214
207
  end
@@ -223,7 +216,9 @@ module Storify
223
216
  stories = []
224
217
 
225
218
  begin
226
- data = call(endpoint, :GET, paging: pager.to_hash, use_auth: use_auth, params: uparams)
219
+ p = merge_params!(params: uparams, paging: pager.to_hash, use_auth: use_auth)
220
+
221
+ data = call(endpoint, :GET, params: p)
227
222
  content = data['content']
228
223
 
229
224
  content['stories'].each do |s|
@@ -237,28 +232,28 @@ module Storify
237
232
  stories
238
233
  end
239
234
 
240
- def call(endpoint, verb, params: {}, paging: {}, opts: {}, use_auth: true)
235
+ def merge_params!(params: {}, paging: {}, use_auth: true)
236
+ params.merge!(paging)
237
+ params[:username] = @username
238
+ params[:api_key] = @api_key
239
+ params[:_token] = @token if (authenticated && use_auth)
240
+ params
241
+ end
242
+
243
+ def call(endpoint, verb, params: {}, opts: {})
241
244
  raw = nil
242
245
 
243
246
  begin
244
- # add paging and auth query params
245
- params.merge!(paging)
246
- params[:username] = @username
247
- params[:api_key] = @api_key
248
- params[:_token] = @token if (authenticated && use_auth)
249
-
250
247
  case verb
251
248
  when :POST
252
249
  raw = RestClient.post endpoint, params, {:accept => :json}
253
250
  when :GET
254
- raw = RestClient.get endpoint, {:params => params}
251
+ raw = RestClient.get endpoint, {:params => params, :accept => :json}
255
252
  end
256
253
  rescue => e
257
254
  data = JSON.parse(e.response)
258
255
  error = data['error']
259
256
 
260
- puts error.inspect
261
-
262
257
  return Storify::error(data['code'], error['message'], error['type'], end_of_content: EOC)
263
258
  end
264
259
 
@@ -11,6 +11,7 @@ module Storify
11
11
 
12
12
  collection :quoted, :class => Storify::Quotable, :extend => Storify::QuotableRepresentable
13
13
  collection :hashtags
14
- property :created_with, :class => Storify::CreatedWith, :extend => Storify::CreatedWithRepresentable
14
+ property :created_with, :class => lambda { |fragment, *| fragment.respond_to?(:has_key?) ? Storify::CreatedWith : String },
15
+ :extend => lambda { |name, *| name.is_a?(Storify::CreatedWith) ? Storify::CreatedWithRepresentable : Storify::StringRepresentable }
15
16
  end
16
17
  end
@@ -0,0 +1,10 @@
1
+ require 'representable/json'
2
+
3
+ module Storify
4
+ module StringRepresentable
5
+ include Representable::JSON
6
+
7
+ def to_hash(*); self; end
8
+ def from_hash(hsh, *args); hsh; end
9
+ end
10
+ end
@@ -1,30 +1,43 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Storify::Client do
4
- before(:each) do
5
- @client = Storify::Client.new(:api_key => @api_key, :username => @username)
6
- end
4
+ context "#auth" do
5
+ let(:client) {Storify::Client.new(:api_key => @api_key, :username => @username)}
6
+
7
+ it "receives a token on success" do
8
+ VCR.use_cassette('auth', :decode_compressed_response => true) do
9
+ client.auth(get_password)
10
+ end
7
11
 
8
- context "Authentication" do
9
- it "should retrieve an auth token on success" do
10
- @client.auth(get_password).token.should_not be_nil
11
- @client.authenticated.should be_true
12
+ expect(client.authenticated).to be_true
12
13
  end
13
14
 
14
- it "should raise an API error on failure" do
15
- expect{@client.auth('invalid_password')}.to raise_error(Storify::ApiError)
15
+ it "raises an API Error on failure" do
16
+ expect(client.authenticated).to be_false
17
+
18
+ VCR.use_cassette('auth') do
19
+ expect{client.auth('')}.to raise_error(Storify::ApiError)
20
+ end
16
21
  end
17
22
 
18
- it "should accept endpoint options (version)" do
23
+ it "accepts endpoint options: version" do
19
24
  options = {:version => :v1}
20
- @client.auth(get_password, options: options)
21
- @client.authenticated.should be_true
25
+
26
+ VCR.use_cassette('auth', :decode_compressed_response => true) do
27
+ client.auth(get_password, options: options)
28
+ end
29
+
30
+ expect(client.authenticated).to be_true
22
31
  end
23
32
 
24
- it "should ignore endpoint options (protocol, method)" do
33
+ it "ignores endpoint options: protocol, method" do
25
34
  options = {:method => :unknown, :protocol => :insecure}
26
- @client.auth(get_password, options: options)
27
- @client.authenticated.should be_true
35
+
36
+ VCR.use_cassette('auth', :decode_compressed_response => true) do
37
+ client.auth(get_password, options: options)
38
+ end
39
+
40
+ expect(client.authenticated).to be_true
28
41
  end
29
42
  end
30
43
  end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Storify::Client do
4
+ let(:options) { {:version => :v1, :protocol => :insecure} }
5
+ let(:pager) { Storify::Pager.new(page: 1, max: 1, per_page: 10) }
6
+ let(:slug1) { 'getting-started' }
7
+ let(:slug2) { 'storify-is-awesome' }
8
+ let(:tape) { 'edit_slug' }
9
+ let(:client) do
10
+ VCR.use_cassette('auth') do
11
+ Storify::Client.new(:api_key => @api_key, :username => @username).auth(get_password)
12
+ end
13
+ end
14
+
15
+ context "#edit_slug [POST /stories/:username/:story-slug/editslug]" do
16
+ it "responds with the new slug name" do
17
+ VCR.use_cassette(tape) do
18
+ expect(client.edit_slug(@username, slug1, slug2)).to eql slug2
19
+ expect(client.edit_slug(@username, slug2, slug1)).to eql slug1
20
+ end
21
+ end
22
+
23
+ it "responds with the new slug name using options: version, protocol" do
24
+ VCR.use_cassette(tape, :match_requests_on => vcr_ignore_protocol) do
25
+ expect(client.edit_slug(@username, slug1, slug2, options: options)).to eql slug2
26
+ expect(client.edit_slug(@username, slug2, slug1, options: options)).to eql slug1
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Storify::Client do
4
+ let(:options) { {:version => :v1, :protocol => :insecure} }
5
+ let(:tape) { 'profile' }
6
+ let(:client) do
7
+ VCR.use_cassette('auth') do
8
+ Storify::Client.new(:api_key => @api_key, :username => @username).auth(get_password)
9
+ end
10
+ end
11
+
12
+ context "#profile [GET /users/:username]" do
13
+ it "gets a user profile" do
14
+ VCR.use_cassette(tape) do
15
+ expect(client.profile(@username).username).to eql @username
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe Storify::Client do
4
+ let(:options) { {:version => :v1, :protocol => :insecure} }
5
+ let(:user) { Storify::User.new.extend(Storify::UserRepresentable) }
6
+ let(:not_found) { 'mock_user$$$$' }
7
+ let(:tape) { 'profile_update' }
8
+ let(:rloc) { "This is a new location" }
9
+ let(:client) do
10
+ VCR.use_cassette('auth') do
11
+ Storify::Client.new(:api_key => @api_key, :username => @username).auth(get_password)
12
+ end
13
+ end
14
+
15
+ context "#update_profile [POST /users/:username/update]" do
16
+ it "raises an exception if a user is not provided" do
17
+ VCR.use_cassette(tape) do
18
+ expect{client.update_profile(nil)}.to raise_exception
19
+ end
20
+ end
21
+
22
+ it "raises an exception if the user is not found" do
23
+ VCR.use_cassette(tape) do
24
+ user.username = not_found
25
+ expect{client.update_profile(user)}.to raise_exception(Storify::ApiError)
26
+ end
27
+ end
28
+
29
+ it "raises an exception if the user is not found using options" do
30
+ VCR.use_cassette(tape, :match_requests_on => vcr_ignore_protocol) do
31
+ user.username = not_found
32
+ expect{client.update_profile(user, options: options)}.to raise_exception(Storify::ApiError)
33
+ end
34
+ end
35
+
36
+ it "raises an exception if the profile cannot be updated" do
37
+ VCR.use_cassette(tape) do
38
+ user.username = "storify"
39
+ expect{client.update_profile(user)}.to raise_exception(Storify::ApiError)
40
+ end
41
+ end
42
+
43
+ it "rejects profile updates for free plans" do
44
+ u = nil
45
+
46
+ VCR.use_cassette('profile') do
47
+ u = client.profile(@username)
48
+ u.location = rloc
49
+ end
50
+
51
+ VCR.use_cassette(tape) do
52
+ expect(u.paid_plan).to eql "free"
53
+ expect{client.update_profile(u)}.to raise_exception(Storify::ApiError)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,256 +1,43 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Storify::Client do
4
- before(:all) do
5
- @client = Storify::Client.new(:api_key => @api_key, :username => @username)
6
- @client.auth(get_password)
7
- end
4
+ let(:key) { 'k' }
5
+ let(:usr) { 'u' }
6
+ let(:tok) { 't' }
8
7
 
9
8
  context ".new" do
10
- it "should accept a hash of credentials (api_key, username, token)" do
11
- clients = [Storify::Client.new(:api_key => 'k', :username => 'u', :token => 't'),
12
- Storify::Client.new('api_key' => 'k', 'username' => 'u', 'token' => 't')]
9
+ it "accepts a hash of credentials as symbols" do
10
+ client = Storify::Client.new(:api_key => key, :username => usr, :token => tok)
11
+ expect(client.api_key).to eql key
12
+ expect(client.username).to eql usr
13
+ expect(client.token).to eql tok
14
+ end
13
15
 
14
- clients.each do |c|
15
- c.api_key.should == 'k'
16
- c.username.should == 'u'
17
- c.token.should == 't'
18
- end
16
+ it "accepts a hash of credentials as strings" do
17
+ client = Storify::Client.new('api_key' => key, 'username' => usr, 'token' => tok)
18
+ expect(client.api_key).to eql key
19
+ expect(client.username).to eql usr
20
+ expect(client.token).to eql tok
19
21
  end
20
22
 
21
- it "should accept a configuration block of credentials" do
23
+ it "accepts a block of credentials" do
22
24
  client = Storify::Client.new do |config|
23
- config.api_key = 'YOUR API KEY'
24
- config.username = 'YOUR USERNAME'
25
- config.token = 'YOUR AUTH TOKEN'
25
+ config.api_key = key
26
+ config.username = usr
27
+ config.token = tok
26
28
  end
27
29
 
28
- client.api_key.should == 'YOUR API KEY'
30
+ expect(client.api_key).to eql key
31
+ expect(client.username).to eql usr
32
+ expect(client.token).to eql tok
29
33
  end
30
34
 
31
- it "should raise an exception for unknown credentials" do
35
+ it "raises an exception for unknown hash credentials" do
32
36
  expect {Storify::Client.new(:unknown => 'value')}.to raise_exception
33
- expect {Storify::Client.new {|config| config.unknown = ''}}.to raise_exception
34
- end
35
- end
36
-
37
- context "GET /stories/:username" do
38
- it "should get all stories for a specific user" do
39
- @client.userstories(@username).length.should >= 2
40
- end
41
-
42
- it "should accept endpoint options (version, protocol)" do
43
- options = {:version => :v1, :protocol => :insecure}
44
- @client.userstories(@username, options: options).length.should >= 2
45
- end
46
-
47
- it "should accept paging options (Pager)" do
48
- pager = Storify::Pager.new(page: 1, max: 1, per_page: 10)
49
- stories = @client.userstories('joshuabaer', pager: pager)
50
- stories.length.should == 10
51
- end
52
- end
53
-
54
- context "GET /stories/:username/:slug" do
55
- before(:all) do
56
- puts "Enter a Story-Slug for your Account:"
57
- @slug = STDIN.gets.chomp
58
- end
59
-
60
- it "should get a specific story for a user (all pages)" do
61
- @client.story(@slug).elements.length.should == 3
62
- end
63
-
64
- it "should accept endpoint options (version, protocol)" do
65
- options = {:version => :v1, :protocol => :insecure}
66
- @client.story(@slug, options: options).elements.length.should == 3
67
- end
68
-
69
- it "should accept paging options (Page)" do
70
- pager = Storify::Pager.new(page: 2, max: 3)
71
- story = @client.story('austin-startup-digest-for-december-9-2014', 'joshuabaer', pager: pager)
72
- story = story.to_s
73
-
74
- ['408651138632667136', '409182832234213376'].each {|s| story.include?(s).should be_true }
75
- end
76
- end
77
-
78
- context "POST /stories/:username/:story-slug/editslug" do
79
- before(:all) do
80
- puts "Enter a Story-Slug for your Account:"
81
- @slug1 = STDIN.gets.chomp
82
-
83
- puts "Enter a New Unique Story-Slug for your Account"
84
- @slug2 = STDIN.gets.chomp
85
- end
86
-
87
- it "should respond with the new slug name (on a successful change)" do
88
- @client.edit_slug(@username, @slug1, @slug2).should == @slug2
89
- @client.edit_slug(@username, @slug2, @slug1).should == @slug1
90
- end
91
-
92
- it "should accept endpoint options (version, protocol)" do
93
- opts = {:version => :v1, :protocol => :insecure}
94
- @client.edit_slug(@username, @slug1, @slug2, options: opts).should == @slug2
95
- @client.edit_slug(@username, @slug2, @slug1, options: opts).should == @slug1
96
- end
97
- end
98
-
99
- context "GET /users/:username" do
100
- it "should get a specific user's profile" do
101
- @client.profile(@username).username.should == @username
102
- end
103
- end
104
-
105
- context "POST /stories/:username/:slug/publish" do
106
- it "should raise an exception if a story is not provided" do
107
- expect{@client.publish(nil)}.to raise_exception
108
- end
109
-
110
- it "should raise an exception if the story is not found" do
111
- story = Storify::Story.new.extend(Storify::StoryRepresentable)
112
- author = Storify::User.new.extend(Storify::UserRepresentable)
113
- author.username = 'rtejpar'
114
- story.author = author
115
- story.slug = 'does-not-exist-story'
116
-
117
- expect{@client.publish(story)}.to raise_exception(Storify::ApiError)
118
- end
119
-
120
- it "should raise an exception if you do not have permission to publish" do
121
- story = Storify::Story.new.extend(Storify::StoryRepresentable)
122
- author = Storify::User.new.extend(Storify::UserRepresentable)
123
- author.username = 'storify'
124
- story.author = author
125
- story.slug = 'storify-acquired-by-livefyre'
126
-
127
- expect{@client.publish(story)}.to raise_exception(Storify::ApiError)
128
- end
129
-
130
- it "should publish an existing story" do
131
- story = @client.story('test-story', @username)
132
- @client.publish(story).should == true
133
- end
134
-
135
- it "should accept endpoint options" do
136
- options = {:version => :v1, :protocol => :insecure}
137
- story = @client.story('test-story', @username)
138
- @client.publish(story, options: options).should == true
139
37
  end
140
38
 
141
- it "should allow changes to the story during a publish" do
142
- story = @client.story('no-embeds', @username)
143
- new_desc = "New Description #{Random.new(Random.new_seed).to_s}"
144
-
145
- story.description = new_desc
146
- story.description.should == new_desc
147
- @client.publish(story).should == true
148
-
149
- revised = @client.story('no-embeds', @username)
150
- revised.description.should == new_desc
151
- end
152
- end
153
-
154
- context "POST /users/:username/update" do
155
- it "should raise an exception if a user is not provided" do
156
- expect{@client.update_profile(nil)}.to raise_exception
157
- end
158
-
159
- it "should raise an exception if the user cannot be found" do
160
- user = Storify::User.new.extend(Storify::UserRepresentable)
161
- user.username = "rtejpar$$$$"
162
- expect{@client.update_profile(user)}.to raise_exception(Storify::ApiError)
163
- end
164
-
165
- it "should raise an exception if the profile cannot be updated" do
166
- user = Storify::User.new.extend(Storify::UserRepresentable)
167
- user.username = "storify"
168
- expect{@client.update_profile(user)}.to raise_exception(Storify::ApiError)
169
- end
170
-
171
- it "should accept/reject updates to profile information based on plan status" do
172
- user = @client.profile(@username)
173
- user.location = "Loc #{Random.new(Random.new_seed).to_s}"
174
-
175
- if user.paid_plan == "free"
176
- expect{@client.update_profile(user)}.to raise_exception(Storify::ApiError)
177
- else
178
- @client.update_profile(user).should == true
179
- end
180
- end
181
-
182
- it "should support endpoint options" do
183
- options = {:version => :v1, :protocol => :insecure}
184
- user = Storify::User.new.extend(Storify::UserRepresentable)
185
- user.username = "rtejpar$$$$"
186
- expect{@client.update_profile(user, options: options)}.to raise_exception(Storify::ApiError)
187
- end
188
- end
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
-
250
- context "Serialization" do
251
- it "should allow a story to be serialized as text" do
252
- story = @client.story('austin-startup-digest-for-december-9-2014', 'joshuabaer')
253
- story.should_not eql ""
39
+ it "raises an exception for unknown block credentials" do
40
+ expect {Storify::Client.new {|config| config.unknown = ''}}.to raise_exception
254
41
  end
255
42
  end
256
43
  end