Sha256: 0c0305a5497ffa4948503b5c24472d10bfd10a3b82e06b477f8e266e646c2e48

Contents?: true

Size: 1.19 KB

Versions: 5

Compression:

Stored size: 1.19 KB

Contents

module Storyq
  class Photo < Storyq::Resource
    include Storyq::Upload
    
    class << self
      def save_params
        %w(title note)
      end
      
      def collection_name(type = :url)
        "photos"
      end
      def singular_name(type = :url)
        "photo"
      end      
    end

    def initialize(*args)
      @photo_box = args.pop
      @holder = @photo_box.holder
      @hash = args.shift
    end
    
    def parameters
      parameters = super
      if @hash["filename"]
        parameters["photo[uploaded_data]"] = uploaded_file(@hash["filename"])
      end
      parameters
    end    

    def save
      if new?
        p parameters
        xml = @holder.post("/photo_boxes/#{@photo_box.id}/photos", multipart_body(parameters, boundary), 
          "content-type" => "multipart/form-data; boundary=#{boundary}")
        @hash["filename"] = nil
      else
        xml = @holder.put("/photo_boxes/#{@photo_box.id}/photos/#{id}", parameters.to_query)
      end
      @hash = Hash.from_xml(xml)["photo"]
      self
    end
    
    def destroy
      puts "hey"
      xml = @holder.delete("/photo_boxes/#{@photo_box.id}/photos/#{id}")
      @hash = Hash.from_xml(xml)
    end    
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
aproxacs-storyq_client-0.0.1 lib/storyq_client/photo.rb
aproxacs-storyq_client-0.0.2 lib/storyq_client/photo.rb
aproxacs-storyq_client-0.0.3 lib/storyq_client/photo.rb
aproxacs-storyq_client-0.1.0 lib/storyq_client/photo.rb
aproxacs-storyq_client-0.1.1 lib/storyq_client/photo.rb