storify 0.0.11 → 0.0.12

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: 1bc26cd7a6d0f18da904689a7765d52d75099d25
4
- data.tar.gz: 5101109dee46ec2679dd36a84c959c189dc968c2
3
+ metadata.gz: 58748b03027c0d1b55dab4d3c625a623f5ac885b
4
+ data.tar.gz: 35b8e4dfdf2ffbea53947b09dbb0bb64bcf6700e
5
5
  SHA512:
6
- metadata.gz: 648001b71e271feafa2abcc8e094b5a0941e35531028dbc4b06a8b8cf363012126be512c1404f4796214b2548e361091175a26d47188c7da961d38c51af82b22
7
- data.tar.gz: b03312e0debb19881ee528d7b1c97a5472f3c0a49cdf55ad57e20bda7e855d30d18d620a6f02efb9aea5657ced4b06879d616fa62397292518aa1bfa5413f02c
6
+ metadata.gz: 7a599dff3581d8912472d1f096abde3c38867437828f7fbba68e780aa42087e565bb627b9c96e8b992d2737d5735f500f8c8ca7657d40566d6eb10a09e66d3d0
7
+ data.tar.gz: 8337f44f6dabe2e3d3bb8d7c95b5c7b1d55b31467a8740933684047ceb93c04dbb37abddb7b18c017cf3ea1803e8a6088aae63b8241eab642a7fc39debf00feb
data/lib/storify.rb CHANGED
@@ -19,6 +19,7 @@ module Storify
19
19
  :editslug => '/stories/:username/:slug/editslug',
20
20
  :users => '/users',
21
21
  :userprofile => '/users/:username',
22
+ :update_profile => '/users/:username/update',
22
23
  :publish => '/stories/:username/:slug/publish'
23
24
  }
24
25
  }
@@ -135,8 +135,23 @@ module Storify
135
135
  User.new.extend(UserRepresentable).from_json(json)
136
136
  end
137
137
 
138
+ def update_profile(user, options: {})
139
+ raise "Not a User" unless user.is_a?(Storify::User)
140
+
141
+ username = user.username
142
+ endpoint = Storify::endpoint(version: options[:version],
143
+ protocol: options[:protocol],
144
+ method: :update_profile,
145
+ params: {':username' => username})
146
+
147
+ json = user.to_json
148
+ data = call(endpoint, :POST, params: {:user => json})
149
+
150
+ true
151
+ end
152
+
138
153
  def publish(story, options: {})
139
- puts story.inspect
154
+
140
155
  # ensure we have a story w/slug and author
141
156
  raise "Not a Story" unless story.is_a?(Storify::Story)
142
157
  raise "No slug found" if story.slug.nil?
@@ -153,7 +168,7 @@ module Storify
153
168
 
154
169
  # attempt to publish
155
170
  json = story.to_json
156
- data = call(endpoint, :POST, params: {:data => json})
171
+ data = call(endpoint, :POST, params: {:story => json})
157
172
  true
158
173
  end
159
174
 
data/spec/client_spec.rb CHANGED
@@ -132,19 +132,59 @@ describe Storify::Client do
132
132
  @client.publish(story).should == true
133
133
  end
134
134
 
135
- it "should ignore any changes to the story during a publish" do
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
+ end
140
+
141
+ it "should allow changes to the story during a publish" do
136
142
  story = @client.story('no-embeds', @username)
137
143
  new_desc = "New Description #{Random.new(Random.new_seed).to_s}"
138
- old_desc = story.description
139
144
 
140
145
  story.description = new_desc
141
146
  story.description.should == new_desc
142
147
  @client.publish(story).should == true
143
148
 
144
149
  revised = @client.story('no-embeds', @username)
145
- revised.description.should == old_desc
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)
146
163
  end
147
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
148
188
  end
149
189
 
150
190
  context "Serialization" do
data/spec/storify_spec.rb CHANGED
@@ -85,6 +85,10 @@ describe Storify do
85
85
  it "should support the Publish Story endpoint" do
86
86
  Storify::ENDPOINTS[:v1][:publish].should == "/stories/:username/:slug/publish"
87
87
  end
88
+
89
+ it "should support the Update User Profile endpoint" do
90
+ Storify::ENDPOINTS[:v1][:update_profile].should == "/users/:username/update"
91
+ end
88
92
  end
89
93
 
90
94
  context "API Endpoint URI Builder:" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: storify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rizwan Tejpar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-15 00:00:00.000000000 Z
11
+ date: 2013-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json