storify 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a597b9c43e8afeeac84225326bb2cd5feae00ff6
4
- data.tar.gz: 599b496edc23eaf9f8d3cd97b1560ec67d64c269
3
+ metadata.gz: 80ab1db50509835603c3e6c168b8e280609b56b8
4
+ data.tar.gz: 8ee9e89be0fd86fb103359ed310a2b08b83d2ca4
5
5
  SHA512:
6
- metadata.gz: 58d374aa18d1df960a68c30ba93933656699a44b547170d30334067d0d2093cf75b69d271f738530225cbb2b25e3a93af7ee64003bc3b489707014ea7842023c
7
- data.tar.gz: bd950c0efe4e478c0815ed9a38f49a22a9df4e006965329a7d12f89e57ab21ad3f7e7b8ebbee7d41ce5f5653a6deb73b8997b8e842cbff8ca1714f538ff7c070
6
+ metadata.gz: d9150aaed0238077440089ff91343f388446662d2accf6a60764a30fe11ab36b14d3fa5f620b95111ee5d3470b0ebf795cfebb790cf5080adc8a7550d3e22185
7
+ data.tar.gz: 7da411bd9aec3aff5a5b131b00cc446535e7f7a5d7aa19afb2d665d584af2de3c3df9b9fafd1dceddd8c3ade7f31ef85aea087a17324bdcc67e4bfbe1aaecb1a
@@ -41,6 +41,15 @@ module Storify
41
41
  story_list(:popular, pager, options: options, use_auth: false)
42
42
  end
43
43
 
44
+ def topic(topic, pager: nil, options: {})
45
+ story_list(:topic, pager, options: options, params: {':topic' => topic})
46
+ end
47
+
48
+ def search(criteria, pager: nil, options: {})
49
+ u = {'q' => criteria}
50
+ story_list(:search, pager, options: options, use_auth: false, uparams: u)
51
+ end
52
+
44
53
  def userstories(username = @username, pager: nil, options: {})
45
54
  params = {':username' => username}
46
55
  story_list(:userstories, pager, options: options, params: params)
@@ -73,6 +82,17 @@ module Storify
73
82
  story
74
83
  end
75
84
 
85
+ def edit_slug(username = @username, old_slug, new_slug, options: {})
86
+ params = {':username' => username, ':slug' => old_slug}
87
+ endpoint = Storify::endpoint(version: options[:version],
88
+ protocol: options[:protocol],
89
+ method: :editslug,
90
+ params: params)
91
+
92
+ data = call(endpoint, :POST, params: {slug: new_slug})
93
+ data['content']['slug']
94
+ end
95
+
76
96
  def authenticated
77
97
  !@token.nil?
78
98
  end
@@ -80,7 +100,7 @@ module Storify
80
100
 
81
101
  private
82
102
 
83
- def story_list(method, pager, params: {}, options: {}, use_auth: true)
103
+ def story_list(method, pager, params: {}, options: {}, use_auth: true, uparams: {})
84
104
  endpoint = Storify::endpoint(version: options[:version],
85
105
  protocol: options[:protocol],
86
106
  method: method,
@@ -90,7 +110,7 @@ module Storify
90
110
  stories = []
91
111
 
92
112
  begin
93
- data = call(endpoint, :GET, paging: pager.to_hash, use_auth: use_auth)
113
+ data = call(endpoint, :GET, paging: pager.to_hash, use_auth: use_auth, params: uparams)
94
114
  content = data['content']
95
115
 
96
116
  content['stories'].each do |s|
data/lib/storify.rb CHANGED
@@ -13,7 +13,10 @@ module Storify
13
13
  :userstory => '/stories/:username/:slug',
14
14
  :latest => '/stories/browse/latest',
15
15
  :featured => '/stories/browse/featured',
16
- :popular => '/stories/browse/popular'
16
+ :popular => '/stories/browse/popular',
17
+ :topic => '/stories/browse/topic/:topic',
18
+ :search => '/stories/search',
19
+ :editslug => '/stories/:username/:slug/editslug'
17
20
  }
18
21
  }
19
22
 
@@ -68,4 +68,38 @@ describe "Storify::Client -- Unauthenticated" do
68
68
  @client.popular(pager: p).length.should == 15
69
69
  end
70
70
  end
71
+
72
+ context "GET /stories/browse/topic/:topic" do
73
+ it "should get all stories with a topic until the maximum" do
74
+ @client.topic('nfl-playoffs').length.should > 1
75
+ end
76
+
77
+ it "should accept endpoint options (version, protocol)" do
78
+ @client.topic('nfl-playoffs', options: @options).length.should > 1
79
+ end
80
+
81
+ it "should get the top 10 stories for a topic" do
82
+ p = Storify::Pager.new(page: 1, max: 1, per_page: 10)
83
+ @client.topic('nfl-playoffs', pager: p).length.should == 10
84
+ end
85
+
86
+ it "should raise an exception if the topic is not found" do
87
+ expect{@client.topic('does-not-exist-topic')}.to raise_exception(Storify::ApiError)
88
+ end
89
+ end
90
+
91
+ context "GET /stories/search" do
92
+ it "should get all stories with a specified search criteria" do
93
+ @client.search('startups').length.should > 10
94
+ end
95
+
96
+ it "should accept endpoint options (version, protocol)" do
97
+ @client.search('startups', options: @options).length.should > 10
98
+ end
99
+
100
+ it "should get the first 5 stories about startups" do
101
+ p = Storify::Pager.new(page: 1, max: 1, per_page: 5)
102
+ @client.search('startups', pager: p).length.should == 5
103
+ end
104
+ end
71
105
  end
data/spec/client_spec.rb CHANGED
@@ -53,17 +53,17 @@ describe Storify::Client do
53
53
 
54
54
  context "GET /stories/:username/:slug" do
55
55
  before(:all) do
56
- puts "Enter a Story Id for your Account:"
57
- @story = STDIN.gets.chomp
56
+ puts "Enter a Story-Slug for your Account:"
57
+ @slug = STDIN.gets.chomp
58
58
  end
59
59
 
60
60
  it "should get a specific story for a user (all pages)" do
61
- @client.story(@story).elements.length.should == 3
61
+ @client.story(@slug).elements.length.should == 3
62
62
  end
63
63
 
64
64
  it "should accept endpoint options (version, protocol)" do
65
65
  options = {:version => :v1, :protocol => :insecure}
66
- @client.story(@story, options: options).elements.length.should == 3
66
+ @client.story(@slug, options: options).elements.length.should == 3
67
67
  end
68
68
 
69
69
  it "should accept paging options (Page)" do
@@ -75,6 +75,27 @@ describe Storify::Client do
75
75
  end
76
76
  end
77
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
+
78
99
  it "should allow a story to be serialized as text" do
79
100
  story = @client.story('austin-startup-digest-for-december-9-2014', 'joshuabaer')
80
101
  story.should_not eql ""
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,7 @@ RSpec.configure do |config|
5
5
  config.mock_with :rspec
6
6
  config.add_setting :api_key, :default => ''
7
7
  config.add_setting :api_usr, :default => ''
8
-
8
+
9
9
  # load user-specific keys or fallback to defaults
10
10
  config.before(:all) do
11
11
  begin
data/spec/storify_spec.rb CHANGED
@@ -54,6 +54,10 @@ describe Storify do
54
54
  Storify::ENDPOINTS[:v1][:popular].should == "/stories/browse/popular"
55
55
  end
56
56
 
57
+ it "should support Stories by Topic endpoint" do
58
+ Storify::ENDPOINTS[:v1][:topic].should == "/stories/browse/topic/:topic"
59
+ end
60
+
57
61
  it "should support the User Stories endpoint" do
58
62
  Storify::ENDPOINTS[:v1][:userstories].should == "/stories/:username"
59
63
  end
@@ -61,6 +65,14 @@ describe Storify do
61
65
  it "should support the Single Story endpoint" do
62
66
  Storify::ENDPOINTS[:v1][:userstory].should == "/stories/:username/:slug"
63
67
  end
68
+
69
+ it "should support the Edit Story Slug endpoint" do
70
+ Storify::ENDPOINTS[:v1][:editslug].should == "/stories/:username/:slug/editslug"
71
+ end
72
+
73
+ it "should support the Search Story endpoint" do
74
+ Storify::ENDPOINTS[:v1][:search].should == "/stories/search"
75
+ end
64
76
  end
65
77
 
66
78
  context "API Endpoint URI Builder:" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: storify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rizwan Tejpar