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
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Storify::Client do
4
+ let(:client) { Storify::Client.new(:api_key => @api_key, :username => @username) }
5
+ let(:options) { {:version => :v1, :protocol => :insecure} }
6
+ let(:pager) { Storify::Pager.new(page: 1, max: 1, per_page: 20) }
7
+ let(:tape) { 'featured' }
8
+
9
+ context "#featured [GET /stories/browse/featured]" do
10
+ it "gets all featured stories" do
11
+ VCR.use_cassette(tape) do
12
+ expect(client.featured.length).to be > 400
13
+ end
14
+ end
15
+
16
+ it "gets all featured stories with options: version, protocol" do
17
+ VCR.use_cassette(tape, :match_requests_on => vcr_ignore_protocol) do
18
+ expect(client.featured(options: options).length).to be > 400
19
+ end
20
+ end
21
+
22
+ it "gets the top 20 featured stories" do
23
+ VCR.use_cassette(tape) do
24
+ expect(client.featured(pager: pager).length).to eql 20
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Storify::Client do
4
+ let(:client) { Storify::Client.new(:api_key => @api_key, :username => @username) }
5
+ let(:options) { {:version => :v1, :protocol => :insecure} }
6
+ let(:pager) { Storify::Pager.new(page: 1, max: 1, per_page: 20) }
7
+ let(:tape) { 'latest' }
8
+
9
+ context "#latest [GET /stories/browse/latest]" do
10
+ it "gets all latest stories" do
11
+ VCR.use_cassette(tape) do
12
+ expect(client.latest.length).to be > 400
13
+ end
14
+ end
15
+
16
+ it "gets all latest stories with options: version, protocol" do
17
+ VCR.use_cassette(tape, :match_requests_on => vcr_ignore_protocol) do
18
+ expect(client.latest(options: options).length).to be > 400
19
+ end
20
+ end
21
+
22
+ it "gets the top 20 latest stories" do
23
+ VCR.use_cassette(tape) do
24
+ expect(client.latest(pager: pager).length).to eql 20
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Storify::Client do
4
+ let(:client) { Storify::Client.new(:api_key => @api_key, :username => @username) }
5
+ let(:options) { {:version => :v1, :protocol => :insecure} }
6
+ let(:pager) { Storify::Pager.new(page: 1, max: 1, per_page: 15) }
7
+ let(:tape) { 'popular' }
8
+
9
+ context "#popular [GET /stories/browse/popular]" do
10
+ it "gets all popular stories" do
11
+ VCR.use_cassette(tape) do
12
+ expect(client.popular.length).to be > 400
13
+ end
14
+ end
15
+
16
+ it "gets all popular stories with options: version, protocol" do
17
+ VCR.use_cassette(tape, :match_requests_on => vcr_ignore_protocol) do
18
+ expect(client.popular(options: options).length).to be > 400
19
+ end
20
+ end
21
+
22
+ it "gets the top 15 popular stories" do
23
+ VCR.use_cassette(tape) do
24
+ expect(client.popular(pager: pager).length).to eql 15
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Storify::Client do
4
+ let(:client) { Storify::Client.new(:api_key => @api_key, :username => @username) }
5
+ let(:options) { {:version => :v1, :protocol => :insecure} }
6
+ let(:pager) { Storify::Pager.new(page: 1, max: 1, per_page: 5) }
7
+ let(:criteria) { 'startups' }
8
+ let(:tape) { 'search' }
9
+
10
+ context "#search [GET /stories/search]" do
11
+ it "gets all stories with search criteria" do
12
+ VCR.use_cassette(tape) do
13
+ expect(client.search(criteria).length).to be > 10
14
+ end
15
+ end
16
+
17
+ it "gets all stories with search criteria using options: version, protocol" do
18
+ VCR.use_cassette(tape, :match_requests_on => vcr_ignore_protocol) do
19
+ expect(client.search(criteria, options: options).length).to be > 10
20
+ end
21
+ end
22
+
23
+ it "gets the top 5 stories with search criteria" do
24
+ VCR.use_cassette(tape) do
25
+ expect(client.search(criteria, pager: pager).length).to eql 5
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Storify::Client do
4
+ let(:client) { Storify::Client.new(:api_key => @api_key, :username => @username) }
5
+ let(:options) { {:version => :v1, :protocol => :insecure} }
6
+ let(:pager) { Storify::Pager.new(page: 1, max: 2, per_page: 20) }
7
+ let(:tape) { 'stories' }
8
+
9
+ context "#stories [GET /stories]" do
10
+ it "gets all stories" do
11
+ VCR.use_cassette(tape) do
12
+ expect(client.stories.length).to be > 400
13
+ end
14
+ end
15
+
16
+ it "gets all stories with options: version, protocol" do
17
+ VCR.use_cassette(tape, :match_requests_on => vcr_ignore_protocol) do
18
+ expect(client.stories(options: options).length).to be > 400
19
+ end
20
+ end
21
+
22
+ it "gets the first 2 pages of stories" do
23
+ VCR.use_cassette(tape) do
24
+ expect(client.stories(pager: pager).length).to eql 40
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Storify::Client do
4
+ let(:client) { Storify::Client.new(:api_key => @api_key, :username => @username) }
5
+ let(:options) { {:version => :v1, :protocol => :insecure} }
6
+ let(:pager) { Storify::Pager.new(page: 1, max: 1, per_page: 10) }
7
+ let(:tape) { 'topic' }
8
+ let(:nfl) { 'nfl-playoffs' }
9
+
10
+ context "#topic [GET /stories/browse/topic/:topic]" do
11
+ it "gets all stories for a topic" do
12
+ VCR.use_cassette(tape) do
13
+ expect(client.topic(nfl).length).to be > 1
14
+ end
15
+ end
16
+
17
+ it "gets all stories for a topic with options: version, protocol" do
18
+ VCR.use_cassette(tape, :match_requests_on => vcr_ignore_protocol) do
19
+ expect(client.topic(nfl, options: options).length).to be > 1
20
+ end
21
+ end
22
+
23
+ it "gets the top 10 stories for a topic" do
24
+ VCR.use_cassette(tape) do
25
+ expect(client.topic(nfl, pager: pager).length).to eql 10
26
+ end
27
+ end
28
+
29
+ it "raises an exception if the topic is not found" do
30
+ VCR.use_cassette(tape) do
31
+ expect{client.topic('does-not-exist-topic')}.to raise_exception(Storify::ApiError)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Storify::Client do
4
+ let(:options) { {:version => :v1, :protocol => :insecure} }
5
+ let(:story) { Storify::Story.new.extend(Storify::StoryRepresentable) }
6
+ let(:data) { Storify::StoryData.new.extend(Storify::StoryDataRepresentable) }
7
+ let(:tape) { 'create' }
8
+ let(:client) do
9
+ VCR.use_cassette('auth') do
10
+ Storify::Client.new(:api_key => @api_key, :username => @username).auth(get_password)
11
+ end
12
+ end
13
+
14
+ context "#create [POST /stories/:username/create]" do
15
+ it "creates a story with multiple elements" do
16
+ VCR.use_cassette(tape) do
17
+ story.title = "Create Story Test"
18
+ story.elements = []
19
+ story.elements << Storify::Element.new.extend(Storify::ElementRepresentable)
20
+ story.elements << Storify::Element.new.extend(Storify::ElementRepresentable)
21
+ story.elements << Storify::Element.new.extend(Storify::ElementRepresentable)
22
+
23
+ # add text data item
24
+ item = story.elements[0]
25
+ item.data = Storify::StoryData.new.extend(Storify::StoryDataRepresentable)
26
+ item.data.text = "Start of the story..."
27
+
28
+ # add twitter link
29
+ item = story.elements[1]
30
+ item.permalink = "http://twitter.com/fmquaglia/status/409875377482264577"
31
+
32
+ # twitter link with image
33
+ item = story.elements[2]
34
+ item.permalink = "http://twitter.com/NicholleJ/status/407924506380861441"
35
+
36
+ expect(client.create(story, true)).to_not eql ""
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Storify::Client do
4
+ let(:slug) { 'create-story-test' }
5
+ let(:tape) { 'delete' }
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 "#delete [POST /stories/:username/:slug/delete]" do
13
+ it "deletes the specified story" do
14
+ VCR.use_cassette(tape) do
15
+ expect(client.delete(slug, @username)).to be_true
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe Storify::Client do
4
+ let(:options) { {:version => :v1, :protocol => :insecure} }
5
+ let(:story) { Storify::Story.new.extend(Storify::StoryRepresentable) }
6
+ let(:user) { Storify::User.new.extend(Storify::UserRepresentable) }
7
+ let(:desc) { 'This is a desc modification test' }
8
+ let(:tape) { 'publish' }
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
+ let(:test_story) do
15
+ VCR.use_cassette('story') do
16
+ client.story('test-story', @username)
17
+ end
18
+ end
19
+ let(:empty_story) do
20
+ VCR.use_cassette('story') do
21
+ client.story('no-embeds')
22
+ end
23
+ end
24
+
25
+ context "#publish [POST /stories/:username/:slug/publish]" do
26
+ it "raises an exception if a story is not provided" do
27
+ VCR.use_cassette(tape) do
28
+ expect{client.publish(nil)}.to raise_exception
29
+ end
30
+ end
31
+
32
+ it "raises an exception if the story is not found" do
33
+ user.username = @username
34
+ story.author = user
35
+ story.slug = 'does-not-exist-story'
36
+
37
+ VCR.use_cassette(tape) do
38
+ expect{client.publish(story)}.to raise_exception(Storify::ApiError)
39
+ end
40
+ end
41
+
42
+ it "raises an exception if unauthorized" do
43
+ user.username = 'storify'
44
+ story.author = user
45
+ story.slug = 'storify-acquired-by-livefyre'
46
+
47
+ VCR.use_cassette(tape) do
48
+ expect{client.publish(story)}.to raise_exception(Storify::ApiError)
49
+ end
50
+ end
51
+
52
+ it "publishes an existing story" do
53
+ VCR.use_cassette(tape) do
54
+ expect(client.publish(test_story)).to be_true
55
+ end
56
+ end
57
+
58
+ it "publishes an existing story using options: version, protocol" do
59
+ VCR.use_cassette(tape, :match_requests_on => vcr_ignore_protocol) do
60
+ expect(client.publish(test_story, options: options)).to be_true
61
+ end
62
+ end
63
+
64
+ it "should allow changes to the story during a publish" do
65
+ expect(empty_story.description).to_not eql desc
66
+ empty_story.description = desc
67
+
68
+ VCR.use_cassette(tape) do
69
+ expect(client.publish(empty_story)).to be_true
70
+ expect(client.story('no-embeds', @username).description).to eql desc
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Storify::Client do
4
+ let(:options) { {:version => :v1, :protocol => :insecure} }
5
+ let(:element) { Storify::Element.new.extend(Storify::ElementRepresentable) }
6
+ let(:data) { Storify::StoryData.new.extend(Storify::StoryDataRepresentable) }
7
+ let(:tape) { 'save' }
8
+ let(:client) do
9
+ VCR.use_cassette('auth') do
10
+ Storify::Client.new(:api_key => @api_key, :username => @username).auth(get_password)
11
+ end
12
+ end
13
+ let(:test_story) do
14
+ VCR.use_cassette('story') do
15
+ client.story('test-story', @username)
16
+ end
17
+ end
18
+ let(:empty_story) do
19
+ VCR.use_cassette('story') do
20
+ client.story('no-embeds')
21
+ end
22
+ end
23
+
24
+ context "#save [POST /stories/:username/:slug/save]" do
25
+ it "saves an existing story" do
26
+ element.data = data
27
+ element.data.text = "Added new text item"
28
+ empty_story.elements << element
29
+
30
+ VCR.use_cassette(tape) do
31
+ expect(client.save(empty_story)).to be_true
32
+ expect(client.publish(empty_story)).to be_true
33
+
34
+ revised = client.story('no-embeds', @username)
35
+ expect(revised.elements.length).to eql 1
36
+
37
+ revised.elements = []
38
+ expect(client.save(revised)).to be_true
39
+ expect(client.publish(revised)).to be_true
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Storify::Client do
4
+ let(:options) { {:version => :v1, :protocol => :insecure} }
5
+ let(:pager) { Storify::Pager.new(page: 2, max: 3) }
6
+ let(:digest) { 'austin-startup-digest-for-december-9-2014' }
7
+ let(:slug) { 'test-story' }
8
+ let(:tape) { 'story' }
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 "#story [GET /stories/:username/:slug]" do
16
+ it "gets an entire story for a user" do
17
+ VCR.use_cassette(tape) do
18
+ expect(client.story(slug).elements.length).to eql 3
19
+ end
20
+ end
21
+
22
+ it "gets an entire story for a user using options: version, protocol" do
23
+ VCR.use_cassette(tape, :match_requests_on => vcr_ignore_protocol) do
24
+ expect(client.story(slug, options: options).elements.length).to eql 3
25
+ end
26
+ end
27
+
28
+ it "gets specific pages of a story for a user" do
29
+ VCR.use_cassette(tape) do
30
+ story = client.story(digest, 'joshuabaer', pager: pager).to_s
31
+
32
+ ['408651138632667136', '409182832234213376'].each do |s|
33
+ expect(story.include?(s)).to be_true
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ context "#to_s" do
40
+ it "serializes a story as text" do
41
+ VCR.use_cassette(tape) do
42
+ expect(client.story(digest, 'joshuabaer').to_s).to_not eql ""
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Storify::Client do
4
+ let(:client) { Storify::Client.new(:api_key => @api_key, :username => @username) }
5
+ let(:options) { {:version => :v1, :protocol => :insecure} }
6
+ let(:pager) { Storify::Pager.new(page: 1, max: 1, per_page: 10) }
7
+ let(:tape) { 'users' }
8
+
9
+ context "#users [GET /users]" do
10
+ it "gets all users" do
11
+ VCR.use_cassette(tape) do
12
+ expect(client.users.length).to be > 100
13
+ end
14
+ end
15
+
16
+ it "gets all users using options: version, protocol" do
17
+ VCR.use_cassette(tape, :match_requests_on => vcr_ignore_protocol) do
18
+ expect(client.users(options: options).length).to be > 100
19
+ end
20
+ end
21
+
22
+ it "gets the first 10 users" do
23
+ VCR.use_cassette(tape) do
24
+ expect(client.users(pager: pager).length).to eql 10
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,32 @@
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(:tape) { 'userstories' }
7
+ let(:client) do
8
+ VCR.use_cassette('auth') do
9
+ Storify::Client.new(:api_key => @api_key, :username => @username).auth(get_password)
10
+ end
11
+ end
12
+
13
+ context "#userstories [GET /stories/:username]" do
14
+ it "gets all stories for a user" do
15
+ VCR.use_cassette(tape) do
16
+ expect(client.userstories.length).to be >= 2
17
+ end
18
+ end
19
+
20
+ it "gets all stories for a user using options: version, protocol" do
21
+ VCR.use_cassette(tape, :match_requests_on => vcr_ignore_protocol) do
22
+ expect(client.userstories(options: options).length).to be >= 2
23
+ end
24
+ end
25
+
26
+ it "gets the first page of stories for a user" do
27
+ VCR.use_cassette(tape) do
28
+ expect(client.userstories('joshuabaer', pager: pager).length).to eql 10
29
+ end
30
+ end
31
+ end
32
+ end