spark_api 1.3.18 → 1.3.19

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.18
1
+ 1.3.19
@@ -5,11 +5,11 @@ module SparkApi
5
5
  class Photo < Base
6
6
  extend Subresource
7
7
  self.element_name = "photos"
8
-
8
+
9
9
  attr_accessor :update_path
10
-
10
+
11
11
  EDITABLE_FIELDS = [:Picture, :FileName, :Name, :Caption, :Primary]
12
-
12
+
13
13
  def initialize(opts={})
14
14
  defaulted_opts = {}
15
15
  EDITABLE_FIELDS.each do |k|
@@ -19,10 +19,10 @@ module SparkApi
19
19
  super(opts.merge(defaulted_opts))
20
20
  end
21
21
 
22
- def primary?
23
- @attributes["Primary"] == true
22
+ def primary?
23
+ @attributes["Primary"] == true
24
24
  end
25
-
25
+
26
26
  def save(arguments={})
27
27
  begin
28
28
  return save!(arguments)
@@ -44,12 +44,12 @@ module SparkApi
44
44
  load(result)
45
45
  true
46
46
  end
47
-
47
+
48
48
  def load_picture(file_name)
49
49
  self.Picture = Base64.encode64(File.open(file_name, 'rb').read).gsub(/\n/, '')
50
50
  self.FileName = File.basename(file_name)
51
51
  end
52
-
52
+
53
53
  def delete(args={})
54
54
  connection.delete("#{update_path}/#{self.Id}", args)
55
55
  end
@@ -58,15 +58,24 @@ module SparkApi
58
58
  payload = {"Version" => version}
59
59
  connection.put "#{update_path}/#{self.Id}/versions/current", payload
60
60
  end
61
-
61
+
62
+
63
+ def rotate!(direction)
64
+ unless [:clockwise, :counterclockwise].include? direction.to_sym
65
+ raise ArgumentError, "Photo rotate failed. '#{direction}' is not supported."
66
+ end
67
+ payload = { 'Photos' => [{'Rotate' => direction.to_s }] }
68
+ connection.put "#{self.update_path}/#{self.Id}", payload
69
+ end
70
+
62
71
  def exists?
63
72
  @attributes.include?("Id")
64
73
  end
65
-
74
+
66
75
  private
67
-
76
+
68
77
  def build_photo_hash
69
- results_hash = {}
78
+ results_hash = {}
70
79
  EDITABLE_FIELDS.each do |k|
71
80
  key = k.to_s
72
81
  results_hash[key] = @attributes[key] unless @attributes[key].nil?
@@ -0,0 +1,7 @@
1
+ {
2
+ "D": {
3
+ "Photos": [
4
+ {"Rotate": "clockwise"}
5
+ ]
6
+ }
7
+ }
@@ -81,6 +81,18 @@ describe Photo do
81
81
  subject.Id.should eq("20110826220032167405000000")
82
82
  end
83
83
 
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
+
90
+ on_put_it "should raise an exception for an invalid rotate parameter" do
91
+ stub_api_put('/listings/1234/photos/20110826220032167405000000', 'listings/photos/rotate.json', 'success.json')
92
+ subject.Id = "20110826220032167405000000"
93
+ expect { subject.rotate!('left') }.to raise_error(ArgumentError)
94
+ end
95
+
84
96
  on_delete_it "should delete a photo" do
85
97
  stub_api_delete('/listings/1234/photos/20110826220032167405000000','success.json')
86
98
  subject.Id = "20110826220032167405000000"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spark_api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 61
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 18
10
- version: 1.3.18
9
+ - 19
10
+ version: 1.3.19
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brandon Hornseth
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2014-11-14 00:00:00 Z
19
+ date: 2014-12-15 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  type: :runtime
@@ -450,6 +450,7 @@ files:
450
450
  - spec/fixtures/listings/photos/index.json
451
451
  - spec/fixtures/listings/photos/new.json
452
452
  - spec/fixtures/listings/photos/rollback.json
453
+ - spec/fixtures/listings/photos/rotate.json
453
454
  - spec/fixtures/listings/put_expiration_date.json
454
455
  - spec/fixtures/listings/with_photos.json
455
456
  - spec/fixtures/listings/open_houses.json
@@ -655,6 +656,7 @@ test_files:
655
656
  - spec/fixtures/listings/photos/index.json
656
657
  - spec/fixtures/listings/photos/new.json
657
658
  - spec/fixtures/listings/photos/rollback.json
659
+ - spec/fixtures/listings/photos/rotate.json
658
660
  - spec/fixtures/listings/put_expiration_date.json
659
661
  - spec/fixtures/listings/with_photos.json
660
662
  - spec/fixtures/listings/open_houses.json