def save_image(image_data)

      instagram_service = Lentil::Service.where(:name => "Instagram").first

      user_record = instagram_service.users.where(:user_name => image_data[:user][:username]).
        first_or_create!({:full_name => image_data[:user][:full_name], :bio => image_data[:user][:bio]})

      raise DuplicateImageError, "Duplicate image identifier" unless user_record.
        images.where(:external_identifier => image_data[:external_id]).first.nil?

      image_record = user_record.images.build({
        :external_identifier => image_data[:external_id],
        :description => image_data[:name],
        :url => image_data[:url],
        :long_url => image_data[:large_url],
        :video_url => image_data[:video_url],
        :original_datetime => image_data[:original_datetime],
        :media_type => image_data[:media_type]
      })

      image_record.original_metadata = image_data[:original_metadata].to_hash

      # Default to "All Rights Reserved" until we find out more about licenses
      # FIXME: Set the default license in the app config
      unless image_record.licenses.size > 0
        image_record.licenses << Lentil::License.where(:short_name => "ARR").first
      end

      image_data[:tags].each {|tag| image_record.tags << Lentil::Tag.where(:name => tag).first_or_create}

      user_record.save!
      image_record.save!
      image_record
    end
def save_image(image_data)

      instagram_service = Lentil::Service.where(:name => "Instagram").first

      user_record = instagram_service.users.where(:user_name => image_data[:user][:username]).
        first_or_create!({:full_name => image_data[:user][:full_name], :bio => image_data[:user][:bio]})

      raise DuplicateImageError, "Duplicate image identifier" unless user_record.
        images.where(:external_identifier => image_data[:external_id]).first.nil?

      image_record = user_record.images.build({
        :external_identifier => image_data[:external_id],
        :description => image_data[:name],
        :url => image_data[:url],
        :long_url => image_data[:large_url],
        :video_url => image_data[:video_url],
        :original_datetime => image_data[:original_datetime],
        :media_type => image_data[:media_type]
      })

      image_record.original_metadata = image_data[:original_metadata].to_hash

      # Default to "All Rights Reserved" until we find out more about licenses
      # FIXME: Set the default license in the app config
      unless image_record.licenses.size > 0
        image_record.licenses << Lentil::License.where(:short_name => "ARR").first
      end

      image_data[:tags].each {|tag| image_record.tags << Lentil::Tag.where(:name => tag).first_or_create}

      user_record.save!
      image_record.save!
      image_record
    end
Takes return from Instagram API gem and adds image,
 users, and tags to the database.

 @raise [DuplicateImageError] This method does not accept duplicate external image IDs

 @param [Hash] image_data processed Instagram image metadata

 @return [Image] new Image object