Sha256: 4cf770459dc359ddee9ca0f5d614f64d28efeaad98f227240b9c2753c438a47e

Contents?: true

Size: 945 Bytes

Versions: 2

Compression:

Stored size: 945 Bytes

Contents

require 'base64'

class CityGrid
  class API
    class Advertising
      class Image < Advertising
        def self.upload user_id, name, type, image_path, options = {}
          token = extract_auth_token options
          image_data = Base64.encode64(File.open(image_path).read.to_s).gsub(/\n/, "")
          format = options[:format] || image_path.split(".").last
          request_and_handle :post,
            "#{base_uri}/#{endpoint}/upload",
            :body => {"mutateOperationListResource" => [
              {
                "operand" => {
                  "imageType" => type,
                  "imageName" => name,
                  "imageFormat" => format,
                  "image" => image_data
                },
                "operator" => "ADD",
                "userId" => user_id
              }
            ]}.to_json,
            :headers => merge_headers("authToken" => token)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
citygrid_api-0.0.10 lib/citygrid/api/advertising/image.rb
citygrid_api-0.0.9 lib/citygrid/api/advertising/image.rb