Skip to content

Commit b273410

Browse files
committed
Merge pull request #87 from cernalpanic/FLEX-698
Flex 698
2 parents e2f5a30 + e89845d commit b273410

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

lib/spark_api/models/photo.rb

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ module Models
55
class Photo < Base
66
extend Subresource
77
self.element_name = "photos"
8-
8+
99
attr_accessor :update_path
10-
10+
1111
EDITABLE_FIELDS = [:Picture, :FileName, :Name, :Caption, :Primary]
12-
12+
1313
def initialize(opts={})
1414
defaulted_opts = {}
1515
EDITABLE_FIELDS.each do |k|
@@ -19,10 +19,10 @@ def initialize(opts={})
1919
super(opts.merge(defaulted_opts))
2020
end
2121

22-
def primary?
23-
@attributes["Primary"] == true
22+
def primary?
23+
@attributes["Primary"] == true
2424
end
25-
25+
2626
def save(arguments={})
2727
begin
2828
return save!(arguments)
@@ -44,12 +44,12 @@ def save!(arguments={})
4444
load(result)
4545
true
4646
end
47-
47+
4848
def load_picture(file_name)
4949
self.Picture = Base64.encode64(File.open(file_name, 'rb').read).gsub(/\n/, '')
5050
self.FileName = File.basename(file_name)
5151
end
52-
52+
5353
def delete(args={})
5454
connection.delete("#{update_path}/#{self.Id}", args)
5555
end
@@ -58,15 +58,20 @@ def rollback(version)
5858
payload = {"Version" => version}
5959
connection.put "#{update_path}/#{self.Id}/versions/current", payload
6060
end
61-
61+
62+
def rotate(direction)
63+
payload = { 'Photos' => [ {'Rotate' => direction }] }
64+
connection.put "#{self.update_path}/#{self.Id}", payload
65+
end
66+
6267
def exists?
6368
@attributes.include?("Id")
6469
end
65-
70+
6671
private
67-
72+
6873
def build_photo_hash
69-
results_hash = {}
74+
results_hash = {}
7075
EDITABLE_FIELDS.each do |k|
7176
key = k.to_s
7277
results_hash[key] = @attributes[key] unless @attributes[key].nil?
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"D": {
3+
"Photos": [
4+
{"Rotate": "clockwise"}
5+
]
6+
}
7+
}

spec/unit/spark_api/models/photo_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@
8181
subject.Id.should eq("20110826220032167405000000")
8282
end
8383

84+
on_put_it "should rotate a photo" do
85+
stub_api_put('/listings/1234/photos/20110826220032167405000000', 'listings/photos/rotate.json', 'success.json')
86+
subject.Id = "20110826220032167405000000"
87+
subject.rotate('clockwise')
88+
end
89+
8490
on_delete_it "should delete a photo" do
8591
stub_api_delete('/listings/1234/photos/20110826220032167405000000','success.json')
8692
subject.Id = "20110826220032167405000000"

0 commit comments

Comments
 (0)